[PATCH] D66717: [ELF] Do not ICF two sections with different output sections (by SECTIONS commands)

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 25 09:13:06 PDT 2019


MaskRay created this revision.
MaskRay added reviewers: grimar, pcc, peter.smith, ruiu.
Herald added subscribers: llvm-commits, kristof.beyls, arichardson, javed.absar, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Fixes PR39418. Complements D47241 <https://reviews.llvm.org/D47241> (the non-linker-script case).

processSectionCommands() assigns input sections to output sections.
ICF is called before it, so .text.foo and .text.bar may be folded even if
their output sections are made different by SECTIONS commands.

  markLive<ELFT>()
  doIcf<ELFT>()                      // During ICF, we don't know the output sections
  writeResult()
    combineEhSections<ELFT>()
    script->processSectionCommands() // InputSection -> OutputSection assignment

This patch splits processSectionCommands() into processSectionCommands() and
processSymbolAssignments():

  markLive<ELFT>()
  script->processSectionCommands()
  doIcf<ELFT>()                  // After ICF, dead input sections should be deleted
  writeResult()
    combineEhSections<ELFT>()    // EhInputSection and .ARM.exidx* are removed
    script->processSymbolAssignments()
      createInputSectionList
        computeInputSections(cmd)

processSectionCommands() is now called before combineEhSections().
EhInputSection and .ARM.exidx* can reach computeInputSections now, so
they should be skipped.

An alternative approach is to unfold sec in processSectionCommands() when we
find sec and sec->repl belong to different output sections. I feel this
patch is superior because the decouple of SectionCommand/SymbolAssignment
gives flexibility:

- An ExprValue can't be evaluated before its section is assigned to an output section -> we can delete getOutputSectionVA and simplify another place where we had to check if the output section is null. Moreover, a case in linkerscript/early-assign-symbol.s can be handled now.
- processSectionCommands/processSymbolAssignments can be freely moved around.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D66717

Files:
  ELF/Driver.cpp
  ELF/ICF.cpp
  ELF/LinkerScript.cpp
  ELF/LinkerScript.h
  ELF/Writer.cpp
  ELF/Writer.h
  test/ELF/linkerscript/early-assign-symbol.s
  test/ELF/linkerscript/icf-different-output-sections.s
  test/ELF/linkerscript/subalign.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66717.217048.patch
Type: text/x-patch
Size: 15181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190825/023a224e/attachment.bin>


More information about the llvm-commits mailing list