[ELF] - X86_64: don't allow 8/16 bit dynamic relocations.
authorGeorge Rimar <grimar@accesssoftek.com>
Tue, 3 Apr 2018 11:58:23 +0000 (11:58 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Tue, 3 Apr 2018 11:58:23 +0000 (11:58 +0000)
Having 8/16 bits dynamic relocations is incorrect.

Both gold and bfd (built from latest sources) disallow
that too.

Differential revision: https://reviews.llvm.org/D45158

llvm-svn: 329059

lld/ELF/Arch/X86_64.cpp
lld/test/ELF/x86-64-dyn-rel-error3.s [new file with mode: 0644]

index a370508..879fe31 100644 (file)
@@ -156,8 +156,9 @@ void X86_64<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,
 }
 
 template <class ELFT> bool X86_64<ELFT>::isPicRel(RelType Type) const {
-  return Type != R_X86_64_PC32 && Type != R_X86_64_32 &&
-         Type != R_X86_64_TPOFF32;
+  return Type != R_X86_64_8 && Type != R_X86_64_PC8 && Type != R_X86_64_16 &&
+         Type != R_X86_64_PC16 && Type != R_X86_64_32 &&
+         Type != R_X86_64_PC32 && Type != R_X86_64_TPOFF32;
 }
 
 template <class ELFT>
diff --git a/lld/test/ELF/x86-64-dyn-rel-error3.s b/lld/test/ELF/x86-64-dyn-rel-error3.s
new file mode 100644 (file)
index 0000000..82a580d
--- /dev/null
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: not ld.lld %t.o -shared -o %t.so 2>&1 | FileCheck %s
+
+# CHECK: relocation R_X86_64_8 cannot be used against symbol foo; recompile with -fPIC
+# CHECK: relocation R_X86_64_16 cannot be used against symbol foo; recompile with -fPIC
+# CHECK: relocation R_X86_64_PC8 cannot be used against symbol foo; recompile with -fPIC
+# CHECK: relocation R_X86_64_PC16 cannot be used against symbol foo; recompile with -fPIC
+
+.global foo
+
+.data
+.byte foo       # R_X86_64_8
+.short foo      # R_X86_64_16
+.byte foo - .   # R_X86_64_PC8
+.short foo - .  # R_X86_64_PC16