This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix incorrect inclusion of program headers to PT_LOAD segment
ClosedPublic

Authored by evgeny777 on Oct 19 2016, 4:40 AM.

Details

Reviewers
ruiu
rafael
Summary

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

  1. PHDRS directive exists
  2. 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

Event Timeline

evgeny777 updated this revision to Diff 75126.Oct 19 2016, 4:40 AM
evgeny777 retitled this revision from to [ELF] Fix incorrect inclusion of program headers to PT_LOAD 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.
evgeny777 updated this revision to Diff 75149.Oct 19 2016, 7:36 AM
evgeny777 removed rL LLVM as the repository for this revision.

Addressed review comments

rafael accepted this revision.Oct 19 2016, 7:45 AM
rafael edited edge metadata.

LGTM

This revision is now accepted and ready to land.Oct 19 2016, 7:45 AM

Wrong diff for this revision. This was actually for
https://reviews.llvm.org/D24795

evgeny777 closed this revision.Oct 19 2016, 8:23 AM

New revision created for the issue:
https://reviews.llvm.org/D25774