Skip to content

Commit a712244

Browse files
author
Kai Luo
authored
[PowerPC][JITLink] Support R_PPC64_GOT_PCREL34 (#68658)
`R_PPC64_GOT_PCREL34` is generated for pwr10+.
1 parent fbe47bf commit a712244

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum EdgeKind_ppc64 : Edge::Kind {
5151
TOCDelta16HI,
5252
TOCDelta16LO,
5353
TOCDelta16LODS,
54+
RequestGOTAndTransformToDelta34,
5455
CallBranchDelta,
5556
// Need to restore r2 after the bl, suggesting the bl is followed by a nop.
5657
CallBranchDeltaRestoreTOC,
@@ -170,6 +171,10 @@ class TOCTableManager : public TableManager<TOCTableManager<Endianness>> {
170171
// Create TOC section if TOC relocation, PLT or GOT is used.
171172
getOrCreateTOCSection(G);
172173
return false;
174+
case RequestGOTAndTransformToDelta34:
175+
E.setKind(ppc64::Delta34);
176+
E.setTarget(createEntry(G, E.getTarget()));
177+
return true;
173178
default:
174179
return false;
175180
}

llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ class ELFLinkGraphBuilder_ppc64
234234
if (ELFReloc == ELF::R_PPC64_TLSLD)
235235
return make_error<StringError>("Local-dynamic TLS model is not supported",
236236
inconvertibleErrorCode());
237+
if (ELFReloc == ELF::R_PPC64_PCREL_OPT)
238+
// TODO: Support PCREL optimization, now ignore it.
239+
return Error::success();
237240

238241
auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
239242
if (!ObjSymbol)
@@ -360,6 +363,9 @@ class ELFLinkGraphBuilder_ppc64
360363
case ELF::R_PPC64_PCREL34:
361364
Kind = ppc64::Delta34;
362365
break;
366+
case ELF::R_PPC64_GOT_PCREL34:
367+
Kind = ppc64::RequestGOTAndTransformToDelta34;
368+
break;
363369
case ELF::R_PPC64_GOT_TLSGD16_HA:
364370
Kind = ppc64::RequestTLSDescInGOTAndTransformToTOCDelta16HA;
365371
break;

llvm/lib/ExecutionEngine/JITLink/ppc64.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ const char *getEdgeKindName(Edge::Kind K) {
120120
return "TOCDelta16LO";
121121
case TOCDelta16LODS:
122122
return "TOCDelta16LODS";
123+
case RequestGOTAndTransformToDelta34:
124+
return "RequestGOTAndTransformToDelta34";
123125
case CallBranchDelta:
124126
return "CallBranchDelta";
125127
case CallBranchDeltaRestoreTOC:

llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# RUN: --abs external_addr14_func=0x0880 \
99
# RUN: --abs external_addr16_data=0x6000 \
1010
# RUN: --abs external_addr32_data=0x36668840 \
11+
# RUN: --abs pcrel_external_var=0x36668860 \
1112
# RUN: --check %s %t/elf_reloc.o
1213
# RUN: llvm-mc --triple=powerpc64-unknown-linux-gnu --filetype=obj -o \
1314
# RUN: %t/elf_reloc.o %s
@@ -18,6 +19,7 @@
1819
# RUN: --abs external_addr14_func=0x0880 \
1920
# RUN: --abs external_addr16_data=0x6000 \
2021
# RUN: --abs external_addr32_data=0x36668840 \
22+
# RUN: --abs pcrel_external_var=0x36668860 \
2123
# RUN: --check %s %t/elf_reloc.o
2224

2325
# jitlink-check: section_addr(elf_reloc.o, $__GOT) + 0x8000 = __TOC__
@@ -240,6 +242,19 @@ reloc_rel16:
240242
blr
241243
.size reloc_rel16, .-reloc_rel16
242244

245+
# Check R_PPC64_GOT_PCREL34
246+
# jitlink-check: (got_addr(elf_reloc.o, pcrel_external_var) - reloc_got_pcrel34)[33:0] = \
247+
# jitlink-check: ((((*{4}(reloc_got_pcrel34)) & 0x3ffff) << 16) | ((*{4}(reloc_got_pcrel34 + 4)) & 0xffff))[33:0]
248+
.global reloc_got_pcrel34
249+
.p2align 4
250+
.type reloc_got_pcrel34,@function
251+
reloc_got_pcrel34:
252+
pld 3,pcrel_external_var@got@pcrel(0),1
253+
.Lpcrel0:
254+
.reloc .Lpcrel0-8,R_PPC64_PCREL_OPT,.-(.Lpcrel0-8)
255+
blr
256+
.size reloc_got_pcrel34,.-reloc_got_pcrel34
257+
243258
.type .L.str,@object
244259
.section .rodata.str1.1,"aMS",@progbits,1
245260
.L.str:

0 commit comments

Comments
 (0)