[ELF] - Error out when R_X86_64_PC32/R_X86_64_32 are used against preemptible symbol...
authorGeorge Rimar <grimar@accesssoftek.com>
Tue, 29 Mar 2016 08:35:42 +0000 (08:35 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Tue, 29 Mar 2016 08:35:42 +0000 (08:35 +0000)
When R_X86_64_PC32/R_X86_64_32 relocations are
used against preemptible symbol and output is position independent,
error should be generated.

Differential revision: http://reviews.llvm.org/D18190

llvm-svn: 264707

lld/ELF/Target.cpp
lld/test/ELF/Inputs/allow-shlib-undefined.s
lld/test/ELF/Inputs/llvm33-rela-outside-group.o
lld/test/ELF/allow-shlib-undefined.s
lld/test/ELF/llvm33-rela-outside-group.s
lld/test/ELF/lto/linkonce-odr.ll
lld/test/ELF/lto/linkonce.ll
lld/test/ELF/no-undefined.s
lld/test/ELF/x86-64-reloc-32-fpic.s [new file with mode: 0644]
lld/test/ELF/x86-64-reloc-pc32-fpic.s [new file with mode: 0644]

index 5bc6fc0..4f87aac 100644 (file)
@@ -110,6 +110,7 @@ public:
 class X86_64TargetInfo final : public TargetInfo {
 public:
   X86_64TargetInfo();
+  uint32_t getDynRel(uint32_t Type) const override;
   uint32_t getTlsGotRel(uint32_t Type) const override;
   bool pointsToLocalDynamicGotEntry(uint32_t Type) const override;
   bool isTlsLocalDynamicRel(uint32_t Type) const override;
@@ -758,6 +759,14 @@ bool X86_64TargetInfo::needsGot(uint32_t Type, SymbolBody &S) const {
   return refersToGotEntry(Type) || needsPlt(Type, S);
 }
 
+uint32_t X86_64TargetInfo::getDynRel(uint32_t Type) const {
+  if (Type == R_X86_64_PC32 || Type == R_X86_64_32)
+    if (Config->Shared)
+      error(getELFRelocationTypeName(EM_X86_64, Type) +
+            " cannot be a dynamic relocation");
+  return Type;
+}
+
 uint32_t X86_64TargetInfo::getTlsGotRel(uint32_t Type) const {
   // No other types of TLS relocations requiring GOT should
   // reach here.
index e2fb7de..5e3a461 100644 (file)
@@ -1,3 +1,3 @@
 .globl _shared
 _shared:
-  call _unresolved
+  callq _unresolved@PLT
index 2e2f2dc..70e659f 100644 (file)
Binary files a/lld/test/ELF/Inputs/llvm33-rela-outside-group.o and b/lld/test/ELF/Inputs/llvm33-rela-outside-group.o differ
index 541a7e1..2d068b0 100644 (file)
@@ -22,4 +22,4 @@
 
 .globl _start
 _start:
-  call _shared
+  callq _shared@PLT
index 6127537..8e7e7c4 100644 (file)
@@ -8,4 +8,4 @@
 
        .section        .text._Z3fooIiEvv,"axG",@progbits,_Z3fooIiEvv,comdat
 _Z3fooIiEvv:
-       callq   bar
+       callq   bar@PLT
index aca7d0c..569e271 100644 (file)
@@ -1,6 +1,6 @@
 ; REQUIRES: x86
 ; RUN: llvm-as %p/Inputs/linkonce-odr.ll -o %t1.o
-; RUN: llc %s -o %t2.o -filetype=obj
+; RUN: llc -relocation-model=pic %s -o %t2.o -filetype=obj
 ; RUN: ld.lld %t1.o %t2.o -o %t.so -shared -save-temps
 ; RUN: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s
 
index b32ffeb..f980eff 100644 (file)
@@ -1,6 +1,6 @@
 ; REQUIRES: x86
 ; RUN: llvm-as %p/Inputs/linkonce.ll -o %t1.o
-; RUN: llc %s -o %t2.o -filetype=obj
+; RUN: llc -relocation-model=pic %s -o %t2.o -filetype=obj
 ; RUN: ld.lld %t1.o %t2.o -o %t.so -shared -save-temps
 ; RUN: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s
 
index 94378bd..fa4d5e9 100644 (file)
@@ -4,4 +4,4 @@
 
 .globl _shared
 _shared:
-  call _unresolved
+  callq _unresolved@PLT
diff --git a/lld/test/ELF/x86-64-reloc-32-fpic.s b/lld/test/ELF/x86-64-reloc-32-fpic.s
new file mode 100644 (file)
index 0000000..d46c553
--- /dev/null
@@ -0,0 +1,6 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
+# CHECK: R_X86_64_32 cannot be a dynamic relocation
+
+.long _shared
diff --git a/lld/test/ELF/x86-64-reloc-pc32-fpic.s b/lld/test/ELF/x86-64-reloc-pc32-fpic.s
new file mode 100644 (file)
index 0000000..6723177
--- /dev/null
@@ -0,0 +1,6 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
+# CHECK: R_X86_64_PC32 cannot be a dynamic relocation
+
+call _shared