This is an archive of the discontinued LLVM Phabricator instance.

ELF: Add .interp synthetic sections first in createSyntheticSections().
ClosedPublic

Authored by pcc on Sep 30 2019, 7:03 PM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Sep 30 2019, 7:03 PM

Looks good. Thanks for catching the issues.

lld/ELF/Writer.cpp
321 ↗(On Diff #222536)

i = 1; i <= partitions.size(); ++i to use i instead of i + 1 below.

lld/test/ELF/dynamic-linker.s
7 ↗(On Diff #222536)

While here, use double-dash form for llvm-readelf: --program-headers --section-headers

lld/test/ELF/partition-dynamic-linker.s
9 ↗(On Diff #222536)

--section-headers

ruiu accepted this revision.Sep 30 2019, 11:48 PM

LGTM

This revision is now accepted and ready to land.Sep 30 2019, 11:48 PM
grimar accepted this revision.Oct 1 2019, 1:55 AM

LGTM with a minor nit.

lld/test/ELF/dynamic-linker.s
10 ↗(On Diff #222536)

Perhaps a bit better would be to use FileCheck %s --implicit-check-not=.bss here and above.
That removes a dependency on the order of program/sections headers printed (recently there were patches that changed the output order back and forth to be more GNU-output compatible).

This revision was automatically updated to reflect the committed changes.