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.
Details
Diff Detail
Event Timeline
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. |
lld/test/ELF/debug-dead-reloc-relocatable.s | ||
---|---|---|
6 | Use .o for relocatable object files. |
- Add .o in the test
- Swap then and else branches in InputSection::relocateNonAlloc()
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 | ||
---|---|---|
1002–1003 | 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 | ||
8 | Super nit: llvm-readelf -r -x .debug_ranges or llvm-objdump -r -s -j .debug_ranges |
Maybe it's time to swap then and else.