[llvm] [PowerPC][JITLink] Support R_PPC64_GOT_TLSGD_PCREL34 (PR #68660)
Kai Luo via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 21:54:56 PDT 2023
https://github.com/bzEq updated https://github.com/llvm/llvm-project/pull/68660
>From 4b0f4431fd664c149b0694e4f17b0ed64c97f2e4 Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Tue, 10 Oct 2023 12:56:08 +0800
Subject: [PATCH 1/3] Support R_PPC64_GOT_TLSGD_PCREL34
---
.../llvm/ExecutionEngine/JITLink/ppc64.h | 1 +
llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp | 16 ++++++++++++----
llvm/lib/ExecutionEngine/JITLink/ppc64.cpp | 2 ++
.../JITLink/ppc64/ELF_ppc64_relocations.s | 18 ++++++++++++++++++
4 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h b/llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
index 88af15d61e714e1..252dc1647639da6 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
@@ -60,6 +60,7 @@ enum EdgeKind_ppc64 : Edge::Kind {
RequestCallNoTOC,
RequestTLSDescInGOTAndTransformToTOCDelta16HA,
RequestTLSDescInGOTAndTransformToTOCDelta16LO,
+ RequestTLSDescInGOTAndTransformToDelta34,
};
enum PLTCallStubKind {
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
index 5ce7a5bda840239..46f38b99ec8687b 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
@@ -43,17 +43,22 @@ class TLSInfoTableManager_ELF_ppc64
bool visitEdge(LinkGraph &G, Block *B, Edge &E) {
Edge::Kind K = E.getKind();
- if (K == ppc64::RequestTLSDescInGOTAndTransformToTOCDelta16HA) {
+ switch (K) {
+ case ppc64::RequestTLSDescInGOTAndTransformToTOCDelta16HA:
E.setKind(ppc64::TOCDelta16HA);
E.setTarget(this->getEntryForTarget(G, E.getTarget()));
return true;
- }
- if (K == ppc64::RequestTLSDescInGOTAndTransformToTOCDelta16LO) {
+ case ppc64::RequestTLSDescInGOTAndTransformToTOCDelta16LO:
E.setKind(ppc64::TOCDelta16LO);
E.setTarget(this->getEntryForTarget(G, E.getTarget()));
return true;
+ case ppc64::RequestTLSDescInGOTAndTransformToDelta34:
+ E.setKind(ppc64::Delta34);
+ E.setTarget(this->getEntryForTarget(G, E.getTarget()));
+ return true;
+ default:
+ return false;
}
- return false;
}
Symbol &createEntry(LinkGraph &G, Symbol &Target) {
@@ -366,6 +371,9 @@ class ELFLinkGraphBuilder_ppc64
case ELF::R_PPC64_GOT_TLSGD16_LO:
Kind = ppc64::RequestTLSDescInGOTAndTransformToTOCDelta16LO;
break;
+ case ELF::R_PPC64_GOT_TLSGD_PCREL34:
+ Kind = ppc64::RequestTLSDescInGOTAndTransformToDelta34;
+ break;
}
Edge GE(Kind, Offset, *GraphSymbol, Addend);
diff --git a/llvm/lib/ExecutionEngine/JITLink/ppc64.cpp b/llvm/lib/ExecutionEngine/JITLink/ppc64.cpp
index b147ffc8dac2175..a96ad15c6a32ee1 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ppc64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ppc64.cpp
@@ -132,6 +132,8 @@ const char *getEdgeKindName(Edge::Kind K) {
return "RequestTLSDescInGOTAndTransformToTOCDelta16HA";
case RequestTLSDescInGOTAndTransformToTOCDelta16LO:
return "RequestTLSDescInGOTAndTransformToTOCDelta16LO";
+ case RequestTLSDescInGOTAndTransformToDelta34:
+ return "RequestTLSDescInGOTAndTransformToDelta34";
default:
return getGenericEdgeKindName(static_cast<Edge::Kind>(K));
}
diff --git a/llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s b/llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s
index 7e39a20ef6ab8b0..4034aa115d7d7a2 100644
--- a/llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s
+++ b/llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s
@@ -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_tls=0x36668880 \
# RUN: --check %s %t/elf_reloc.o
# RUN: llvm-mc --triple=powerpc64-unknown-linux-gnu --filetype=obj -o \
# RUN: %t/elf_reloc.o %s
@@ -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_tls=0x36668880 \
# RUN: --check %s %t/elf_reloc.o
# jitlink-check: section_addr(elf_reloc.o, $__GOT) + 0x8000 = __TOC__
@@ -240,6 +242,22 @@ reloc_rel16:
blr
.size reloc_rel16, .-reloc_rel16
+ .global reloc_tlsgd_pcrel34
+ .p2align 4
+ .type reloc_tlsgd_pcrel34, at function
+reloc_tlsgd_pcrel34:
+ mflr 0
+ std 0, 16(1)
+ stdu 1, -32(1)
+ paddi 3, 0, pcrel_external_tls at got@tlsgd at pcrel, 1
+ bl __tls_get_addr at notoc(a at tlsgd)
+ lwa 3, 0(3)
+ addi 1, 1, 32
+ ld 0, 16(1)
+ mtlr 0
+ blr
+ .size reloc_tlsgd_pcrel34,.-reloc_tlsgd_pcrel34
+
.type .L.str, at object
.section .rodata.str1.1,"aMS", at progbits,1
.L.str:
>From 6b2faf455587e49e9dea43d85ea1a9bffb8336cb Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Wed, 11 Oct 2023 10:55:04 +0800
Subject: [PATCH 2/3] R_PPC64_TPREL34 unsupported
---
llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
index 46f38b99ec8687b..e2c50276d92d405 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
@@ -239,6 +239,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_TPREL34)
+ return make_error<StringError>("Local-exec TLS model is not supported",
+ inconvertibleErrorCode());
auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
if (!ObjSymbol)
>From 036ca30cd3ac3532c81b1ead3ff81a872d4426da Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Wed, 11 Oct 2023 12:54:39 +0800
Subject: [PATCH 3/3] No __tls_get_addr under windows
---
llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s b/llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s
index 4034aa115d7d7a2..2257560809c4e0c 100644
--- a/llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s
+++ b/llvm/test/ExecutionEngine/JITLink/ppc64/ELF_ppc64_relocations.s
@@ -1,3 +1,4 @@
+# REQUIRES: system-linux
# RUN: rm -rf %t && mkdir -p %t
# RUN: llvm-mc --triple=powerpc64le-unknown-linux-gnu --filetype=obj -o \
# RUN: %t/elf_reloc.o --defsym LE=1 %s
More information about the llvm-commits
mailing list