This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Avoid creating a 2.1GB output file in arm-exidx-range.s
ClosedPublic

Authored by arichardson on Aug 10 2020, 9:47 AM.

Details

Summary

Currently both sections will be placed in the same PT_LOAD and therefore
lld generates a contiguous output file containing both sections.
By marking the .vectors section as writable, it will be placed in a
separate PT_LOAD and the resulting file is now only a few kilobytes.

Diff Detail

Event Timeline

arichardson created this revision.Aug 10 2020, 9:47 AM
arichardson requested review of this revision.Aug 10 2020, 9:47 AM
psmith accepted this revision.Aug 10 2020, 10:00 AM

Thanks for spotting that. I'd personally prefer to fix in the linker script, rather than make the code RW but I don't have a strong preference.

In a magical world where there is spare time, it would be great to make the LLD program header generation more like BFD which I believe will generate separate program headers when the distance between OutputSections is large. Not for this patch though.

lld/test/ELF/arm-exidx-range.s
6

This can be also be fixed by replacing this line:
.vectors 0xffff0000 : AT(0xffff0000) : { *(.vectors) } \

This revision is now accepted and ready to land.Aug 10 2020, 10:00 AM

Use linker script approach instead

arichardson added a comment.EditedAug 10 2020, 10:06 AM
This comment has been deleted.
lld/test/ELF/arm-exidx-range.s
6

Thanks, that's a better solution. I thought I'd have to add custom PHDRS to fix this so I used the attribute mismatch to force a new PT_LOAD.

This revision was landed with ongoing or failed builds.Aug 10 2020, 10:09 AM
This revision was automatically updated to reflect the committed changes.

Thanks for spotting that. I'd personally prefer to fix in the linker script, rather than make the code RW but I don't have a strong preference.

In a magical world where there is spare time, it would be great to make the LLD program header generation more like BFD which I believe will generate separate program headers when the distance between OutputSections is large. Not for this patch though.

This reminds me of D79254 and a previous discussion about why RISC-V relaxation is difficult to implement in LLD.

BFD does program header allocation and address assignments in a loop while we don't. We could allocate a new header whenever an output section address is specified but that could waste lots of program header space if we ended up merging many PT_LOAD segments. If we have a loop as well, we can indeed behave more like BFD. The additional complexity needs a lot of thoughts.