This is an archive of the discontinued LLVM Phabricator instance.

[llvm][dsymutil] Add DW_TAG_imported_declaration to accelerator table
ClosedPublic

Authored by Michael137 on Feb 6 2023, 7:47 PM.

Details

Summary

Summary

After this patch, dsymutil will preserve DW_TAG_imported_declarations
entries in accelerator tables.

This allows consumers to resolve imported declarations even on
executables processsed through dsymutil.

This helps consumers, particularly LLDB's expression evaluator,
to resolve imported declarations (i.e., useful for namespace aliases
in C++) more efficiently.

Testing

  • Added unit-test

Diff Detail

Event Timeline

Michael137 created this revision.Feb 6 2023, 7:47 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: hiraditya. · View Herald Transcript
Michael137 requested review of this revision.Feb 6 2023, 7:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2023, 7:47 PM
aprantl added a subscriber: avl.Feb 8 2023, 4:51 PM
aprantl added inline comments.
llvm/lib/DWARFLinker/DWARFLinker.cpp
1592

Now that DWARFLinker.cpp has been moved from tools/dsymutil into lib/DWARFLinker do we also have access to the debugger tuning settings?
My understanding is that @avl is working on a DWARFLinker for ELF so if that flag is exposed here, it might be nice to make this conditional to match the AsmPrinter behavior. If it's not exposed, I think leaving it as is is probably okay.

JDevlieghere accepted this revision.Feb 8 2023, 7:38 PM

LGTM

llvm/lib/DWARFLinker/DWARFLinker.cpp
1592

The DWARFLinker has options that allow it to be configured differently between users (like dsymutil). That said, looking at the DWARF spec:

The name index must contain an entry for each debugging information entry that defines a named subprogram, label, variable, type, or namespace, subject to the following rules: [..]

Nothing in the later stated "rules" excludes DW_TAG_imported_declaration from being part of the index. So following the wording of the spec, we "must" include it.

llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.cpp
2
This revision is now accepted and ready to land.Feb 8 2023, 7:38 PM
avl added inline comments.Feb 9 2023, 1:42 AM
llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test
4

it looks like -accelerator=None run is not necessary?

Michael137 added inline comments.Feb 9 2023, 4:34 AM
llvm/lib/DWARFLinker/DWARFLinker.cpp
1592

I interpreted it as being optional to include an imported declaration (since imported declaration != namespace, although for our purposes that is the case). That said, we haven't put a version check on the codegen side either, so probably not necessary here

llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test
4

Good catch

Michael137 marked an inline comment as done.Feb 9 2023, 4:39 AM
Michael137 updated this revision to Diff 496090.Feb 9 2023, 4:45 AM
  • Test cleanup
avl added inline comments.Feb 9 2023, 5:04 AM
llvm/lib/DWARFLinker/DWARFLinker.cpp
1592

this patch makes the behavior to be similar to the behavior of AsmPrinter(after D143397 AsmPrinter will put imported declaration into the apple_namespaces and/or debug_names), correct?

Michael137 added inline comments.Feb 9 2023, 5:10 AM
llvm/lib/DWARFLinker/DWARFLinker.cpp
1592

Exactly, I would only commit it as is once D143397 is approved

avl accepted this revision.Feb 9 2023, 5:17 AM
avl added inline comments.
llvm/lib/DWARFLinker/DWARFLinker.cpp
1592

If the behavior matched then it is probably not necessary to make it conditional(until someone need it directly).

JDevlieghere accepted this revision.Feb 9 2023, 2:06 PM
This revision was landed with ongoing or failed builds.Feb 9 2023, 5:34 PM
This revision was automatically updated to reflect the committed changes.

Seems to have broken linux bot:

/vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test:7:9: error: COMMON: expected string not found in input
COMMON: .debug_info contents
        ^
<stdin>:1:1: note: scanning from here
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/test/tools/dsymutil/ARM/Output/accel-imported-declarations.test.tmp.dwarf.dSYM/Contents/Resources/DWARF/accel-imported-declaration.macho-arm64: file format Mach-O arm64
^
<stdin>:7:1: note: possible intended match here
.debug_str contents:

Reverting until I figure out what's wrong on Linux. I think I didn't generate the executable correctly