This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Simplify output section creation.
ClosedPublic

Authored by grimar on Oct 18 2017, 4:27 AM.

Details

Summary

Our code that creates output sections is very similar to code
that handles orphans. Earlier we did integration of LLD scripted/non-scripted logic
so that even fabricate script commands in createSections() and with fabricateDefaultCommands
when no layout specified in script. And I think when there is no SECTION
commands given, all sections are technically orphans, but now we handle script orphans
sections and regular "orphans" sections for non-scripted case differently,
though we can handle them at one place.

That IMO makes code cleaner and simpler. Patch shows the change I am suggesting.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Oct 18 2017, 4:27 AM
grimar edited the summary of this revision. (Show Details)Oct 18 2017, 4:28 AM
ruiu added inline comments.Oct 25 2017, 4:53 PM
ELF/LinkerScript.cpp
464–468 ↗(On Diff #119457)

I do not understand this particular change, but I guess this will be removed by your other change.

487 ↗(On Diff #119457)

any others -> otheers

490–492 ↗(On Diff #119457)

I think

if (HasSectionsCommand)
  SectionCommands.insert(SectionsCommand.begin(), V.begin(), V.end());
else
  SectionCommands.insert(SectionsCommand.end(), V.begin(), V.end());

is more straightforward.

ELF/Writer.cpp
162 ↗(On Diff #119457)

is given

163 ↗(On Diff #119457)

, -> .

"Otherwise ..." part of the comment doesn't seem to describe this code. Please move it to the right place.

168–170 ↗(On Diff #119457)
// Linker scripts controls how input sections are assigned to output sections. Input sections that were not handled by scripts are called "orphans", and they are assigned to output sections by the default rule. Process that.
173–176 ↗(On Diff #119457)

Hmm, at this point, I started wondering if the changes to this function actually improves the function. Now, it isn't easy to point out which code is executed when linker script is given/not givne.

grimar added inline comments.
ELF/Writer.cpp
173–176 ↗(On Diff #119457)

It is not good place to apply default sorting I think.
I prepared patch to cleanup this place: D39371.

It should relax this place if we land it, what do you think ?

grimar updated this revision to Diff 120799.Oct 30 2017, 4:47 AM
grimar marked 8 inline comments as done.
  • Addressed review comments.
ELF/LinkerScript.cpp
464–468 ↗(On Diff #119457)

Yep, it's gone.

ELF/Writer.cpp
173–176 ↗(On Diff #119457)

With help of D39371 and one more change, this code was completly removed.

grimar edited the summary of this revision. (Show Details)Oct 30 2017, 4:54 AM
ruiu accepted this revision.Oct 30 2017, 6:43 PM

LGTM

ELF/LinkerScript.cpp
802 ↗(On Diff #120799)

This comment doesn't make sense even though it's not new. Please remove instead of copy&paste.

This revision is now accepted and ready to land.Oct 30 2017, 6:43 PM
This revision was automatically updated to reflect the committed changes.