This is an archive of the discontinued LLVM Phabricator instance.

[clang][Toolchains][Gnu] pass -gdwarf-* through to assembler
ClosedPublic

Authored by nickdesaulniers on Oct 25 2022, 11:38 AM.

Details

Summary

We've been working around this for a long time in the Linux kernel; we
bend over backwards to continue to support CC=clang (w/
-fno-integrated-as) for architectures where clang can't yet be used to
assemble the kernel's assembler sources. Supporting debug info for the
combination of CC=clang w/ GNU binutils as "GAS" has been painful.

Fix this in clang so that we can work towards dropping complexity in the
Linux kernel's build system, Kbuild, for supporting this combination of
tools.

GAS added support for -gdwarf-{3|4|5} in 2020 2.35 release via
commit 31bf18645d98 ("Add support for --dwarf-[3|4|5] to assembler command line.")

Refactor code to share logic between integrated-as and non-integrated-as
for determining the implicit default. This change will now always
explicitly pass a -gdwarf-* flag to the GNU assembler when -g is
specified.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2022, 11:38 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
nickdesaulniers requested review of this revision.Oct 25 2022, 11:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2022, 11:38 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
clang/lib/Driver/ToolChains/Clang.cpp
4206–4214

I might be able to elide this/move/refactor this as well...

clang/lib/Driver/ToolChains/CommonArgs.h
106–107

This can be made static to the .cpp file now.

MaskRay accepted this revision.Oct 25 2022, 3:27 PM
This revision is now accepted and ready to land.Oct 25 2022, 3:27 PM
  • more refactoring
MaskRay added inline comments.Oct 25 2022, 4:20 PM
clang/lib/Driver/ToolChains/Clang.cpp
7966

Consider const if this variable is not modified.

clang/lib/Driver/ToolChains/CommonArgs.h
114

If this patch touches all use cases of GetDwarfVersion, consider switching the case to getDwarfVersion.

clang/lib/Driver/ToolChains/Gnu.cpp
980

MakeArgString accepts a Twine. Just use "-gdwarf-" + Twine(DwarfVersion); as the argument.

nickdesaulniers marked 3 inline comments as done.
  • add const, fix lowerCamelCase, use Twine
MaskRay added inline comments.Oct 26 2022, 10:41 AM
clang/lib/Driver/ToolChains/Gnu.cpp
980

Twine as a local variable is not safe.

Use `CmdArgs.push_back(Args.MakeArgString("-gdwarf-" + Twine(DwarfVersion)));

This revision was landed with ongoing or failed builds.Oct 26 2022, 10:45 AM
This revision was automatically updated to reflect the committed changes.

This change has caused clang -Wall -fdebug-default-version=5 -c -xc /dev/null -o /dev/null to print the following warning, because it has moved the read of the argument into a conditional.
clang: warning: argument unused during compilation: '-fdebug-default-version=5' [-Wunused-command-line-argument]

It shouldn't warn about that.

This change has caused clang -Wall -fdebug-default-version=5 -c -xc /dev/null -o /dev/null to print the following warning, because it has moved the read of the argument into a conditional.
clang: warning: argument unused during compilation: '-fdebug-default-version=5' [-Wunused-command-line-argument]

It shouldn't warn about that.

I will fix this.