[lld] r321311 - Call isStaticLinkTimeConstant only once per relocation.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 21 13:45:35 PST 2017


Author: rafael
Date: Thu Dec 21 13:45:35 2017
New Revision: 321311

URL: http://llvm.org/viewvc/llvm-project?rev=321311&view=rev
Log:
Call isStaticLinkTimeConstant only once per relocation.

It is a pretty expensive function. Some of the speedups:

clang: 1.92%
chrome: 1.15%
linux-kernel: 1.40%

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=321311&r1=321310&r2=321311&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Dec 21 13:45:35 2017
@@ -556,7 +556,8 @@ static void errorOrWarn(const Twine &Msg
 
 template <class ELFT>
 static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type,
-                          InputSectionBase &S, uint64_t RelOff) {
+                          InputSectionBase &S, uint64_t RelOff,
+                          bool &IsConstant) {
   // We can create any dynamic relocation if a section is simply writable.
   if (S.Flags & SHF_WRITE)
     return Expr;
@@ -569,7 +570,7 @@ static RelExpr adjustExpr(Symbol &Sym, R
 
   // If a relocation can be applied at link-time, we don't need to
   // create a dynamic relocation in the first place.
-  if (isStaticLinkTimeConstant<ELFT>(Expr, Type, Sym, S, RelOff))
+  if (IsConstant)
     return Expr;
 
   // If we got here we know that this relocation would require the dynamic
@@ -579,6 +580,7 @@ static RelExpr adjustExpr(Symbol &Sym, R
   // non preemptible 0.
   if (Sym.isUndefWeak()) {
     Sym.IsPreemptible = false;
+    IsConstant = true;
     return Expr;
   }
 
@@ -611,6 +613,7 @@ static RelExpr adjustExpr(Symbol &Sym, R
 
       addCopyRelSymbol<ELFT>(B);
     }
+    IsConstant = true;
     return Expr;
   }
 
@@ -637,6 +640,7 @@ static RelExpr adjustExpr(Symbol &Sym, R
     // R_386_JMP_SLOT, etc).
     Sym.NeedsPltAddr = true;
     Sym.IsPreemptible = false;
+    IsConstant = true;
     return toPlt(Expr);
   }
 
@@ -923,7 +927,10 @@ static void scanRelocs(InputSectionBase
     else if (!Preemptible)
       Expr = fromPlt(Expr);
 
-    Expr = adjustExpr<ELFT>(Sym, Expr, Type, Sec, Rel.r_offset);
+    bool IsConstant =
+        isStaticLinkTimeConstant<ELFT>(Expr, Type, Sym, Sec, Rel.r_offset);
+
+    Expr = adjustExpr<ELFT>(Sym, Expr, Type, Sec, Rel.r_offset, IsConstant);
     if (errorCount())
       continue;
 
@@ -1005,10 +1012,6 @@ static void scanRelocs(InputSectionBase
       continue;
     }
 
-    // If the relocation points to something in the file, we can process it.
-    bool IsConstant =
-        isStaticLinkTimeConstant<ELFT>(Expr, Type, Sym, Sec, Rel.r_offset);
-
     // The size is not going to change, so we fold it in here.
     if (Expr == R_SIZE)
       Addend += Sym.getSize();




More information about the llvm-commits mailing list