[lld] r321688 - Don't assume that size relocations are always constant.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 2 19:58:58 PST 2018


Author: rafael
Date: Tue Jan  2 19:58:58 2018
New Revision: 321688

URL: http://llvm.org/viewvc/llvm-project?rev=321688&view=rev
Log:
Don't assume that size relocations are always constant.

Added:
    lld/trunk/test/ELF/relocation-size-err.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=321688&r1=321687&r2=321688&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Jan  2 19:58:58 2018
@@ -367,7 +367,7 @@ static bool isRelExpr(RelExpr Expr) {
 static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym,
                                      InputSectionBase &S, uint64_t RelOff) {
   // These expressions always compute a constant
-  if (isRelExprOneOf<R_SIZE, R_GOT_FROM_END, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE,
+  if (isRelExprOneOf<R_GOT_FROM_END, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE,
                      R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_MIPS_GOT_GP_PC,
                      R_MIPS_TLSGD, R_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC,
                      R_GOTONLY_PC_FROM_END, R_PLT_PC, R_TLSGD_PC, R_TLSGD,
@@ -384,6 +384,10 @@ static bool isStaticLinkTimeConstant(Rel
   if (!Config->Pic)
     return true;
 
+  // The size of a non preemptible symbol is a constant.
+  if (E == R_SIZE)
+    return true;
+
   // For the target and the relocation, we want to know if they are
   // absolute or relative.
   bool AbsVal = isAbsoluteValue(Sym);

Added: lld/trunk/test/ELF/relocation-size-err.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocation-size-err.s?rev=321688&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocation-size-err.s (added)
+++ lld/trunk/test/ELF/relocation-size-err.s Tue Jan  2 19:58:58 2018
@@ -0,0 +1,12 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s
+
+// CHECK:  error: can't create dynamic relocation R_X86_64_SIZE64 against symbol: foo in readonly segment; recompile object files with -fPIC
+
+        .global foo
+foo:
+        .quad 42
+        .size foo, 8
+
+        .quad foo at SIZE




More information about the llvm-commits mailing list