Details
- Reviewers
llvm-commits MaskRay - Commits
- rG0e23fd676c39: [Driver] Add DWARF64 flag: -gdwarf64
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
- The patch needs tests to check the added functionality.
- DWARF64 can be generated only for a limited number of targets. There should be diagnostics for invalid switch combinations to prevent misuse. @MaskRay mentioned that in the patch for llc, D87011#2254749, but that makes a lot more sense for user-level tools.
The failure seems unrelated to my changes. Trying locally it fails with latest upstream even without my changes.
@jansvoboda11 Can you take a look? The failing test is unrelated it seems. Fails locally even without my change.
This change covers non-LTO cases. For LTO, I think we would need to pass it from driver to LTO. Something like this: tools::addLTOOptions -> lld -> lto::Config (Config->TargetOptions->MCTargetOptions) ->LTO Backend.
Oh, no. Sorry I wasn't clear. I was just looking for people to review this patch, and saw you recently reviewed another patch.
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | Is there any precedent to draw from for this flag name? (Does GCC support DWARF64? Does it support it under this flag name or some other? (similarly with other gcc-like compilers (Intel's? Whoever else... ))) |
It looks like lld/test/COFF/lto-new-pass-manager.ll.obj was added to the patch by accident and should be removed.
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | It looks like we are pioneering in that area. To me, the proposed name looks consonant with other debug-related switches. | |
clang/lib/Driver/ToolChains/Clang.cpp | ||
4030 | We also should check that the output format is ELF. |
It's weird. The file gets automatically added whenever I commit the files I have modified locally.
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | I didn't see any dwarf64 flags in gcc: I tried to follow clang convention for other dwarf flags. |
Adding DWARF64 clang flag
It is important to mention the exact option name: Add -gdwarf-64 to enable 64-bit DWARF format
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
4022 | Both A, and RawTriple are used more than once. |
clang/include/clang/Driver/Options.td | ||
---|---|---|
2577–2578 | Does this actually enable debug info emission (the -gdwarf-N versions do cause debug info to be emitted, and set the dwarf version - but, say -ggnu-pubnames does not cause debug info to be emitted if it isn't otherwise requested). Experience has shown it's probably better to have flags like this not enable debug info emission - so they can be used orthogonally (eg: if a project is large, it can add -gdwarf64 to its flags permanently, even though maybe only some build modes, etc, enable debug info (with -g)) If this doesn't enable debug info emission, the phrasing of the help text might be worth changing somewhat (I wonder how we document -ggnu-pubnames, for instance/comparison/inspiration) | |
clang/lib/Driver/ToolChains/Clang.cpp | ||
4024–4025 | perhaps we could phrase this more generally (so it's true even when DWARFv6 comes along - and doesn't get unwieldy listing all the DWARF versions). "DWARFv3 or later" ? | |
4030 | Is DWARF64 not supported on MachO, for instance? (I'd have DWARF64 would be pretty usable on any platform that supported DWARF in general - certainly some system tools that are DWARF aware (including actual debuggers) might not be up to the task of using it - but if we can correctly generate it in the object files, it seems OK to accept the request (useful for folks testing out/implementing DWARF64 consumers on those platforms)) | |
clang/test/Driver/debug-options.c | ||
389 | Typo in "architecture" |
clang/include/clang/Driver/Options.td | ||
---|---|---|
2577–2578 | This enables DWARF64 if emission is enabled. From DebugInfo it seems like it's only Elf Format: bool Dwarf64 = Asm->TM.Options.MCOptions.Dwarf64 && DwarfVersion >= 3 && // DWARF64 was introduced in DWARFv3. TT.isArch64Bit() && // DWARF64 requires 64-bit relocations. TT.isOSBinFormatELF(); // Support only ELF for now. |
clang/include/clang/Driver/Options.td | ||
---|---|---|
2577–2578 |
| |
clang/lib/Driver/ToolChains/Clang.cpp | ||
4030 | From DebugInfo it seems like it's only Elf Format: bool Dwarf64 = Asm->TM.Options.MCOptions.Dwarf64 && DwarfVersion >= 3 && // DWARF64 was introduced in DWARFv3. TT.isArch64Bit() && // DWARF64 requires 64-bit relocations. TT.isOSBinFormatELF(); // Support only ELF for now. |
clang/include/clang/Driver/Options.td | ||
---|---|---|
2577–2578 |
Then perhaps the Help Text phrasing should distinguish this behavior from the behavior of -gdwarf-N which not only sets the version, but enables emission. (perhaps the phrasing of flags that don't enable emission, like "-ggnu-pubnames" could provide inspiration for phrasing the help text for this new flag)
I'm curious as to why it's ELF only, though - could you explain what the motivation is there? (random aside: I still worry about this precedent for -g* flags that sometimes enable debug info and set a feature, and sometimes they only set the feature and don't enable debug info - it's a bit of a confusing mess and I personally rather the -fdebug* flags set a feature but don't enable emission and -g* flags enable emission, but there's a lack of clear agreement and there's examples on both sides, so not sure there's much to be done about that here) |
clang/include/clang/Driver/Options.td | ||
---|---|---|
2577–2578 |
Our customers need DWARF64 for ELF and I do not have much experience with other platforms, so I cannot provide adequate support there. Some platform-specific tools, like dsymutil, have to be fixed to work with DWARF64, but I am personally a bit reluctant to do that because I cannot check the result in practice. If there will be developers who are willing to support DWARF64 on these platforms, they will be able to unlock it and use all the experience we collect with ELF, but for now, I prefer to focus on one particular platform with practical applications. |
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | Huh - tried making really big binaries or anything (or checking the GCC source) to see if it does it implicitly under some conditions? (they also touch on the "all units must agree" issue - so not sure if the same folks involved in those discussions have also been included in the discussions around debug info 32/64 sorting as another approach that may avoid the "all units must agree" constraint (I assume that's the reason they had that constraint)) |
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | In the DWARFV5-64 pdf it says 64 bit support has no patches and is after DWARF5. Although it's not clear if they are talking about DWARF64 support for V5 or in general. I have not hacked our build system to use gcc for builds that can overflow debug_info. I scanned through gcc code and was only able to find references to dwarf 64 in go library, and in dwarf2out.c. In latter it relies on DWARF_OFFSET_SIZE macro. I don't quite understand the "all [CU] units must agree" part either. From DWARF perspective we are free to match on CU level DWARF32/64, and consumer are free not to do anything beyond that. So if overflow occurs, will so be it. What we are trying to do in linker with sorting is being "nice" to the users, and kind of going beyond what spec requires. Sounds like no conclusion was reached on their side, but only one of them -gdwarf64 follows naming convention of other debug flags.
|
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 |
There are many debug flags that don't use the '-g' prefix. (-fdebug-types-section comes to mind, but I think - this was discussed in depth earlier this year with regards to the -gsplit-dwarf flag, for instance: https://www.mail-archive.com/gcc@gcc.gnu.org/msg92495.html - though at least the DWARF64 flag doesn't have the legacy that -gsplit-dwarf has that complicates things further there) |
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | Ah, thanks for the context. My takeaway it's a mess. :) |
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | Yep, bit of a mess - hence the concern about making it messier/trying to drive in that general direction. Could you reach out to the gcc mailing list, link the thread I linked, CC myself (& anyone else from this review who seems interested) and any of the folks you might be able to identify from the Plumbers conference or other context that seems to have an interest in this & ask what they think the flag should be? I ask because so far as I can tell from prior experience, GCC is less likely to adopt Clang's convention out of compatibility, so it's more on us to try to pick something with some buy-in from their side of things lest we end up with divergent flags or semantics. |
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | Made a post: https://gcc.gnu.org/pipermail/gcc/2020-November/234290.html |
clang/include/clang/Basic/CodeGenOptions.def | ||
---|---|---|
35 | Seems like that thread eventually settled into someone submitting a patch to GCC with -gdwarf32/64 and them not implying -g by default. So that's consistent with this patch you're proposing here, right? Could you check the wording that the GCC patch uses for description/details/user manual and compare it with the wording you're proposing here? |
From: David Blaikie via Phabricator <reviews@reviews.llvm.org>
Sent: Monday, December 7, 2020 11:08 AM
To: Alexander Yermolovich <ayermolo@fb.com>; llvm-commits@lists.llvm.org <llvm-commits@lists.llvm.org>
Cc: Hongtao Yu <hoy@fb.com>; jan_svoboda@apple.com <jan_svoboda@apple.com>; stevenwu@apple.com <stevenwu@apple.com>; dany.grumberg@gmail.com <dany.grumberg@gmail.com>; Wenlei He <wenlei@fb.com>; dexonsmith@apple.com <dexonsmith@apple.com>; cfe-commits@lists.llvm.org <cfe-commits@lists.llvm.org>; maskray@google.com <maskray@google.com>; ikudrin@accesssoftek.com <ikudrin@accesssoftek.com>; bhuvanendra.kumarn@amd.com <bhuvanendra.kumarn@amd.com>; mlekena@skidmore.edu <mlekena@skidmore.edu>; blitzrakete@gmail.com <blitzrakete@gmail.com>; shenhan@google.com <shenhan@google.com>; orlando.hyams@sony.com <orlando.hyams@sony.com>
Subject: [PATCH] D90507: [Driver] Add DWARF64 flag: -gdwarf64
dblaikie added inline comments.
Herald added a subscriber: hoy.
Comment at: clang/include/clang/Basic/CodeGenOptions.def:35
CODEGENOPT(AsmVerbose , 1, 0) /< -dA, -fverbose-asm.
+CODEGENOPT(Dwarf64 , 1, 0) /< -gdwarf64.
CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
ayermolo wrote:
dblaikie wrote:
ayermolo wrote:
dblaikie wrote:
ayermolo wrote:
dblaikie wrote:
ayermolo wrote:
ikudrin wrote:
dblaikie wrote:
Is there any precedent to draw from for this flag name? (Does GCC support DWARF64? Does it support it under this flag name or some other? (similarly with other gcc-like compilers (Intel's? Whoever else... )))
It looks like we are pioneering in that area. To me, the proposed name looks consonant with other debug-related switches.
I didn't see any dwarf64 flags in gcc:
https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.htmlI tried to follow clang convention for other dwarf flags.
Huh - tried making really big binaries or anything (or checking the GCC source) to see if it does it implicitly under some conditions?
Hmm - looks like this maybe came up at the Linux Plumbers Conference & the suggested flag was -fdwarf64/32: https://linuxplumbersconf.org/event/7/contributions/746/attachments/578/1018/DWARF5-64.pdf (this avoids the "does g imply debug info" and avoids the subtle distinction between "-gdwarf64 and -gdwarf-N" the presence of the '-' changing the meaning of the number quite significantly). Though hardly authoritative
https://linuxplumbersconf.org/event/7/sessions/90/attachments/583/1201/dwarf-bof-notes-aug24-lpc-2020.txt - seems some other options were (are?) under consideration too. Might be worth touching base with the folks involved in those discussions to see where they're at with regard to naming/support?(they also touch on the "all units must agree" issue - so not sure if the same folks involved in those discussions have also been included in the discussions around debug info 32/64 sorting as another approach that may avoid the "all units must agree" constraint (I assume that's the reason they had that constraint))
In the DWARFV5-64 pdf it says 64 bit support has no patches and is after DWARF5. Although it's not clear if they are talking about DWARF64 support for V5 or in general.
I have not hacked our build system to use gcc for builds that can overflow debug_info. I scanned through gcc code and was only able to find references to dwarf 64 in go library, and in dwarf2out.c. In latter it relies on DWARF_OFFSET_SIZE macro.
I don't quite understand the "all [CU] units must agree" part either. From DWARF perspective we are free to match on CU level DWARF32/64, and consumer are free not to do anything beyond that. So if overflow occurs, will so be it. What we are trying to do in linker with sorting is being "nice" to the users, and kind of going beyond what spec requires.
Sounds like no conclusion was reached on their side, but only one of them -gdwarf64 follows naming convention of other debug flags.
- -fdwarf64/-fdwarf32
- or -gdwarf32 or -gdwarf64
- or -gdbdwarf=32/64
only one of them -gdwarf64 follows naming convention of other debug flags.
There are many debug flags that don't use the '-g' prefix. (-fdebug-types-section comes to mind, but I think - this was discussed in depth earlier this year with regards to the -gsplit-dwarf flag, for instance: https://www.mail-archive.com/gcc@gcc.gnu.org/msg92495.html - though at least the DWARF64 flag doesn't have the legacy that -gsplit-dwarf has that complicates things further there)
Ah, thanks for the context. My takeaway it's a mess. :)
Personally I find it more confusing that there are debug options that start with -f and -g, rather then that some -g enable debug output. When I look at documentation I just want to have see all the related options grouped in one area/one prefix, but that's just how my brain works.
That being said I don't have particular strong opinion about naming convention of this flag. Judging from that conversation, maybe there is some preference for -f, but mainly it was a big push against changing an option after it was introduced and proliferated.Yep, bit of a mess - hence the concern about making it messier/trying to drive in that general direction.
Could you reach out to the gcc mailing list, link the thread I linked, CC myself (& anyone else from this review who seems interested) and any of the folks you might be able to identify from the Plumbers conference or other context that seems to have an interest in this & ask what they think the flag should be?
I ask because so far as I can tell from prior experience, GCC is less likely to adopt Clang's convention out of compatibility, so it's more on us to try to pick something with some buy-in from their side of things lest we end up with divergent flags or semantics.
Made a post: https://gcc.gnu.org/pipermail/gcc/2020-November/234290.html
CCed people in this review + Mark Wielaard.
Seems like that thread eventually settled into someone submitting a patch to GCC with -gdwarf32/64 and them not implying -g by default.
So that's consistent with this patch you're proposing here, right?
Could you check the wording that the GCC patch uses for description/details/user manual and compare it with the wording you're proposing here?
[Alex]
From commit message:
"dwarf: Add -gdwarf{32,64} options
The following patch makes the choice between 32-bit and 64-bit DWARF formats selectable by command line switch, rather than being hardcoded through DWARF_OFFSET_SIZE macro. The options themselves don't turn on debug info themselves, so one needs to use -g -gdwarf64 or similar."
Sounds like it is settled then. I'll update my llvm diff accordingly, mainly adding -gdwarf32 flag.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90507/new/
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
4033 | Use render (see other render in the file) | |
clang/test/Driver/debug-options.c | ||
378 | Append -c to test just the compile action. x86_64-linux-gnu -> x86_64 to make it clear this is a generic ELF behavior (e.g. FreeBSD works). | |
382 | Don't repeat -target x86_64-linux-gnu |
clang/test/Driver/debug-options.c | ||
---|---|---|
389 | The diagnostic elf output format is untested. Please add an x86_64-apple-darwin test. |
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
4031 | "elf output format" -> "ELF platforms" ELF is usually capitalized. Here I think "platforms" is probably more suitable than "output format" (which I'd prefer "binary format") |
clang/test/Driver/debug-options.c | ||
---|---|---|
379 |
lit does not replace VALIDT with x86_64. Do you just want to test -target x86_64? |
clang/test/Driver/debug-options.c | ||
---|---|---|
379 | A, you are right. Should have checked lit with -a. I guess this only works for --check-prefix. |
Is there any precedent to draw from for this flag name? (Does GCC support DWARF64? Does it support it under this flag name or some other? (similarly with other gcc-like compilers (Intel's? Whoever else... )))