[lld] r297108 - Remove Config->Rela and define Config->isRela() instead.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 16:43:54 PST 2017


Author: ruiu
Date: Mon Mar  6 18:43:53 2017
New Revision: 297108

URL: http://llvm.org/viewvc/llvm-project?rev=297108&view=rev
Log:
Remove Config->Rela and define Config->isRela() instead.

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

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=297108&r1=297107&r2=297108&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Mon Mar  6 18:43:53 2017
@@ -162,6 +162,26 @@ struct Configuration {
   unsigned Optimize;
   unsigned ThinLTOJobs;
 
+  // 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
+  // the location where the relocations are applied. So, REL is more
+  // compact than RELA but requires a bit of more work to process.
+  //
+  // (From the linker writer's view, this distinction is not necessary.
+  // If the ELF had chosen whichever and sticked with it, it would have
+  // been easier to write code to process relocations, but it's too late
+  // to change the spec.)
+  //
+  // Each ABI defines its relocation type. This function returns that.
+  // 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;
+  }
+
   // Returns true if we need to pass through relocations in input
   // files to the output file. Usually false because we consume
   // relocations.

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=297108&r1=297107&r2=297108&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon Mar  6 18:43:53 2017
@@ -803,8 +803,6 @@ template <class ELFT> void LinkerDriver:
   Target = createTarget();
   ScriptBase = Script<ELFT>::X = make<LinkerScript<ELFT>>();
 
-  Config->Rela =
-      ELFT::Is64Bits || Config->EMachine == EM_X86_64 || Config->MipsN32Abi;
   Config->MaxPageSize = getMaxPageSize(Args);
   Config->ImageBase = getImageBase(Args);
 

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=297108&r1=297107&r2=297108&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Mar  6 18:43:53 2017
@@ -228,7 +228,7 @@ void InputSection::copyRelocations(uint8
     auto *P = reinterpret_cast<typename ELFT::Rela *>(Buf);
     Buf += sizeof(RelTy);
 
-    if (Config->Rela)
+    if (Config->isRela())
       P->r_addend = getAddend<ELFT>(Rel);
 
     // Output section VA is zero for -r, so r_offset is an offset within the
@@ -254,7 +254,7 @@ void InputSection::copyRelocations(uint8
         continue;
       }
 
-      if (Config->Rela) {
+      if (Config->isRela()) {
         P->r_addend += Body.getVA<ELFT>() - Section->OutSec->Addr;
       } else if (Config->Relocatable) {
         const uint8_t *BufLoc = RelocatedSection->Data.begin() + Rel.r_offset;

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=297108&r1=297107&r2=297108&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Mar  6 18:43:53 2017
@@ -1087,7 +1087,7 @@ template <class ELFT> void DynamicSectio
 
   this->Link = In<ELFT>::DynStrTab->OutSec->SectionIndex;
   if (In<ELFT>::RelaDyn->OutSec->Size > 0) {
-    bool IsRela = Config->Rela;
+    bool IsRela = Config->isRela();
     add({IsRela ? DT_RELA : DT_REL, In<ELFT>::RelaDyn});
     add({IsRela ? DT_RELASZ : DT_RELSZ, In<ELFT>::RelaDyn->OutSec->Size});
     add({IsRela ? DT_RELAENT : DT_RELENT,
@@ -1107,7 +1107,7 @@ template <class ELFT> void DynamicSectio
     add({DT_PLTRELSZ, In<ELFT>::RelaPlt->OutSec->Size});
     add({Config->EMachine == EM_MIPS ? DT_MIPS_PLTGOT : DT_PLTGOT,
          In<ELFT>::GotPlt});
-    add({DT_PLTREL, uint64_t(Config->Rela ? DT_RELA : DT_REL)});
+    add({DT_PLTREL, uint64_t(Config->isRela() ? DT_RELA : DT_REL)});
   }
 
   add({DT_SYMTAB, In<ELFT>::DynSymTab});
@@ -1215,10 +1215,10 @@ template <class ELFT> uint32_t DynamicRe
 
 template <class ELFT>
 RelocationSection<ELFT>::RelocationSection(StringRef Name, bool Sort)
-    : SyntheticSection(SHF_ALLOC, Config->Rela ? SHT_RELA : SHT_REL,
+    : SyntheticSection(SHF_ALLOC, Config->isRela() ? SHT_RELA : SHT_REL,
                        sizeof(uintX_t), Name),
       Sort(Sort) {
-  this->Entsize = Config->Rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
+  this->Entsize = Config->isRela() ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
 }
 
 template <class ELFT>
@@ -1242,9 +1242,9 @@ template <class ELFT> void RelocationSec
   uint8_t *BufBegin = Buf;
   for (const DynamicReloc<ELFT> &Rel : Relocs) {
     auto *P = reinterpret_cast<Elf_Rela *>(Buf);
-    Buf += Config->Rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
+    Buf += Config->isRela() ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
 
-    if (Config->Rela)
+    if (Config->isRela())
       P->r_addend = Rel.getAddend();
     P->r_offset = Rel.getOffset();
     if (Config->EMachine == EM_MIPS && Rel.getInputSec() == In<ELFT>::MipsGot)
@@ -1256,7 +1256,7 @@ template <class ELFT> void RelocationSec
   }
 
   if (Sort) {
-    if (Config->Rela)
+    if (Config->isRela())
       std::stable_sort((Elf_Rela *)BufBegin,
                        (Elf_Rela *)BufBegin + Relocs.size(),
                        compRelocations<ELFT, Elf_Rela>);

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=297108&r1=297107&r2=297108&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Mar  6 18:43:53 2017
@@ -312,7 +312,7 @@ template <class ELFT> void Writer<ELFT>:
   In<ELFT>::DynStrTab = make<StringTableSection<ELFT>>(".dynstr", true);
   In<ELFT>::Dynamic = make<DynamicSection<ELFT>>();
   In<ELFT>::RelaDyn = make<RelocationSection<ELFT>>(
-      Config->Rela ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc);
+      Config->isRela() ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc);
   In<ELFT>::ShStrTab = make<StringTableSection<ELFT>>(".shstrtab", false);
 
   Out::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC);
@@ -421,7 +421,7 @@ template <class ELFT> void Writer<ELFT>:
   // We always need to add rel[a].plt to output if it has entries.
   // Even for static linking it can contain R_[*]_IRELATIVE relocations.
   In<ELFT>::RelaPlt = make<RelocationSection<ELFT>>(
-      Config->Rela ? ".rela.plt" : ".rel.plt", false /*Sort*/);
+      Config->isRela() ? ".rela.plt" : ".rel.plt", false /*Sort*/);
   Add(In<ELFT>::RelaPlt);
 
   // The RelaIplt immediately follows .rel.plt (.rel.dyn for ARM) to ensure
@@ -774,10 +774,10 @@ static Symbol *addOptionalRegular(String
 template <class ELFT> void Writer<ELFT>::addRelIpltSymbols() {
   if (In<ELFT>::DynSymTab)
     return;
-  StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start";
+  StringRef S = Config->isRela() ? "__rela_iplt_start" : "__rel_iplt_start";
   addOptionalRegular<ELFT>(S, In<ELFT>::RelaIplt, 0);
 
-  S = Config->Rela ? "__rela_iplt_end" : "__rel_iplt_end";
+  S = Config->isRela() ? "__rela_iplt_end" : "__rel_iplt_end";
   addOptionalRegular<ELFT>(S, In<ELFT>::RelaIplt, -1);
 }
 




More information about the llvm-commits mailing list