[PATCH] D67504: [ELF] Make SHF_MERGE merging aware of output sections

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 12 08:53:54 PDT 2019


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

Fixes PR38748

mergeSections() calls getOutputSectionName() to get output section
names. Two MergeInputSections may be merged even if they are made
different by SECTIONS commands.

This patch moves mergeSections() after processSectionCommands() and
addOrphanSections() to fix the issue. The new pass is renamed to
OutputSection::finalizeInputSections().

processSectionCommands() and addorphanSections() are changed to add
sections to InputSectionDescription::sectionBases, which can contain
InputSections and MergeInputSections.

finalizeInputSections() can be thought of an OutputSection-aware
mergeSections(). It merges MergeInputSections into
MergeSyntheticSections, and transforms `sectionBases` into `sections`,
which contains exclusively InputSections.

For the -r case, we drop the rule that creates one output section per
synthetic section in addOrphanSections(). The rule is an optimization
that tries keeping sh_entsize non-zero. It is inconvenient to perform
now because we don't have a uniform mergeSections() pass now.
merge-entsize2.s reflects the change.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D67504

Files:
  ELF/Driver.cpp
  ELF/LinkerScript.cpp
  ELF/LinkerScript.h
  ELF/OutputSections.cpp
  ELF/OutputSections.h
  ELF/Relocations.cpp
  ELF/SyntheticSections.cpp
  ELF/SyntheticSections.h
  ELF/Writer.cpp
  test/ELF/linkerscript/merge-output-sections.s
  test/ELF/linkerscript/merge-sections.s
  test/ELF/merge-entsize2.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67504.219931.patch
Type: text/x-patch
Size: 24785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190912/ebc0a4d9/attachment.bin>


More information about the llvm-commits mailing list