This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] Make SHF_LINK_ORDER sections orphans
AbandonedPublic

Authored by peter.smith on Apr 25 2017, 6:44 AM.

Details

Reviewers
ruiu
rafael
Summary

I've separated this out from D32233 as it takes a different approach. Overall I think it is an improvement.

The reordering code for SHF_LINK_ORDER works on OutputSection::Sections if any of the InputSections are covered by an InputSectionDescription from a script then the Script->assignAddresses will take precedence and will likely produce an incorrect order.

To make Script->assignAddresses() pick up the order from the OutputSection we make clear all the InputSectionDescriptions::Sections() to make the InputSections orphans.

A theoretical drawback of this approach is that it will ruin any symbols defined by the linker script for the OutputSection. However I think this won't be a problem in practice. The default linker script in ld.bfd is

PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx   : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }
PROVIDE_HIDDEN (__exidx_end = .);

Which won't be troubled by making the InputSections Orphans.

Diff Detail

Event Timeline

peter.smith created this revision.Apr 25 2017, 6:44 AM
ruiu edited edge metadata.Apr 26 2017, 3:37 PM

I'm not sure if I completely understand this patch. Is this effectively the same as handling

.ARM.exidx { <something> }

as

.ARM.exidx {}

?

Yes that is what it is doing. If there are no InputSectionDescriptions in an OutputSection, the script falls back to flush() which just outputs any OutputSections::Sections() that have not already been output as part of an InputSection. By clearing the InputSectionDescriptions flush() picks up the ordering from OutputSections::finalize();

In the previous review D32355 I made sure that there was an equivalent of a single .ARM.exidx : { *(.ARM.exidx*) }, essentially putting all .ARM.exidx sections in a single InputSectionDescription.

From what Rafael says, if we want to remove flush() then this is definitely the wrong way to go, perhaps there is a way to make it less clunky to fabricate the linker script for the link order dependencies.

I suggest I abandon this and go back to D32355?

peter.smith abandoned this revision.May 2 2017, 7:26 AM

This has been superseded by D32612, abandoning as no longer required.