ELF: Add .interp synthetic sections first in createSyntheticSections().
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 1 Oct 2019 16:10:13 +0000 (16:10 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 1 Oct 2019 16:10:13 +0000 (16:10 +0000)
commit0bb825d20880003c50c9c1a5985db6bc54e57b26
tree216f6b2dfd964d393472021c43ec8508d0f66f5d
parente53680002228149efd8fd7d7ca9b9e1612504a9e
ELF: Add .interp synthetic sections first in createSyntheticSections().

Our .interp section is not a SyntheticSection. As a result, it terminates the
loop in removeUnusedSyntheticSections(). This has at least two consequences:

- The synthetic .bss and .bss.rel.ro sections are always present in
  dynamically linked executables, even when they are not needed.
- The synthetic .ARM.exidx (and possibly other) sections are always present
  in partitions other than the last one, even when not needed.
  .ARM.exidx in particular is problematic because it assumes that its
  list of code sections is non-empty in getLinkOrderDep(), which can
  lead to a crash if the partition does not have any code sections.

Fix these problems by moving the creation of the .interp sections to the
top of createSyntheticSections(). While here, make the code a little less
error-prone by changing the add() lambdas to take a SyntheticSection instead
of an InputSectionBase.

Differential Revision: https://reviews.llvm.org/D68256

llvm-svn: 373347
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp
lld/test/ELF/Inputs/shared.s
lld/test/ELF/dynamic-linker.s
lld/test/ELF/partition-dynamic-linker.s [new file with mode: 0644]