Since DW_AT_name is not a symbol name for DW_TAG_label DIEs
add DW_AT_linkage_name with original symbol name.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
I'm not sure that stripping the leading _ unconditionally is correct either. This code exists to emit DWARF for labels in assembler source code and I'm assuming that this patch will break that use-case.
It would be good to add both a testcase for your intended use-case and one with an assembler label (if that doesn't exist already).
Interestingly the test specifically checks if underscore is removed. Looks like this was very much intentional. But I still do not understand why.. It makes the DW_AT_name of the label differ from elf symbol name (in .dynsym section).
The goal would be for the name to match what the user wrote - not
necessarily what the symbol name is.
It looks like in our case it ended up being not what the user wrote.. and this is especially confusing because libc and exit symbol too (and __exit, which gets converted to _exit...
If there's a difference between the in-source name and the exposed-to-linker name, the in-source name should be provided to DW_AT_name and the exposed-to-linker name should be in DW_AT_linkage_name. Don't try to overload DW_AT_name with any kind of decoration imposed for linking purposes.
Is this correct? What if the user has a label called "_foo"?
I would've thought this '_' handling thing was specifically a OSX/iOS thing (from what I've seen in its handling in LLVM in other places) - so I'm surprised it isn't conditionalized in some way?
I am not sure if I understand - my intended use-case here is in fact an assembler label (a .glob label). Can you please give me a pointer to another use-case? I am not very familiar with llvm code base.
There is still a question about which fix is the correct one. This one or https://reviews.llvm.org/D47104. To reiterate which use case requires clang to remove leading underscores in DW_AT_name?
lib/MC/MCDwarf.cpp | ||
---|---|---|
562 | Uh, DW_AT_linkage_name isn't intended to be used with DW_TAG_labels. It is really meant to provide the mangled names with entries, etc. From DWARF4 spec "Debugging information entries to which DW_AT_linkage_name may apply include: DW_TAG_common_block, DW_TAG_constant, DW_TAG_entry_point, DW_TAG_subprogram and DW_TAG_variable." DWARF5 dropped that wording, but you can still infer that list from Appendix A, etc. I can see that we already emit DW_AT_prototyped for DW_TAG_labels (also extra to the standard). There are other debuggers who consume this stuff. We're about to start work on the OpenVMS debugger to bring it up past DWARF3 and I would have assumed (incorrectly) that nobody would emit these DW_AT_ attributes for labels. Is there a document somewhere that tracks these extra-standard extensions? |
lib/MC/MCDwarf.cpp | ||
---|---|---|
562 |
I wonder if the information in Appendix A (which is non-normative) isn't an oversight. Might be worth bringing this up on the dwarf-discuss mailing list.
Not that I'm aware of. Generally LLVM tends to be fairly permissive about emitting extra dwarf attributes based on that consumers can always ignore extra attributes they don't understand. |
lib/MC/MCDwarf.cpp | ||
---|---|---|
562 | Appendix A is really a best-effort list, not definitive (which is explicitly stated in the opening text of the appendix). DWARF rarely mandates anything, and permissively allows extra attributes not specified in the normative text to appear in a DIE. Any reader needs to be ready for that sort of thing. |
lib/MC/MCDwarf.cpp | ||
---|---|---|
562 | Got it. Thanks. I do agree about omitting it if the linkage_name is the same as the name since that reduces the number of references to the string table. Given your lightning talk and the reduction of string references that led to the changes for DWARF5, no sense making a DWARF4 (or earlier) user pay that extra cost. You do end up with needing two Abbrevs however. I still have a question about the use of DW_AT_prototyped (the normative description is in the "Miscellaneous Subprogram Properties" section) and what it means on a label but I'll go dig for when that was included and the rationale behind it. |