[lld] r349511 - [PPC64] Support got-based relocations.
Sean Fertile via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 18 09:34:27 PST 2018
Author: sfertile
Date: Tue Dec 18 09:34:26 2018
New Revision: 349511
URL: http://llvm.org/viewvc/llvm-project?rev=349511&view=rev
Log:
[PPC64] Support got-based relocations.
Differential Revison: https://reviews.llvm.org/D54859
Added:
lld/trunk/test/ELF/ppc64-got-off.s
Modified:
lld/trunk/ELF/Arch/PPC64.cpp
Modified: lld/trunk/ELF/Arch/PPC64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC64.cpp?rev=349511&r1=349510&r2=349511&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp (original)
+++ lld/trunk/ELF/Arch/PPC64.cpp Tue Dec 18 09:34:26 2018
@@ -412,6 +412,13 @@ void PPC64::relaxTlsIeToLe(uint8_t *Loc,
RelExpr PPC64::getRelExpr(RelType Type, const Symbol &S,
const uint8_t *Loc) const {
switch (Type) {
+ case R_PPC64_GOT16:
+ case R_PPC64_GOT16_DS:
+ case R_PPC64_GOT16_HA:
+ case R_PPC64_GOT16_HI:
+ case R_PPC64_GOT16_LO:
+ case R_PPC64_GOT16_LO_DS:
+ return R_GOT_OFF;
case R_PPC64_TOC16:
case R_PPC64_TOC16_DS:
case R_PPC64_TOC16_HA:
@@ -526,30 +533,36 @@ static std::pair<RelType, uint64_t> toAd
switch (Type) {
// TOC biased relocation.
+ case R_PPC64_GOT16:
case R_PPC64_GOT_TLSGD16:
case R_PPC64_GOT_TLSLD16:
case R_PPC64_TOC16:
return {R_PPC64_ADDR16, TocBiasedVal};
+ case R_PPC64_GOT16_DS:
case R_PPC64_TOC16_DS:
case R_PPC64_GOT_TPREL16_DS:
case R_PPC64_GOT_DTPREL16_DS:
return {R_PPC64_ADDR16_DS, TocBiasedVal};
+ case R_PPC64_GOT16_HA:
case R_PPC64_GOT_TLSGD16_HA:
case R_PPC64_GOT_TLSLD16_HA:
case R_PPC64_GOT_TPREL16_HA:
case R_PPC64_GOT_DTPREL16_HA:
case R_PPC64_TOC16_HA:
return {R_PPC64_ADDR16_HA, TocBiasedVal};
+ case R_PPC64_GOT16_HI:
case R_PPC64_GOT_TLSGD16_HI:
case R_PPC64_GOT_TLSLD16_HI:
case R_PPC64_GOT_TPREL16_HI:
case R_PPC64_GOT_DTPREL16_HI:
case R_PPC64_TOC16_HI:
return {R_PPC64_ADDR16_HI, TocBiasedVal};
+ case R_PPC64_GOT16_LO:
case R_PPC64_GOT_TLSGD16_LO:
case R_PPC64_GOT_TLSLD16_LO:
case R_PPC64_TOC16_LO:
return {R_PPC64_ADDR16_LO, TocBiasedVal};
+ case R_PPC64_GOT16_LO_DS:
case R_PPC64_TOC16_LO_DS:
case R_PPC64_GOT_TPREL16_LO_DS:
case R_PPC64_GOT_DTPREL16_LO_DS:
@@ -590,9 +603,11 @@ static bool isTocRelType(RelType Type) {
}
void PPC64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
- // For a TOC-relative relocation, proceed in terms of the corresponding
- // ADDR16 relocation type.
+ // We need to save the original relocation type to determine if we should
+ // toc-optimize the instructions being relocated.
bool IsTocRelType = isTocRelType(Type);
+ // For TOC-relative and GOT-indirect relocations, proceed in terms of the
+ // corresponding ADDR16 relocation type.
std::tie(Type, Val) = toAddr16Rel(Type, Val);
switch (Type) {
Added: lld/trunk/test/ELF/ppc64-got-off.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ppc64-got-off.s?rev=349511&view=auto
==============================================================================
--- lld/trunk/test/ELF/ppc64-got-off.s (added)
+++ lld/trunk/test/ELF/ppc64-got-off.s Tue Dec 18 09:34:26 2018
@@ -0,0 +1,50 @@
+# REQUIRES: ppc
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
+# RUN: ld.lld -shared --no-toc-optimize %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
+# RUN: ld.lld -shared --no-toc-optimize %t.o -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+
+ .abiversion 2
+ .section ".text"
+
+ .p2align 2
+ .global func
+ .type func, @function
+func:
+.Lfunc_gep:
+ addis 2, 12, .TOC.-.Lfunc_gep at ha
+ addi 2, 2, .TOC.-.Lfunc_gep at l
+.Lfunc_lep:
+ .localentry func, .-func
+ addis 3, 2, a at got@ha
+ ld 3, a at got@l(3)
+ ld 4, a at got(2)
+ lis 5, a at got@h
+ ori 5, 5, a at got@l
+ li 6, 0
+ ori 6, 6, a at got
+ blr
+
+# CHECK-LABEL: func
+# CHECK: addis 3, 2, 0
+# CHECK-NEXT: ld 3, -32760(3)
+# CHECK-NEXT: ld 4, -32760(2)
+# CHECK-NEXT: lis 5, -1
+# CHECK-NEXT: ori 5, 5, 32776
+# CHECK-NEXT: li 6, 0
+# CHECK-NEXT: ori 6, 6, 32776
+
+# Since the got entry for a is .got[1] and the TOC base points to
+# .got + 0x8000, the offset for a at got is -0x7FF8 --> -32760
+
+ .section ".data"
+ .global a
+ .type a, @object
+ .size a, 4
+ .p2align 2
+a:
+ .long 0x1000
More information about the llvm-commits
mailing list