This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Linkerscript: do not fail if there is no space for program headers and there is PHDRS directive
AbandonedPublic

Authored by evgeny777 on Sep 16 2016, 8:08 AM.

Details

Reviewers
ruiu
rafael
Summary

After http://llvm.org/viewvc/llvm-project?view=revision&revision=281660
linking no works for me, because if first section VA is less than size of headers lld emits fatal error.

However in case we have PHDRS directive it doesn't really have to do so, because with PHDRS we can tell lld not to emit program headers or assign separate segment for them.
This patch does two things:

a) Do not emit fatal error in case hasPhdrsCommands() is true
b) Set elf headers VA to the end of the section, so there are more chances it is valid.

Diff Detail

Event Timeline

evgeny777 updated this revision to Diff 71648.Sep 16 2016, 8:08 AM
evgeny777 retitled this revision from to [ELF] Linkerscript: do not fail if there is no space for program headers and there is PHDRS directive.
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, llvm-commits.
emaste added a subscriber: emaste.Sep 18 2016, 1:31 PM

I've encountered this in FreeBSD as well after rL281660. The patch does not apply to HEAD, at rL281836 though.

ruiu added inline comments.Sep 20 2016, 9:48 PM
ELF/LinkerScript.cpp
472–479

I thought about this new code probably more than 15 minutes but am still not sure if this is correct. What is the problem you are trying to fix with this change?

test/ELF/linkerscript/phdrs.s
23–28

Is this linker script expected to create a valid executable?

evgeny777 abandoned this revision.Sep 21 2016, 5:38 AM

This works for me, because I have separate load segment for ELF and file headers, but now I think that in general it shouldn't

mloud added a subscriber: mloud.Sep 25 2021, 11:42 AM