This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Linkerscript: Yet Another Fix For Empty Sections.
AbandonedPublic

Authored by evgeny777 on Sep 26 2016, 8:53 AM.

Details

Reviewers
ruiu
rafael
Summary

Current implementation handles empty section only in case it contains symbols. Unfortunately it's not the only case when empty section should be kept. Consider the following example:

SECTIONS {
  .eh_frame_hdr : { *(.eh_frame_hdr) }
  __eh_frame_hdr_start = ADDR(.eh_frame_hdr);
}

This script cannot be processed by lld in case there is no .eh_frame_hdr section in the target image.
The proposed implementation doesn't have side effects (no extended PT_LOADs and no empty sections in the target image) and doesn't look more complex than the existing one

Diff Detail

Event Timeline

evgeny777 updated this revision to Diff 72496.Sep 26 2016, 8:53 AM
evgeny777 retitled this revision from to [ELF] Linkerscript: Yet Another Fix For Empty Sections..
evgeny777 updated this object.
evgeny777 added reviewers: rafael, ruiu.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
rafael edited edge metadata.Sep 26 2016, 3:49 PM

I think I am sold on this, but it needs some comments. Also, please don't delete the tests, instead show what is now produced. One of the advantages of this implementation is precisely that PT_LOAD creation is not impacted.

ELF/LinkerScript.cpp
456

Don't you have to adjust the value?

500

Add a comment about what is being done. If I understand it correctly, it is:

  • In here, create any missing output section as SHF_EXCLUDE. They are created such that in the end the OutputSectionCommands and the OutputSections are in the same order and have a 1:1 mapping.
  • The creation is after the creation of PT_LOADs, so they don't impact them.
  • Once addresses have been computed, the sections are deleted.

Also comment about the fact that we know no existing section can have the SHF_EXCLUDE flag.

507

std::find_if

evgeny777 abandoned this revision.Jun 21 2017, 9:05 AM
ELF/Writer.cpp