mirror of
https://github.com/intel/llvm.git
synced 2026-01-23 07:58:23 +08:00
[ELF][PPC64] Don't apply LD->LE relaxation on R_PPC64_GOT_DTPREL16*
In ELF v2 ABI, R_PPC64_GOT_DTPREL16* are not relaxed. This family of relocation types are used for variables outside of 2GiB of the TLS block. 2 instructions cannot materialize a DTPREL offset that is not 32-bit. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D62737 llvm-svn: 362357
This commit is contained in:
@@ -445,10 +445,6 @@ void PPC64::relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {
|
||||
case R_PPC64_DTPREL16_DS:
|
||||
case R_PPC64_DTPREL16_LO:
|
||||
case R_PPC64_DTPREL16_LO_DS:
|
||||
case R_PPC64_GOT_DTPREL16_HA:
|
||||
case R_PPC64_GOT_DTPREL16_LO_DS:
|
||||
case R_PPC64_GOT_DTPREL16_DS:
|
||||
case R_PPC64_GOT_DTPREL16_HI:
|
||||
relocateOne(Loc, Type, Val);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -257,13 +257,8 @@ handleTlsRelocation(RelType Type, Symbol &Sym, InputSectionBase &C,
|
||||
}
|
||||
|
||||
// Local-Dynamic sequence where offset of tls variable relative to dynamic
|
||||
// thread pointer is stored in the got.
|
||||
// thread pointer is stored in the got. This cannot be relaxed to Local-Exec.
|
||||
if (Expr == R_TLSLD_GOT_OFF) {
|
||||
// Local-Dynamic relocs can be relaxed to local-exec
|
||||
if (!Config->Shared) {
|
||||
C.Relocations.push_back({R_RELAX_TLS_LD_TO_LE, Type, Offset, Addend, &Sym});
|
||||
return 1;
|
||||
}
|
||||
if (!Sym.isInGot()) {
|
||||
In.Got->addEntry(Sym);
|
||||
uint64_t Off = Sym.getGotOffset();
|
||||
|
||||
@@ -97,15 +97,6 @@ test_not_adjusted:
|
||||
mtlr 0
|
||||
blr
|
||||
|
||||
.globl test_got_dtprel
|
||||
.p2align 4
|
||||
.type test_got_dtprel,@function
|
||||
test_got_dtprel:
|
||||
addis 3, 2, i@got@dtprel@ha
|
||||
ld 3, i@got@dtprel@l(3)
|
||||
addis 3, 2, i@got@dtprel@h
|
||||
addi 3, 2, i@got@dtprel
|
||||
|
||||
.section .debug_addr,"",@progbits
|
||||
.quad i@dtprel+32768
|
||||
|
||||
@@ -137,10 +128,6 @@ k:
|
||||
// InputRelocs: R_PPC64_DTPREL16_HIGHER {{[0-9a-f]+}} k + 0
|
||||
// InputRelocs: R_PPC64_DTPREL16_HI {{[0-9a-f]+}} k + 0
|
||||
// InputRelocs: R_PPC64_DTPREL16_LO {{[0-9a-f]+}} k + 0
|
||||
// InputRelocs: R_PPC64_GOT_DTPREL16_HA {{[0-9a-f]+}} i + 0
|
||||
// InputRelocs: R_PPC64_GOT_DTPREL16_LO_DS {{[0-9a-f]+}} i + 0
|
||||
// InputRelocs: R_PPC64_GOT_DTPREL16_HI {{[0-9a-f]+}} i + 0
|
||||
// InputRelocs: R_PPC64_GOT_DTPREL16_DS {{[0-9a-f]+}} i + 0
|
||||
// InputRelocs: Relocation section '.rela.debug_addr'
|
||||
// InputRelocs: R_PPC64_DTPREL64 {{[0-9a-f]+}} i + 8000
|
||||
|
||||
@@ -154,11 +141,11 @@ k:
|
||||
// i@dtprel = 1024 - 0x8000 = -31744 = 0xffffffffffff8400
|
||||
// HEX-LE: section '.got':
|
||||
// HEX-LE-NEXT: 4204f8 f8844200 00000000 00000000 00000000
|
||||
// HEX-LE-NEXT: 420508 00000000 00000000 0084ffff ffffffff
|
||||
// HEX-LE-NEXT: 420508 00000000 00000000
|
||||
|
||||
// HEX-BE: section '.got':
|
||||
// HEX-BE-NEXT: 4204f8 00000000 004284f8 00000000 00000000
|
||||
// HEX-BE-NEXT: 420508 00000000 00000000 ffffffff ffff8400
|
||||
// HEX-BE-NEXT: 420508 00000000 00000000
|
||||
|
||||
// Dis: test:
|
||||
// Dis: addi 4, 3, -31744
|
||||
@@ -186,12 +173,3 @@ k:
|
||||
// Dis: oris 4, 4, 63
|
||||
// Dis: ori 4, 4, 33796
|
||||
|
||||
// #ha(i@got@dtprel) = ((0x420510 - (.got+0x8000) + 0x8000) >> 16) & 0xffff = 0
|
||||
// #lo(i@got@dtprel) = (0x420510 - (.got+0x8000)) & 0xffff = -32744
|
||||
// #hi(i@got@dtprel) = ((0x420510 - (.got+0x8000)) >> 16) & 0xffff = -1
|
||||
// i@got@dtprel --> 0x420510 - (.got+0x8000) = -32744
|
||||
// Dis: test_got_dtprel:
|
||||
// Dis: addis 3, 2, 0
|
||||
// Dis: ld 3, -32744(3)
|
||||
// Dis: addis 3, 2, -1
|
||||
// Dis: addi 3, 2, -32744
|
||||
|
||||
44
lld/test/ELF/ppc64-ld-got-dtprel.s
Normal file
44
lld/test/ELF/ppc64-ld-got-dtprel.s
Normal file
@@ -0,0 +1,44 @@
|
||||
# REQUIRES: ppc
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
|
||||
# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=RELOCS %s
|
||||
# RUN: ld.lld -shared %t.o -o %t.so
|
||||
# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s
|
||||
## Check LD->LE relaxation does not affect R_PPC64_GOT_DTPREL16*.
|
||||
# RUN: ld.lld %t.o -o %t
|
||||
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t.o
|
||||
# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=RELOCS %s
|
||||
# RUN: ld.lld -shared %t.o -o %t.so
|
||||
# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s
|
||||
# RUN: ld.lld %t.o -o %t
|
||||
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
|
||||
|
||||
# RELOCS: .rela.text {
|
||||
# RELOCS-NEXT: R_PPC64_GOT_DTPREL16_HA i 0x0
|
||||
# RELOCS-NEXT: R_PPC64_GOT_DTPREL16_LO_DS i 0x0
|
||||
# RELOCS-NEXT: R_PPC64_GOT_DTPREL16_HI j 0x0
|
||||
# RELOCS-NEXT: R_PPC64_GOT_DTPREL16_DS j 0x0
|
||||
# RELOCS-NEXT: }
|
||||
|
||||
## ha(i@got@dtprel) = (&.got[0] - (.got+0x8000) + 0x8000 >> 16) & 0xffff = 0
|
||||
## lo(i@got@dtprel) = &.got[0] - (.got+0x8000) & 0xffff = -32768
|
||||
## hi(j@got@dtprel) = (&.got[1] - (.got+0x8000) >> 16) & 0xffff = -1
|
||||
## j@got@dtprel = &.got[1] - (.got+0x8000) = -32760
|
||||
# CHECK: addis 3, 2, 0
|
||||
# CHECK-NEXT: ld 3, -32768(3)
|
||||
# CHECK-NEXT: addis 3, 2, -1
|
||||
# CHECK-NEXT: addi 3, 2, -32760
|
||||
|
||||
addis 3, 2, i@got@dtprel@ha
|
||||
ld 3, i@got@dtprel@l(3)
|
||||
addis 3, 2, j@got@dtprel@h
|
||||
addi 3, 2, j@got@dtprel
|
||||
|
||||
.section .tbss,"awT",@progbits
|
||||
.p2align 2
|
||||
i:
|
||||
.long 0
|
||||
j:
|
||||
.long 0
|
||||
Reference in New Issue
Block a user