summaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2018-06-12 20:27:16 +0000
committerRui Ueyama <ruiu@google.com>2018-06-12 20:27:16 +0000
commit8a8d8cf9834cdc00bdd184f6fa43a7f9f19e3edb (patch)
tree5d2cce8c952c54f9b97a1e10f18378c679f2d2ed /lld
parent9dd2a4a5440cc4fecb90cfe2ec6b4fa55c0398d4 (diff)
Handle R_X86_64_GOTOFF64.
R_X86_64_GOTOFF64 is a relocation type to set to a distance betwween a symbol and the beginning of the .got section. Previously, we always created a dynamic relocation for the relocation type even though it can be resolved at link-time. Creating a dynamic relocation for R_X86_64_GOTOFF64 caused link failure for some programs that do have a relocation of the type in a .text section, as text relocations are prohibited in most configurations. Differential Revision: https://reviews.llvm.org/D48058
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/Arch/X86_64.cpp3
-rw-r--r--lld/test/ELF/x86-64-reloc-gotoff64.s17
2 files changed, 20 insertions, 0 deletions
diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index e4993c3ad09..2a6d22a3015 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -105,6 +105,8 @@ RelExpr X86_64<ELFT>::getRelExpr(RelType Type, const Symbol &S,
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_GOTTPOFF:
return R_GOT_PC;
+ case R_X86_64_GOTOFF64:
+ return R_GOTREL;
case R_X86_64_GOTPC32:
case R_X86_64_GOTPC64:
return R_GOTONLY_PC_FROM_END;
@@ -323,6 +325,7 @@ void X86_64<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
case R_X86_64_PC64:
case R_X86_64_SIZE64:
case R_X86_64_GOT64:
+ case R_X86_64_GOTOFF64:
case R_X86_64_GOTPC64:
write64le(Loc, Val);
break;
diff --git a/lld/test/ELF/x86-64-reloc-gotoff64.s b/lld/test/ELF/x86-64-reloc-gotoff64.s
new file mode 100644
index 00000000000..91df28af642
--- /dev/null
+++ b/lld/test/ELF/x86-64-reloc-gotoff64.s
@@ -0,0 +1,17 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld -shared -o %t.so %t.o
+// RUN: llvm-readelf -sections %t.so | FileCheck %s
+// RUN: llvm-objdump -d %t.so | FileCheck -check-prefix=DISASM %s
+
+// CHECK: .dynamic DYNAMIC 0000000000002000 002000
+// CHECK: .got PROGBITS 0000000000002070 002070
+
+// DISASM: 1000: 48 ba 90 ff ff ff ff ff ff ff movabsq $-112, %rdx
+
+.global _start
+.weak _DYNAMIC
+.hidden _DYNAMIC
+_start:
+ movabsq $_DYNAMIC@GOTOFF, %rdx