This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Use tombstone values for discarded symbols in relocatable output
ClosedPublic

Authored by ikudrin on Jan 10 2022, 7:31 AM.

Details

Summary

This extends D81784. Sections can be discarded when linking a relocatable output. Before the patch, LLD did not update the content of debug sections and only replaced the corresponding relocations with R_*_NONE, which could break the debug information.

Diff Detail

Event Timeline

ikudrin created this revision.Jan 10 2022, 7:31 AM
ikudrin requested review of this revision.Jan 10 2022, 7:31 AM
MaskRay added a comment.EditedJan 10 2022, 11:30 PM

InputSection::relocateNonAlloc takes significant time in the --time-trace metric Write sections.

Now a relocatable link runs both relocateNonAllocForRelocatable and relocateNonAlloc, making it slower. -r performance is less important than executable/shared, so I think if there is no better choice (readability/performance trade-off) paying the cost if fine, but I wonder whether we can do something better.

Unrelated to this patch, I have the question whether we can make relocateNonAlloc faster for executable/shared.

lld/ELF/InputSection.cpp
944

Maybe it's time to swap then and else.

MaskRay added inline comments.Jan 10 2022, 11:34 PM
lld/test/ELF/debug-dead-reloc-relocatable.s
6

Use .o for relocatable object files.

ikudrin updated this revision to Diff 398895.Jan 11 2022, 4:05 AM
ikudrin marked 2 inline comments as done.
ikudrin edited the summary of this revision. (Show Details)
  • Add .o in the test
  • Swap then and else branches in InputSection::relocateNonAlloc()

Now a relocatable link runs both relocateNonAllocForRelocatable and relocateNonAlloc, making it slower. -r performance is less important than executable/shared, so I think if there is no better choice (readability/performance trade-off) paying the cost if fine, but I wonder whether we can do something better.

As copyRelocations() already detects the case, it could store some information for relocateNonAllocForRelocatable() so that the latter apply tombstone values. But that looked more complicated than the taken way, and I agree with you that the performance of -r is not that important to sacrifice readability.

Unrelated to this patch, I have the question whether we can make relocateNonAlloc faster for executable/shared.

As for now, I do not see obvious ways to improve.

Sacrificing the performance for -r seems fine.

lld/ELF/InputSection.cpp
1001

This needs a comment with something like: for a relocatable link, call relocateNonAlloc to rewrite applicable locations with the tombstone value.

lld/test/ELF/debug-dead-reloc-relocatable.s
7

Super nit: llvm-readelf -r -x .debug_ranges or llvm-objdump -r -s -j .debug_ranges

ikudrin updated this revision to Diff 399245.Jan 12 2022, 1:21 AM
ikudrin marked 2 inline comments as done.
  • Add comments
  • Dump only required information in the test
MaskRay accepted this revision.Jan 12 2022, 1:52 AM

LGTM.

This revision is now accepted and ready to land.Jan 12 2022, 1:52 AM