[lld] r298821 - Factor out code to add a GOT entry.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 26 14:00:10 PDT 2017


Author: ruiu
Date: Sun Mar 26 16:00:09 2017
New Revision: 298821

URL: http://llvm.org/viewvc/llvm-project?rev=298821&view=rev
Log:
Factor out code to add a GOT entry.

Modified:
    lld/trunk/ELF/Relocations.cpp

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=298821&r1=298820&r2=298821&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Sun Mar 26 16:00:09 2017
@@ -715,6 +715,32 @@ static void addPltEntry(PltSection *Plt,
   Rel->addReloc({Type, GotPlt, Sym.getGotPltOffset(), UseSymVA, &Sym, 0});
 }
 
+template <class ELFT>
+static void addGotEntry(SymbolBody &Sym, bool Preemptible) {
+  In<ELFT>::Got->addEntry(Sym);
+
+  uint64_t Off = Sym.getGotOffset();
+  uint32_t DynType;
+  RelExpr Expr = R_ABS;
+
+  if (Sym.isTls()) {
+    DynType = Target->TlsGotRel;
+    Expr = R_TLS;
+  } else if (!Preemptible && Config->Pic && !isAbsolute(Sym)) {
+    DynType = Target->RelativeRel;
+  } else {
+    DynType = Target->GotRel;
+  }
+
+  bool Constant = !Preemptible && !(Config->Pic && !isAbsolute(Sym));
+  if (!Constant)
+    In<ELFT>::RelaDyn->addReloc(
+        {DynType, In<ELFT>::Got, Off, !Preemptible, &Sym, 0});
+
+  if (Constant || (!Config->IsRela && !Preemptible))
+    In<ELFT>::Got->Relocations.push_back({Expr, DynType, Off, 0, &Sym});
+}
+
 // The reason we have to do this early scan is as follows
 // * To mmap the output file, we need to know the size
 // * For that, we need to know how many dynamic relocs we will have.
@@ -869,28 +895,8 @@ static void scanRelocs(InputSectionBase
         continue;
       }
 
-      if (Body.isInGot())
-        continue;
-
-      In<ELFT>::Got->addEntry(Body);
-      uint64_t Off = Body.getGotOffset();
-      uint32_t DynType;
-      RelExpr GotRE = R_ABS;
-      if (Body.isTls()) {
-        DynType = Target->TlsGotRel;
-        GotRE = R_TLS;
-      } else if (!Preemptible && Config->Pic && !isAbsolute(Body))
-        DynType = Target->RelativeRel;
-      else
-        DynType = Target->GotRel;
-
-      // FIXME: this logic is almost duplicated above.
-      bool Constant = !Preemptible && !(Config->Pic && !isAbsolute(Body));
-      if (!Constant)
-        In<ELFT>::RelaDyn->addReloc(
-            {DynType, In<ELFT>::Got, Off, !Preemptible, &Body, 0});
-      if (Constant || (!RelTy::IsRela && !Preemptible))
-        In<ELFT>::Got->Relocations.push_back({GotRE, DynType, Off, 0, &Body});
+      if (!Body.isInGot())
+        addGotEntry<ELFT>(Body, Preemptible);
       continue;
     }
   }




More information about the llvm-commits mailing list