[lld] r298792 - Add comments and return early.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 25 20:20:30 PDT 2017


Author: ruiu
Date: Sat Mar 25 22:20:30 2017
New Revision: 298792

URL: http://llvm.org/viewvc/llvm-project?rev=298792&view=rev
Log:
Add comments and return early.

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=298792&r1=298791&r2=298792&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Sat Mar 25 22:20:30 2017
@@ -312,6 +312,15 @@ static bool isRelExpr(RelExpr Expr) {
                         R_PAGE_PC, R_RELAX_GOT_PC>(Expr);
 }
 
+// Returns true if a given relocation can be computed at link-time.
+//
+// For instance, we know the offset from a relocation to its target at
+// link-time if the relocation is PC-relative and refers a
+// (non-interruptible) function in the same executable. This function
+// will return true for such relocation.
+//
+// If this function returns false, that means we need to emit a
+// dynamic relocation so that the relocation will be fixed at load-time.
 template <class ELFT>
 static bool
 isStaticLinkTimeConstant(RelExpr E, uint32_t Type, const SymbolBody &Body,
@@ -331,16 +340,19 @@ isStaticLinkTimeConstant(RelExpr E, uint
 
   if (isPreemptible(Body, Type))
     return false;
-
   if (!Config->Pic)
     return true;
 
+  // For the target and the relocation, we want to know if they are
+  // absolute or relative.
   bool AbsVal = isAbsoluteValue<ELFT>(Body);
   bool RelE = isRelExpr(E);
   if (AbsVal && !RelE)
     return true;
   if (!AbsVal && RelE)
     return true;
+  if (!AbsVal && !RelE)
+    return Target->usesOnlyLowPageBits(Type);
 
   // Relative relocation to an absolute value. This is normally unrepresentable,
   // but if the relocation refers to a weak undefined symbol, we allow it to
@@ -350,16 +362,14 @@ isStaticLinkTimeConstant(RelExpr E, uint
   // Another special case is MIPS _gp_disp symbol which represents offset
   // between start of a function and '_gp' value and defined as absolute just
   // to simplify the code.
-  if (AbsVal && RelE) {
-    if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
-      return true;
-    error(S.getLocation<ELFT>(RelOff) + ": relocation " + toString(Type) +
-          " cannot refer to absolute symbol '" + toString(Body) +
-          "' defined in " + toString(Body.File));
+  assert(AbsVal && RelE);
+  if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
     return true;
-  }
 
-  return Target->usesOnlyLowPageBits(Type);
+  error(S.getLocation<ELFT>(RelOff) + ": relocation " + toString(Type) +
+        " cannot refer to absolute symbol '" + toString(Body) +
+        "' defined in " + toString(Body.File));
+  return true;
 }
 
 static RelExpr toPlt(RelExpr Expr) {




More information about the llvm-commits mailing list