[lld] r254309 - [ELF] - Split RelocationSection<ELFT>::writeTo function.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 30 09:49:19 PST 2015


Author: grimar
Date: Mon Nov 30 11:49:19 2015
New Revision: 254309

URL: http://llvm.org/viewvc/llvm-project?rev=254309&view=rev
Log:
[ELF] - Split RelocationSection<ELFT>::writeTo function.

Splitted writeTo to separate tls relocs handling stuff which is too long for one method now. NFC.

Differential revision: http://reviews.llvm.org/D15012

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=254309&r1=254308&r2=254309&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Nov 30 11:49:19 2015
@@ -193,6 +193,31 @@ RelocationSection<ELFT>::RelocationSecti
   this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
 }
 
+// Applies corresponding symbol and type for dynamic tls relocation.
+// Returns true if relocation was handled.
+template <class ELFT>
+bool RelocationSection<ELFT>::applyTlsDynamicReloc(SymbolBody *Body,
+                                                   uint32_t Type, Elf_Rel *P,
+                                                   Elf_Rel *N) {
+  if (Target->isTlsLocalDynamicReloc(Type)) {
+    P->setSymbolAndType(0, Target->getTlsModuleIndexReloc(), Config->Mips64EL);
+    P->r_offset =
+        Out<ELFT>::Got->getVA() + Out<ELFT>::LocalModuleTlsIndexOffset;
+    return true;
+  }
+
+  if (Body && Target->isTlsGlobalDynamicReloc(Type)) {
+    P->setSymbolAndType(Body->getDynamicSymbolTableIndex(),
+                        Target->getTlsModuleIndexReloc(), Config->Mips64EL);
+    P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body);
+    N->setSymbolAndType(Body->getDynamicSymbolTableIndex(),
+                        Target->getTlsOffsetReloc(), Config->Mips64EL);
+    N->r_offset = Out<ELFT>::Got->getEntryAddr(*Body) + sizeof(uintX_t);
+    return true;
+  }
+  return false;
+}
+
 template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
   const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
   for (const DynamicReloc<ELFT> &Rel : Relocs) {
@@ -213,26 +238,8 @@ template <class ELFT> void RelocationSec
       Body = Body->repl();
 
     uint32_t Type = RI.getType(Config->Mips64EL);
-
-    if (Target->isTlsLocalDynamicReloc(Type)) {
-      P->setSymbolAndType(0, Target->getTlsModuleIndexReloc(),
-                          Config->Mips64EL);
-      P->r_offset =
-          Out<ELFT>::Got->getVA() + Out<ELFT>::LocalModuleTlsIndexOffset;
+    if (applyTlsDynamicReloc(Body, Type, P, reinterpret_cast<Elf_Rel *>(Buf)))
       continue;
-    }
-
-    if (Body && Target->isTlsGlobalDynamicReloc(Type)) {
-      P->setSymbolAndType(Body->getDynamicSymbolTableIndex(),
-                          Target->getTlsModuleIndexReloc(), Config->Mips64EL);
-      P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body);
-      auto *PNext = reinterpret_cast<Elf_Rel *>(Buf);
-      PNext->setSymbolAndType(Body->getDynamicSymbolTableIndex(),
-                              Target->getTlsOffsetReloc(), Config->Mips64EL);
-      PNext->r_offset = Out<ELFT>::Got->getEntryAddr(*Body) + sizeof(uintX_t);
-      continue;
-    }
-
     bool NeedsCopy = Body && Target->relocNeedsCopy(Type, *Body);
     bool NeedsGot = Body && Target->relocNeedsGot(Type, *Body);
     bool CanBePreempted = canBePreempted(Body, NeedsGot);

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=254309&r1=254308&r2=254309&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Mon Nov 30 11:49:19 2015
@@ -223,6 +223,9 @@ public:
   bool isRela() const { return IsRela; }
 
 private:
+  bool applyTlsDynamicReloc(SymbolBody *Body, uint32_t Type, Elf_Rel *P,
+                            Elf_Rel *N);
+
   std::vector<DynamicReloc<ELFT>> Relocs;
   const bool IsRela;
 };




More information about the llvm-commits mailing list