This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Merge sections with different access attributes
AbandonedPublic

Authored by evgeny777 on Sep 9 2016, 6:09 AM.

Details

Reviewers
ruiu
rafael
Summary

There was a long story here of merging output sections when linker script is used and reverting it back to original scheme with multiple output sections having the same name. Now when we returned to original scheme, I'm getting troubles linking boot loader, where all code and data should be packed to a single section and then extracted from result image using objcopy.

To deal with this problem, I suggest dropping section access attributes from output section key and merging them in addSection(). This solves my problem and doesn't break unit tests, except repsection-va.s, which is part of linker script processor test suite.

I'd like to add that such behavior conforms to GNU linkers. Both gold and ld merge section attributes in such case.

Diff Detail

Event Timeline

evgeny777 updated this revision to Diff 70817.Sep 9 2016, 6:09 AM
evgeny777 retitled this revision from to [ELF] Merge sections with different access attributes.
evgeny777 updated this object.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
ruiu edited edge metadata.Sep 12 2016, 3:20 PM

As you know we had lots of discussions whether we should merge them or separate them. After several and forth commits, we are currently not merging sections with different attributes. When the last patch was submitted, the justification of doing it was to handle mergeable sections and other sections properly and also because keeping section writable/executable properties is a good thing. This patch revert that behavior. How would you handle the problems addressed by the last commit?

AFAIK, the main problem was linker script putting mergeable and non-mergeable to the same output section. This is really bad and should be avoided. However we're not living in ideal world and linker scripts putting RX and RW input sections to the same output section do exist. Things get worse when you use assignments:

.mysec : {
   *(.text)
   *(.data)
   . = ALIGN(0x1000);
}

Needless to say that lld will align second .mysec section, leaving the first one as is. Currently the only way lld allows putting code and data together is using PHDRS and single PT_LOAD for both. However nothing can be done to handle the case above correctly.

May be it makes sense to enable R/W/X merging only for linker script case for now?