This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Linkerscript: Try to put section to the last PT_LOAD, in case there is no exact segment specification
ClosedPublic

Authored by evgeny777 on Sep 21 2016, 5:41 AM.

Details

Summary

Some scripts may look like this:

PHDRS { all  PT_LOAD; }
SECTIONS {
   .aaa : { *(.aaa) } : all;
   .bbb : { *(.bbb) }
}

This patch will try to put section .bbb to segment 'all'

Diff Detail

Event Timeline

evgeny777 updated this revision to Diff 72030.Sep 21 2016, 5:41 AM
evgeny777 retitled this revision from to [ELF] Linkerscript: Try to put section to the last PT_LOAD, in case there is no exact segment specification.
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 added inline comments.Sep 21 2016, 7:53 AM
ELF/LinkerScript.cpp
670–680

I do not understand what this code does. Can you elaborate?

evgeny777 updated this revision to Diff 72048.Sep 21 2016, 8:25 AM
evgeny777 removed rL LLVM as the repository for this revision.

I've rewritten it and added comments. Hope it's more clear now.

evgeny777 updated this revision to Diff 72256.Sep 23 2016, 4:54 AM

Simplified

evgeny777 updated this revision to Diff 75000.Oct 18 2016, 7:44 AM

Addressed comments from Rafael

rafael added inline comments.Oct 19 2016, 7:12 AM
ELF/LinkerScript.cpp
652

Add a comment saying what you are doing. If I understand it, this just puts the first PT_LOAD from PHDRS in the vector. Also add a comment saying what the vector is.

660

This if is not necessary anymore, no?

evgeny777 added inline comments.Oct 19 2016, 7:18 AM
ELF/LinkerScript.cpp
652

Yes you're right. If we don't have phdr spec for section and hasn't added any section yet, then we'll simply put section to the very first PT_LOAD found. Here is an example:

PHDRS { segment PT_LOAD; }
SECTIONS {
   .aaa : { *(.aaa) }
   .bbb : { *(.bbb) } : segment
}

Of course this script is malformed, but this happens.

660

Not exactly. You may have no PT_LOAD segments in PHDRS directive. GNU gold (bunutils 2.26) crashes in such case. I think we shouldn't

evgeny777 added inline comments.Oct 19 2016, 7:29 AM
ELF/LinkerScript.cpp
660

On the second look I see that you're right. Will update diff.

evgeny777 accepted this revision.Oct 19 2016, 8:11 AM
evgeny777 added a reviewer: evgeny777.

Posted new diff to wrong review and got green mark
https://reviews.llvm.org/D25765

This revision is now accepted and ready to land.Oct 19 2016, 8:11 AM
This revision was automatically updated to reflect the committed changes.