diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-10-24 20:46:21 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-10-24 20:46:21 +0000 |
commit | 0fab40b9150219e224b65d3dfea3aa10c75455c6 (patch) | |
tree | c08ffe88f200c9e930071f1f0a2c72a5c0b5266e | |
parent | a905007f12e8f2f30065d38b80ebd0100f3f39d4 (diff) | |
download | bcm5719-llvm-0fab40b9150219e224b65d3dfea3aa10c75455c6.tar.gz bcm5719-llvm-0fab40b9150219e224b65d3dfea3aa10c75455c6.zip |
ELF: Simplify handling of *_start/*_end symbols.
We were previously using the (static) addSynthetic function to create
*_start/*_end symbols. This function was doing almost the same thing as
addOptionalSynthetic, except that it would also create the symbol in the
case where it is unreferenced. Because the symbol has hidden visibility,
creating it in that case would have no effect other than adding another
entry to the static symbol table. Remove addSynthetic and change callers to
use addOptionalSynthetic instead.
Differential Revision: https://reviews.llvm.org/D25545
llvm-svn: 285021
-rw-r--r-- | lld/ELF/Writer.cpp | 18 | ||||
-rw-r--r-- | lld/test/ELF/gc-sections.s | 6 |
2 files changed, 3 insertions, 21 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 6ca49918947..417060fa2d9 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -559,14 +559,6 @@ addOptionalSynthetic(StringRef Name, OutputSectionBase<ELFT> *Sec, return Symtab<ELFT>::X->addSynthetic(Name, Sec, Val, StOther); } -template <class ELFT> -static void addSynthetic(StringRef Name, OutputSectionBase<ELFT> *Sec, - typename ELFT::uint Val) { - SymbolBody *S = Symtab<ELFT>::X->find(Name); - if (!S || S->isUndefined() || S->isShared()) - Symtab<ELFT>::X->addSynthetic(Name, Sec, Val, STV_HIDDEN); -} - // The beginning and the ending of .rel[a].plt section are marked // with __rel[a]_iplt_{start,end} symbols if it is a statically linked // executable. The runtime needs these symbols in order to resolve @@ -953,13 +945,9 @@ template <class ELFT> void Writer<ELFT>::addPredefinedSections() { template <class ELFT> void Writer<ELFT>::addStartEndSymbols() { auto Define = [&](StringRef Start, StringRef End, OutputSectionBase<ELFT> *OS) { - if (OS) { - addSynthetic(Start, OS, 0); - addSynthetic(End, OS, DefinedSynthetic<ELFT>::SectionEnd); - } else { - addOptionalSynthetic(Start, (OutputSectionBase<ELFT> *)nullptr, 0); - addOptionalSynthetic(End, (OutputSectionBase<ELFT> *)nullptr, 0); - } + // These symbols resolve to the image base if the section does not exist. + addOptionalSynthetic(Start, OS, 0); + addOptionalSynthetic(End, OS, OS ? DefinedSynthetic<ELFT>::SectionEnd : 0); }; Define("__preinit_array_start", "__preinit_array_end", diff --git a/lld/test/ELF/gc-sections.s b/lld/test/ELF/gc-sections.s index b00d915da1b..f100153ec35 100644 --- a/lld/test/ELF/gc-sections.s +++ b/lld/test/ELF/gc-sections.s @@ -21,8 +21,6 @@ # NOGC: Name: c # NOGC: Name: x # NOGC: Name: y -# NOGC: Name: __preinit_array_start -# NOGC: Name: __preinit_array_end # NOGC: Name: d # GC1: Name: .eh_frame @@ -38,8 +36,6 @@ # GC1: Name: c # GC1-NOT: Name: x # GC1-NOT: Name: y -# GC1: Name: __preinit_array_start -# GC1: Name: __preinit_array_end # GC1-NOT: Name: d # GC2: Name: .eh_frame @@ -55,8 +51,6 @@ # GC2: Name: c # GC2-NOT: Name: x # GC2-NOT: Name: y -# GC2: Name: __preinit_array_start -# GC2: Name: __preinit_array_end # GC2: Name: d .globl _start, d |