[lld] r306292 - Add GlobalOffsetTable to ElfSym. NFC.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 26 08:11:24 PDT 2017
Author: ruiu
Date: Mon Jun 26 08:11:24 2017
New Revision: 306292
URL: http://llvm.org/viewvc/llvm-project?rev=306292&view=rev
Log:
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.
Modified:
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Symbols.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=306292&r1=306291&r2=306292&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Mon Jun 26 08:11:24 2017
@@ -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;
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=306292&r1=306291&r2=306292&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Mon Jun 26 08:11:24 2017
@@ -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;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=306292&r1=306291&r2=306292&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Jun 26 08:11:24 2017
@@ -820,10 +820,10 @@ template <class ELFT> void Writer<ELFT>:
// 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::ve
// 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 removeUnusedSyntheticSection
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>:
return;
addPredefinedSections();
- removeUnusedSyntheticSections(OutputSections, HasGotBaseSym);
+ removeUnusedSyntheticSections(OutputSections);
clearOutputSections();
sortSections();
More information about the llvm-commits
mailing list