summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Writer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/Writer.cpp')
-rw-r--r--lld/ELF/Writer.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 61683acee67..976632d265b 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -292,6 +292,23 @@ template <class ELFT> void Writer<ELFT>::createSections() {
Map[{BssSec.getName(), BssSec.getType(), BssSec.getFlags()}] = &BssSec;
SymbolTable &Symtab = SymTabSec.getSymTable();
+
+ // Declare linker generated symbols.
+ // This must be done before the relocation scan to make sure we can correctly
+ // decide if a dynamic relocation is needed or not.
+ // FIXME: Make this more declarative.
+ for (StringRef Name :
+ {"__preinit_array_start", "__preinit_array_end", "__init_array_start",
+ "__init_array_end", "__fini_array_start", "__fini_array_end"})
+ Symtab.addIgnoredSym<ELFT>(Name);
+
+ // __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For
+ // static linking the linker is required to optimize away any references to
+ // __tls_get_addr, so it's not defined anywhere. Create a hidden definition
+ // to avoid the undefined symbol error.
+ if (!isOutputDynamic())
+ Symtab.addIgnoredSym<ELFT>("__tls_get_addr");
+
for (const std::unique_ptr<ObjectFileBase> &FileB : Symtab.getObjectFiles()) {
auto &File = cast<ObjectFile<ELFT>>(*FileB);
if (!Config->DiscardAll) {
@@ -331,9 +348,6 @@ template <class ELFT> void Writer<ELFT>::createSections() {
if (OS) {
Symtab.addSyntheticSym<ELFT>(Start, *OS, 0);
Symtab.addSyntheticSym<ELFT>(End, *OS, OS->getSize());
- } else {
- Symtab.addIgnoredSym<ELFT>(Start);
- Symtab.addIgnoredSym<ELFT>(End);
}
};
@@ -344,13 +358,6 @@ template <class ELFT> void Writer<ELFT>::createSections() {
AddStartEnd("__fini_array_start", "__fini_array_end",
DynamicSec.FiniArraySec);
- // __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For
- // static linking the linker is required to optimize away any references to
- // __tls_get_addr, so it's not defined anywhere. Create a hidden definition
- // to avoid the undefined symbol error.
- if (!isOutputDynamic())
- Symtab.addIgnoredSym<ELFT>("__tls_get_addr");
-
// FIXME: Try to avoid the extra walk over all global symbols.
std::vector<DefinedCommon<ELFT> *> CommonSymbols;
for (auto &P : Symtab.getSymbols()) {
OpenPOWER on IntegriCloud