[lld] r329059 - [ELF] - X86_64: don't allow 8/16 bit dynamic relocations.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 04:58:23 PDT 2018


Author: grimar
Date: Tue Apr  3 04:58:23 2018
New Revision: 329059

URL: http://llvm.org/viewvc/llvm-project?rev=329059&view=rev
Log:
[ELF] - X86_64: don't allow 8/16 bit dynamic relocations.

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

Added:
    lld/trunk/test/ELF/x86-64-dyn-rel-error3.s
Modified:
    lld/trunk/ELF/Arch/X86_64.cpp

Modified: lld/trunk/ELF/Arch/X86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86_64.cpp?rev=329059&r1=329058&r2=329059&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86_64.cpp (original)
+++ lld/trunk/ELF/Arch/X86_64.cpp Tue Apr  3 04:58:23 2018
@@ -156,8 +156,9 @@ void X86_64<ELFT>::writePlt(uint8_t *Buf
 }
 
 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>

Added: lld/trunk/test/ELF/x86-64-dyn-rel-error3.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-dyn-rel-error3.s?rev=329059&view=auto
==============================================================================
--- lld/trunk/test/ELF/x86-64-dyn-rel-error3.s (added)
+++ lld/trunk/test/ELF/x86-64-dyn-rel-error3.s Tue Apr  3 04:58:23 2018
@@ -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




More information about the llvm-commits mailing list