This is an archive of the discontinued LLVM Phabricator instance.

Tweak orphan section placement
ClosedPublic

Authored by rafael on Sep 18 2017, 2:15 PM.

Details

Reviewers
filcab
ruiu
Summary

Filipe noticed that given a linker script that ended in

.some_sec { ...} ;
stack_start = .;
. = . + 0x2000;
stack_end = .;

lld would put orphan sections like .comment before __stack_end, corrupting the intended meaning.

The reason we don't normally move orphans past assignments to . is to avoid breaking

rx_sec : { *(rx_sec) }
. = ALIGN(0x1000);
/* The RW PT_LOAD starts here*/

but in this case, there is nothing after and it seems safer to put the orphan section last. This seems to match bfd's behavior and is convenient for writing linker scripts that care about the layout of SHF_ALLOC sections, but not of any non SHF_ALLOC sections.

Diff Detail

Event Timeline

rafael created this revision.Sep 18 2017, 2:15 PM
ruiu edited edge metadata.Sep 18 2017, 2:43 PM

I'm not sure if I understand this patch correctly.

.some_sec { ...} ;
__stack_start = .;
. = . + 0x2000;
__stack_end = .;

I think I agree that .comment shouldn't be before __stack_end, but what if it is not a .comment? For example, if an orphan section is a RO section, it might make sense to handle it with the normal rule.

ruiu accepted this revision.Sep 18 2017, 5:43 PM

LGTM

This revision is now accepted and ready to land.Sep 18 2017, 5:43 PM
espindola closed this revision.Mar 14 2018, 3:42 PM
espindola added a subscriber: espindola.

313646