diff options
| author | Fangrui Song <maskray@google.com> | 2018-06-13 23:29:28 +0000 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2018-06-13 23:29:28 +0000 |
| commit | 4ff63648adf243678869daa5359cdfd6b822bc81 (patch) | |
| tree | 654cc31bfbbc7c6988c1dd2de0387cfe637151ef | |
| parent | b8b248cf2e0fdd6b5449aaecb6b060b6050f6b72 (diff) | |
| download | bcm5719-llvm-4ff63648adf243678869daa5359cdfd6b822bc81.tar.gz bcm5719-llvm-4ff63648adf243678869daa5359cdfd6b822bc81.zip | |
[ELF][X86_64] Use R_GOTREL_FROM_END instead of R_GOTREL for R_X86_64_GOTOFF64
Summary:
R_X86_64_GOTOFF64: S + A - GOT
R_X86_64_GOTPC{32,64}: GOT + A - P (R_GOTONLY_PC_FROM_END)
R_X86_64_GOTOFF64 should use R_GOTREL_FROM_END so that in conjunction with
R_X86_64_GOTPC{32,64}, the `GOT` term is neutralized. This also matches
the handling of R_386_GOTOFF (S + A - GOT).
Reviewers: ruiu, espindola
Subscribers: emaste, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D48095
llvm-svn: 334672
| -rw-r--r-- | lld/ELF/Arch/X86_64.cpp | 2 | ||||
| -rw-r--r-- | lld/test/ELF/x86-64-reloc-gotoff64.s | 39 | ||||
| -rw-r--r-- | lld/test/ELF/x86-64-reloc-gotpc64.s (renamed from lld/test/ELF/x86-64-reloc-got.s) | 10 |
3 files changed, 30 insertions, 21 deletions
diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp index 2a6d22a3015..52771c401b4 100644 --- a/lld/ELF/Arch/X86_64.cpp +++ b/lld/ELF/Arch/X86_64.cpp @@ -106,7 +106,7 @@ RelExpr X86_64<ELFT>::getRelExpr(RelType Type, const Symbol &S, case R_X86_64_GOTTPOFF: return R_GOT_PC; case R_X86_64_GOTOFF64: - return R_GOTREL; + return R_GOTREL_FROM_END; case R_X86_64_GOTPC32: case R_X86_64_GOTPC64: return R_GOTONLY_PC_FROM_END; diff --git a/lld/test/ELF/x86-64-reloc-gotoff64.s b/lld/test/ELF/x86-64-reloc-gotoff64.s index 91df28af642..697ac17917a 100644 --- a/lld/test/ELF/x86-64-reloc-gotoff64.s +++ b/lld/test/ELF/x86-64-reloc-gotoff64.s @@ -1,17 +1,32 @@ // 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 +// RUN: ld.lld %t.o -shared -o %t.so +// RUN: llvm-readelf -s %t.so | FileCheck %s -check-prefix=SECTION +// RUN: llvm-objdump -d %t.so | FileCheck %s + +// SECTION: .dynamic DYNAMIC 0000000000003000 +// SECTION: .got PROGBITS 0000000000003070 003070 000000 -// CHECK: .dynamic DYNAMIC 0000000000002000 002000 -// CHECK: .got PROGBITS 0000000000002070 002070 +// All the _GLOBAL_OFFSET_TABLE_ occurrences below refer to the address +// of GOT base, not the address of the symbol _GLOBAL_OFFSET_TABLE_. These +// instructions are special and produce GOT base relative relocations. We +// currently use .got end as the GOT base, which is not equal to +// the address of the special symbol _GLOBAL_OFFSET_TABLE_. -// DISASM: 1000: 48 ba 90 ff ff ff ff ff ff ff movabsq $-112, %rdx +// The assembly is generated by +// gcc -O2 -S -mcmodel=medium -fPIC a.c +// This computes the pc-relative address (runtime address) of _DYNAMIC. +// +// extern long _DYNAMIC[] __attribute__((visibility("hidden"))); +// long* dynamic() { return _DYNAMIC; } -.global _start -.weak _DYNAMIC -.hidden _DYNAMIC -_start: - movabsq $_DYNAMIC@GOTOFF, %rdx +// 0x3070 (.got end) - 0x1007 = 8297 +// 0x3000 (_DYNAMIC) - 0x3070 (.got end) = -112 +// CHECK: 1000: {{.*}} leaq 8297(%rip), %rdx +// CHECK-NEXT: 1007: {{.*}} movabsq $-112, %rax +.global dynamic +dynamic: + leaq _GLOBAL_OFFSET_TABLE_(%rip), %rdx + movabsq $_DYNAMIC@GOTOFF, %rax + addq %rdx, %rax + ret diff --git a/lld/test/ELF/x86-64-reloc-got.s b/lld/test/ELF/x86-64-reloc-gotpc64.s index fd95b1feac8..f07376f4121 100644 --- a/lld/test/ELF/x86-64-reloc-got.s +++ b/lld/test/ELF/x86-64-reloc-gotpc64.s @@ -6,15 +6,9 @@ // SECTION: .got PROGBITS 0000000000003070 003070 000000 -// 0x3070 (.got end) - 0x1007 = 8297 -// CHECK: gotpc32: -// CHECK-NEXT: 1000: {{.*}} leaq 8297(%rip), %r15 -.global gotpc32 -gotpc32: - leaq _GLOBAL_OFFSET_TABLE_(%rip), %r15 - +// 0x3070 (.got end) - 0x1000 = 8304 // CHECK: gotpc64: -// CHECK-NEXT: 1007: {{.*}} movabsq $8297, %r11 +// CHECK-NEXT: 1000: {{.*}} movabsq $8304, %r11 .global gotpc64 gotpc64: movabsq $_GLOBAL_OFFSET_TABLE_-., %r11 |

