[lld] r297813 - [ELF] - Detemplate GotPltSection and IgotPltSection sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 15 02:12:56 PDT 2017


Author: grimar
Date: Wed Mar 15 04:12:56 2017
New Revision: 297813

URL: http://llvm.org/viewvc/llvm-project?rev=297813&view=rev
Log:
[ELF] - Detemplate GotPltSection and IgotPltSection sections.

Patch introduces Config->is64Bit() and with help of that detemplates
GotPltSection and IgotPltSection sections

Differential revision: https://reviews.llvm.org/D30944

Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=297813&r1=297812&r2=297813&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed Mar 15 04:12:56 2017
@@ -162,6 +162,9 @@ struct Configuration {
   unsigned Optimize;
   unsigned ThinLTOJobs;
 
+  // Returns true if target is 64 bit.
+  bool is64Bit() const { return EKind == ELF64LEKind || EKind == ELF64BEKind; }
+
   // The ELF spec defines two types of relocation table entries, RELA and
   // REL. RELA is a triplet of (offset, info, addend) while REL is a
   // tuple of (offset, info). Addends for REL are implicit and read from
@@ -177,9 +180,8 @@ struct Configuration {
   // As far as we know, all 64-bit ABIs are using RELA. A few 32-bit ABIs
   // are using RELA too.
   bool isRela() const {
-    bool is64 = (EKind == ELF64LEKind || EKind == ELF64BEKind);
-    bool isX32Abi = (EKind == ELF32LEKind && EMachine == llvm::ELF::EM_X86_64);
-    return is64 || isX32Abi || MipsN32Abi;
+    bool IsX32Abi = (EKind == ELF32LEKind && EMachine == llvm::ELF::EM_X86_64);
+    return is64Bit() || IsX32Abi || MipsN32Abi;
   }
 
   // Returns true if we need to pass through relocations in input

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=297813&r1=297812&r2=297813&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Mar 15 04:12:56 2017
@@ -937,52 +937,50 @@ template <class ELFT> void MipsGotSectio
   }
 }
 
-template <class ELFT>
-GotPltSection<ELFT>::GotPltSection()
+GotPltSection::GotPltSection()
     : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,
                        Target->GotPltEntrySize, ".got.plt") {}
 
