Skip to content

[PowerPC][JITLink] Support R_PPC64_GOT_PCREL34 #68658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum EdgeKind_ppc64 : Edge::Kind {
TOCDelta16HI,
TOCDelta16LO,
TOCDelta16LODS,
RequestGOTAndTransformToDelta34,
CallBranchDelta,
// Need to restore r2 after the bl, suggesting the bl is followed by a nop.
CallBranchDeltaRestoreTOC,
Expand Down Expand Up @@ -170,6 +171,10 @@ class TOCTableManager : public TableManager<TOCTableManager<Endianness>> {
// Create TOC section if TOC relocation, PLT or GOT is used.
getOrCreateTOCSection(G);
return false;
case RequestGOTAndTransformToDelta34:
E.setKind(ppc64::Delta34);
E.setTarget(createEntry(G, E.getTarget()));
return true;
default:
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class ELFLinkGraphBuilder_ppc64
if (ELFReloc == ELF::R_PPC64_TLSLD)
return make_error<StringError>("Local-dynamic TLS model is not supported",
inconvertibleErrorCode());
if (ELFReloc == ELF::R_PPC64_PCREL_OPT)
// TODO: Support PCREL optimization, now ignore it.
return Error::success();

auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
if (!ObjSymbol)
Expand Down Expand Up @@ -360,6 +363,9 @@ class ELFLinkGraphBuilder_ppc64
case ELF::R_PPC64_PCREL34:
Kind = ppc64::Delta34;
break;
case ELF::R_PPC64_GOT_PCREL34:
Kind = ppc64::RequestGOTAndTransformToDelta34;
break;
case ELF::R_PPC64_GOT_TLSGD16_HA:
Kind = ppc64::RequestTLSDescInGOTAndTransformToTOCDelta16HA;
break;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/ppc64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ const char *getEdgeKindName(Edge::Kind K) {
return "TOCDelta16LO";
case TOCDelta16LODS:
return "TOCDelta16LODS";
case RequestGOTAndTransformToDelta34:
return "RequestGOTAndTransformToDelta34";
case CallBranchDelta:
return "CallBranchDelta";
case CallBranchDeltaRestoreTOC:
Expand Down
15 changes: 15 additions & 0 deletions llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# RUN: --abs external_addr14_func=0x0880 \
# RUN: --abs external_addr16_data=0x6000 \
# RUN: --abs external_addr32_data=0x36668840 \
# RUN: --abs pcrel_external_var=0x36668860 \
# RUN: --check %s %t/elf_reloc.o
# RUN: llvm-mc --triple=powerpc64-unknown-linux-gnu --filetype=obj -o \
# RUN: %t/elf_reloc.o %s
Expand All @@ -18,6 +19,7 @@
# RUN: --abs external_addr14_func=0x0880 \
# RUN: --abs external_addr16_data=0x6000 \
# RUN: --abs external_addr32_data=0x36668840 \
# RUN: --abs pcrel_external_var=0x36668860 \
# RUN: --check %s %t/elf_reloc.o

# jitlink-check: section_addr(elf_reloc.o, $__GOT) + 0x8000 = __TOC__
Expand Down Expand Up @@ -240,6 +242,19 @@ reloc_rel16:
blr
.size reloc_rel16, .-reloc_rel16

# Check R_PPC64_GOT_PCREL34
# jitlink-check: (got_addr(elf_reloc.o, pcrel_external_var) - reloc_got_pcrel34)[33:0] = \
# jitlink-check: ((((*{4}(reloc_got_pcrel34)) & 0x3ffff) << 16) | ((*{4}(reloc_got_pcrel34 + 4)) & 0xffff))[33:0]
.global reloc_got_pcrel34
.p2align 4
.type reloc_got_pcrel34,@function
reloc_got_pcrel34:
pld 3,pcrel_external_var@got@pcrel(0),1
.Lpcrel0:
.reloc .Lpcrel0-8,R_PPC64_PCREL_OPT,.-(.Lpcrel0-8)
blr
.size reloc_got_pcrel34,.-reloc_got_pcrel34

.type .L.str,@object
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
Expand Down