[lld] r285317 - Be less aggressive at relaxing got access in this case.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 10:28:57 PDT 2016


Author: rafael
Date: Thu Oct 27 12:28:56 2016
New Revision: 285317

URL: http://llvm.org/viewvc/llvm-project?rev=285317&view=rev
Log:
Be less aggressive at relaxing got access in this case.

This fixes pr30803 by not relaxing that particular access. We could
also let adjustRelaxExpr know that the target is absolute so that it
uses R_RELAX_GOT_PC_NOPIC, but it is not clear if it is worth it.

Added:
    lld/trunk/test/ELF/x86-64-relax-got-abs.s
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=285317&r1=285316&r2=285317&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Oct 27 12:28:56 2016
@@ -286,6 +286,10 @@ template <class ELFT> static bool isAbso
   return false;
 }
 
+template <class ELFT> static bool isAbsoluteValue(const SymbolBody &Body) {
+  return isAbsolute<ELFT>(Body) || Body.isTls();
+}
+
 static bool needsPlt(RelExpr Expr) {
   return Expr == R_PLT_PC || Expr == R_PPC_PLT_OPD || Expr == R_PLT ||
          Expr == R_PLT_PAGE_PC || Expr == R_THUNK_PLT_PC;
@@ -322,7 +326,7 @@ static bool isStaticLinkTimeConstant(Rel
   if (!Config->Pic)
     return true;
 
-  bool AbsVal = isAbsolute<ELFT>(Body) || Body.isTls();
+  bool AbsVal = isAbsoluteValue<ELFT>(Body);
   bool RelE = isRelExpr(E);
   if (AbsVal && !RelE)
     return true;
@@ -433,7 +437,7 @@ static RelExpr adjustExpr(const elf::Obj
   } else if (!Preemptible) {
     if (needsPlt(Expr))
       Expr = fromPlt(Expr);
-    if (Expr == R_GOT_PC)
+    if (Expr == R_GOT_PC && !isAbsoluteValue<ELFT>(Body))
       Expr = Target->adjustRelaxExpr(Type, Data, Expr);
   }
   Expr = Target->getThunkExpr(Expr, Type, File, Body);

Added: lld/trunk/test/ELF/x86-64-relax-got-abs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-relax-got-abs.s?rev=285317&view=auto
==============================================================================
--- lld/trunk/test/ELF/x86-64-relax-got-abs.s (added)
+++ lld/trunk/test/ELF/x86-64-relax-got-abs.s Thu Oct 27 12:28:56 2016
@@ -0,0 +1,16 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -relax-relocations -triple=x86_64-pc-linux %s \
+// RUN:   -o %t.o
+// RUN: ld.lld %t.o -o %t.so -shared
+// RUN: llvm-objdump -d %t.so | FileCheck %s
+
+// We used to fail trying to relax this into a pc relocation to an absolute
+// value.
+
+// CHECK: movq  4185(%rip), %rax
+
+	movq    bar at GOTPCREL(%rip), %rax
+        .data
+        .global bar
+        .hidden bar
+        bar = 42




More information about the llvm-commits mailing list