-template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody &Sym) {
+void GotPltSection::addEntry(SymbolBody &Sym) {
   Sym.GotPltIndex = Target->GotPltHeaderEntriesNum + Entries.size();
   Entries.push_back(&Sym);
 }
 
-template <class ELFT> size_t GotPltSection<ELFT>::getSize() const {
+size_t GotPltSection::getSize() const {
   return (Target->GotPltHeaderEntriesNum + Entries.size()) *
          Target->GotPltEntrySize;
 }
 
-template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) {
+void GotPltSection::writeTo(uint8_t *Buf) {
   Target->writeGotPltHeader(Buf);
   Buf += Target->GotPltHeaderEntriesNum * Target->GotPltEntrySize;
   for (const SymbolBody *B : Entries) {
     Target->writeGotPlt(Buf, *B);
-    Buf += sizeof(uintX_t);
+    Buf += Config->is64Bit() ? 8 : 4;
   }
 }
 
 // On ARM the IgotPltSection is part of the GotSection, on other Targets it is
 // part of the .got.plt
-template <class ELFT>
-IgotPltSection<ELFT>::IgotPltSection()
+IgotPltSection::IgotPltSection()
     : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,
                        Target->GotPltEntrySize,
                        Config->EMachine == EM_ARM ? ".got" : ".got.plt") {}
 
-template <class ELFT> void IgotPltSection<ELFT>::addEntry(SymbolBody &Sym) {
+void IgotPltSection::addEntry(SymbolBody &Sym) {
   Sym.IsInIgot = true;
   Sym.GotPltIndex = Entries.size();
   Entries.push_back(&Sym);
 }
 
-template <class ELFT> size_t IgotPltSection<ELFT>::getSize() const {
+size_t IgotPltSection::getSize() const {
   return Entries.size() * Target->GotPltEntrySize;
 }
 
-template <class ELFT> void IgotPltSection<ELFT>::writeTo(uint8_t *Buf) {
+void IgotPltSection::writeTo(uint8_t *Buf) {
   for (const SymbolBody *B : Entries) {
     Target->writeIgotPlt(Buf, *B);
-    Buf += sizeof(uintX_t);
+    Buf += Config->is64Bit() ? 8 : 4;
   }
 }
 
@@ -2324,16 +2322,6 @@ template class elf::MipsGotSection<ELF32
 template class elf::MipsGotSection<ELF64LE>;
 template class elf::MipsGotSection<ELF64BE>;
 
-template class elf::GotPltSection<ELF32LE>;
-template class elf::GotPltSection<ELF32BE>;
-template class elf::GotPltSection<ELF64LE>;
-template class elf::GotPltSection<ELF64BE>;
-
-template class elf::IgotPltSection<ELF32LE>;
-template class elf::IgotPltSection<ELF32BE>;
-template class elf::IgotPltSection<ELF64LE>;
-template class elf::IgotPltSection<ELF64BE>;
-
 template class elf::StringTableSection<ELF32LE>;
 template class elf::StringTableSection<ELF32BE>;
 template class elf::StringTableSection<ELF64LE>;

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=297813&r1=297812&r2=297813&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Wed Mar 15 04:12:56 2017
@@ -265,9 +265,7 @@ private:
   uintX_t Size = 0;
 };
 
-template <class ELFT> class GotPltSection final : public SyntheticSection {
-  typedef typename ELFT::uint uintX_t;
-
+class GotPltSection final : public SyntheticSection {
 public:
   GotPltSection();
   void addEntry(SymbolBody &Sym);
@@ -283,9 +281,7 @@ private:
 // Symbols that will be relocated by Target->IRelativeRel.
 // On most Targets the IgotPltSection will immediately follow the GotPltSection
 // on ARM the IgotPltSection will immediately follow the GotSection.
-template <class ELFT> class IgotPltSection final : public SyntheticSection {
-  typedef typename ELFT::uint uintX_t;
-
+class IgotPltSection final : public SyntheticSection {
 public:
   IgotPltSection();
   void addEntry(SymbolBody &Sym);
@@ -773,8 +769,8 @@ template <class ELFT> struct In {
   static GotSection<ELFT> *Got;
   static EhFrameSection<ELFT> *EhFrame;
   static MipsGotSection<ELFT> *MipsGot;
-  static GotPltSection<ELFT> *GotPlt;
-  static IgotPltSection<ELFT> *IgotPlt;
+  static GotPltSection *GotPlt;
+  static IgotPltSection *IgotPlt;
   static HashTableSection<ELFT> *HashTab;
   static InputSection *Interp;
   static MipsRldMapSection<ELFT> *MipsRldMap;
@@ -803,8 +799,8 @@ template <class ELFT> GnuHashTableSectio
 template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
 template <class ELFT> EhFrameSection<ELFT> *In<ELFT>::EhFrame;
 template <class ELFT> MipsGotSection<ELFT> *In<ELFT>::MipsGot;
-template <class ELFT> GotPltSection<ELFT> *In<ELFT>::GotPlt;
-template <class ELFT> IgotPltSection<ELFT> *In<ELFT>::IgotPlt;
+template <class ELFT> GotPltSection *In<ELFT>::GotPlt;
+template <class ELFT> IgotPltSection *In<ELFT>::IgotPlt;
 template <class ELFT> HashTableSection<ELFT> *In<ELFT>::HashTab;
 template <class ELFT> InputSection *In<ELFT>::Interp;
 template <class ELFT> MipsRldMapSection<ELFT> *In<ELFT>::MipsRldMap;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=297813&r1=297812&r2=297813&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Mar 15 04:12:56 2017
@@ -428,9 +428,9 @@ template <class ELFT> void Writer<ELFT>:
     Add(In<ELFT>::Got);
   }
 
-  In<ELFT>::GotPlt = make<GotPltSection<ELFT>>();
+  In<ELFT>::GotPlt = make<GotPltSection>();
   Add(In<ELFT>::GotPlt);
-  In<ELFT>::IgotPlt = make<IgotPltSection<ELFT>>();
+  In<ELFT>::IgotPlt = make<IgotPltSection>();
   Add(In<ELFT>::IgotPlt);
 
   if (Config->GdbIndex) {




More information about the llvm-commits mailing list