diff options
| author | Rui Ueyama <ruiu@google.com> | 2017-06-26 15:11:24 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2017-06-26 15:11:24 +0000 |
| commit | 92c37819598bf893a4e057c046259024ec7f51a1 (patch) | |
| tree | af51c2a08a451301a9f23e71d51e7fa2ab1715f4 | |
| parent | 19520027daa33b4dafde82bcc3530f1aa635eaf1 (diff) | |
| download | bcm5719-llvm-92c37819598bf893a4e057c046259024ec7f51a1.tar.gz bcm5719-llvm-92c37819598bf893a4e057c046259024ec7f51a1.zip | |
Add GlobalOffsetTable to ElfSym. NFC.
Most "reserved" symbols are in ElfSym and it looks like there's no
reason to not do the same thing for _GLOBAL_OFFSET_TABLE_. This should
help https://reviews.llvm.org/D34618 too.
llvm-svn: 306292
| -rw-r--r-- | lld/ELF/Symbols.cpp | 1 | ||||
| -rw-r--r-- | lld/ELF/Symbols.h | 5 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 15 |
3 files changed, 13 insertions, 8 deletions
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 8f9b20477b2..5dce71a32c9 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -35,6 +35,7 @@ DefinedRegular *ElfSym::Edata1; DefinedRegular *ElfSym::Edata2; DefinedRegular *ElfSym::End1; DefinedRegular *ElfSym::End2; +DefinedRegular *ElfSym::GlobalOffsetTable; DefinedRegular *ElfSym::MipsGp; DefinedRegular *ElfSym::MipsGpDisp; DefinedRegular *ElfSym::MipsLocalGp; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index f30b389506a..406fd8e0f57 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -318,6 +318,11 @@ struct ElfSym { static DefinedRegular *End1; static DefinedRegular *End2; + // The _GLOBAL_OFFSET_TABLE_ symbol is defined by target convention to + // be at some offset from the base of the .got section, usually 0 or + // the end of the .got. + static DefinedRegular *GlobalOffsetTable; + // _gp, _gp_disp and __gnu_local_gp symbols. Only for MIPS. static DefinedRegular *MipsGp; static DefinedRegular *MipsGpDisp; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index deb1b214c70..4c12b18836b 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -820,10 +820,10 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() { // The _GLOBAL_OFFSET_TABLE_ symbol is defined by target convention to // be at some offset from the base of the .got section, usually 0 or the end // of the .got - InputSection *GotSection = (InX::MipsGot) ? cast<InputSection>(InX::MipsGot) - : cast<InputSection>(InX::Got); - HasGotBaseSym = addOptionalRegular<ELFT>("_GLOBAL_OFFSET_TABLE_", GotSection, - Target->GotBaseSymOff) != nullptr; + InputSection *GotSection = InX::MipsGot ? cast<InputSection>(InX::MipsGot) + : cast<InputSection>(InX::Got); + ElfSym::GlobalOffsetTable = addOptionalRegular<ELFT>( + "_GLOBAL_OFFSET_TABLE_", GotSection, Target->GotBaseSymOff); // __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 @@ -1132,8 +1132,7 @@ static void applySynthetic(const std::vector<SyntheticSection *> &Sections, // to make them visible from linkescript side. But not all sections are always // required to be in output. For example we don't need dynamic section content // sometimes. This function filters out such unused sections from the output. -static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V, - bool HasGotBaseSym) { +static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V) { // All input synthetic sections that can be empty are placed after // all regular ones. We iterate over them all and exit at first // non-synthetic. @@ -1144,7 +1143,7 @@ static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V, OutputSection *OS = SS->getParent(); if (!SS->empty() || !OS) continue; - if ((SS == InX::Got || SS == InX::MipsGot) && HasGotBaseSym) + if ((SS == InX::Got || SS == InX::MipsGot) && ElfSym::GlobalOffsetTable) continue; OS->Sections.erase(std::find(OS->Sections.begin(), OS->Sections.end(), SS)); SS->Live = false; @@ -1219,7 +1218,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { return; addPredefinedSections(); - removeUnusedSyntheticSections(OutputSections, HasGotBaseSym); + removeUnusedSyntheticSections(OutputSections); clearOutputSections(); sortSections(); |

