Page MenuHomePhabricator

[ELF] Linkerscript: don't add program headers to segment when we have PHDRS directive but don't have FILEHDR and PHDRS attributes for segment
ClosedPublic

Authored by evgeny777 on Oct 19 2016, 8:22 AM.

Details

Summary

Linker shouldn't include program headers in PT_LOAD in the following case:

  • PHDRS directive exists
  • PT_LOAD segment doesn't contain PHDRS and/or FILEHDR attribute

Below is an example of such script:

PHDRS { 
  hdr PT_PHDR FILEHDR PHDRS;
  all PT_LOAD; 
}
SECTIONS { 
   . = 0x10000;
   .text : { *(.text) } : all
  /* other sections go here */
}

Current revision will detect that there is a place to put ELF and program headers and will do this even though 'all' segment doesn't
have PHDRS and FILEHDR attributes.

To make this patch as simple as possible, both FILEHDR and PHDRS attributes are required to put ELF and program headers to PT_LOAD.
GNU gold has the same requirement.

Diff Detail

Repository
rL LLVM

Event Timeline

evgeny777 updated this revision to Diff 75156.Oct 19 2016, 8:22 AM
evgeny777 retitled this revision from to [ELF] Linkerscript: don't add program headers to segment when we have PHDRS directive but don't have FILEHDR and PHDRS attributes for segment.
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: ikudrin, grimar, llvm-commits.
rafael accepted this revision.Oct 19 2016, 11:55 AM
rafael edited edge metadata.

LGTM

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