This is an archive of the discontinued LLVM Phabricator instance.

[dsymutil] Fix .debug_addr index calculation
ClosedPublic

Authored by JDevlieghere on Jun 16 2023, 12:23 PM.

Details

Summary

The DW_OP_addrx operation encodes a zero-based index into the .debug_addr section. The index is relative to the DW_AT_addr_base attribute of the associated compilation unit. In order to compute the offset into the .debug_addr section and find the associated relocation, we need to add the add the add base offset and multiply the index with the address size. This patch fixes a bug in this computation, where the multiplication was omitted. This went unnoticed because for small test cases, the index for interesting addresses (such as the main subprogram) is often zero.

rdar://110881668

Diff Detail

Event Timeline

JDevlieghere created this revision.Jun 16 2023, 12:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 12:23 PM
Herald added a subscriber: arphaman. · View Herald Transcript
JDevlieghere requested review of this revision.Jun 16 2023, 12:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 12:23 PM
avl accepted this revision.Jun 16 2023, 1:13 PM

LGTM, with addressing small code simplification suggestion.

llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
1093

probably, just

return hasValidRelocationAt(ValidDebugAddrRelocs, StartOffset, EndOffset);

?

This revision is now accepted and ready to land.Jun 16 2023, 1:13 PM
JDevlieghere marked an inline comment as done.Jun 16 2023, 1:20 PM
JDevlieghere added inline comments.
llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
1093

Yup, thanks, I meant to unstage that part.

JDevlieghere marked an inline comment as done.Jun 16 2023, 1:26 PM

This patch fixes a 125 tests when running the LLDB test suite against DWARF 5 on Darwin. 🥳

This revision was landed with ongoing or failed builds.Jun 16 2023, 1:27 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Jun 16 2023, 1:33 PM

Seems to break tests: http://45.33.8.238/linux/110001/step_12.txt

Please take a look and revert for now if it takes a while to fix.

Seems to break tests: http://45.33.8.238/linux/110001/step_12.txt

Please take a look and revert for now if it takes a while to fix.

Working on it, just a matter of updating the tests.

aprantl added inline comments.Jun 16 2023, 1:49 PM
llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
1087

I find the name ByteSize misleading. Would you be okay with renaming it to AddrSize? Then it's consistent with how dwarfdump prints the .debug_addr header.

JDevlieghere marked an inline comment as done.Jun 16 2023, 1:58 PM

Seems to break tests: http://45.33.8.238/linux/110001/step_12.txt

Please take a look and revert for now if it takes a while to fix.

Working on it, just a matter of updating the tests.

Fixed in 8e1f820bb4ea.

llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
1087

Done in 8e1f820bb4ea.