This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Tweak sorting rules for output sections to place orphan sections at end.
AbandonedPublic

Authored by grimar on Apr 14 2016, 4:31 AM.

Details

Reviewers
ruiu
rafael
Summary

During discussion of D18499 was stated:
"Orphan sections are sections present in the input files which are not explicitly placed into the output file by the linker script. We place orphan sections at end of file."
This patch does not really affect D18499 because order of OutputSections in D18499 patch does not make sence anymore (script do all layout stuff).

But this patch changes sorting predicate to place orphans to the end. At least that is needed to keep OutputSections in sync with output to
set Sec->SectionIndex correctly for futher finalization.

Diff Detail

Event Timeline

grimar updated this revision to Diff 53690.Apr 14 2016, 4:31 AM
grimar retitled this revision from to [ELF] - Tweak sorting rules for output sections to place orphan sections at end..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
grimar added inline comments.Apr 14 2016, 5:30 AM
ELF/LinkerScript.cpp
68

Forgot to change the comment.
I think it can be:

// A compartor to sort output sections. Returns -1 or 1 if 
// A or B are mentioned in linker script. Otherwise, returns 0
// to use the default rule which is implemented in Writer.cpp.
ruiu added inline comments.Apr 14 2016, 11:54 AM
ELF/LinkerScript.cpp
68

Why don't you update the comment?

grimar updated this revision to Diff 53864.Apr 15 2016, 3:00 AM
  • Updated comment.
  • Fixed name of check prefix in testcase.
ELF/LinkerScript.cpp
68

Done. I assumed it is acceptable to update it during next iteration (which almost always happens) or before commit if "LGTM" is given.

ruiu edited edge metadata.Apr 15 2016, 5:33 AM

I'm confused. If you submit D18499, then there is actually no orphan sections internally because you append all orphan sections to end of the SectionOrder vector, no? Instead of updating the if conditional, shouldn't you just remove it or replace it with assertions?

In D19107#402346, @ruiu wrote:

I'm confused. If you submit D18499, then there is actually no orphan sections internally because you append all orphan sections to end of the SectionOrder vector, no? Instead of updating the if conditional, shouldn't you just remove it or replace it with assertions?

D18499 does not touch SectionOrder vector. It appends orphans to Locations list only.
Probably you're right and it should update the SectionOrder vector too.

But we will do this during assignAddresses now (after addressing last round of review). It will be too late to update SectionOrder vector then.

Also compareSections() is always called now, no matter do we have script or not.
So if we don't have script, then

if (I == E && J == E)

line is expected and valid for us, I think.
So I guess even if we upgrade D18499 and let it update SectionOrder, this patch still seems OK.

grimar abandoned this revision.Apr 15 2016, 11:07 AM

I`ll prepare another approach for solving that.

And this approach is D19171