[llvm] [Draft] Basic JITLink AArch32 support for clang-repl (PR #77313)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 8 06:20:43 PST 2024
https://github.com/weliveindetail created https://github.com/llvm/llvm-project/pull/77313
Running this on my RPi with 32-bit Raspbian, I get:
```
$ ./clang-repl-jitlink-armv6hack --debug-only=jitlink
clang-repl> int a = 1;
clang-repl> a + 2
Building jitlink graph for new input incr_module_1-jitted-objectbuffer...
Created ELFLinkGraphBuilder for "incr_module_1-jitted-objectbuffer" Preparing to build...
Creating graph sections...
0: has type SHT_NULL. Skipping.
1: Creating section for ".strtab"
1: ".strtab" is not a SHF_ALLOC section. Using NoAlloc lifetime.
2: Creating section for ".text"
3: Creating section for ".rel.text"
3: ".rel.text" is not a SHF_ALLOC section. Using NoAlloc lifetime.
4: Skipping section ".ARM.exidx" explicitly
5: Creating section for ".rel.ARM.exidx"
5: ".rel.ARM.exidx" is not a SHF_ALLOC section. Using NoAlloc lifetime.
6: Creating section for ".text.startup"
7: Creating section for ".rel.text.startup"
7: ".rel.text.startup" is not a SHF_ALLOC section. Using NoAlloc lifetime.
8: Skipping section ".ARM.exidx.text.startup" explicitly
9: Creating section for ".rel.ARM.exidx.text.startup"
9: ".rel.ARM.exidx.text.startup" is not a SHF_ALLOC section. Using NoAlloc lifetime.
10: Creating section for ".comment"
10: ".comment" is not a SHF_ALLOC section. Using NoAlloc lifetime.
11: Creating section for ".note.GNU-stack"
11: ".note.GNU-stack" is not a SHF_ALLOC section. Using NoAlloc lifetime.
12: Creating section for ".ARM.attributes"
12: ".ARM.attributes" is not a SHF_ALLOC section. Using NoAlloc lifetime.
13: Creating section for ".symtab"
13: ".symtab" is not a SHF_ALLOC section. Using NoAlloc lifetime.
Creating graph symbols...
Adding symbols from symtab section ".symtab"
0: Creating null graph symbol
1: Skipping STT_FILE symbol "incr_module_1"
2: Creating defined graph symbol for ELF symbol ""
3: Creating defined graph symbol for ELF symbol "__stmts__0"
4: Creating defined graph symbol for ELF symbol "$a.0"
5: Creating defined graph symbol for ELF symbol "$d.1"
6: Creating defined graph symbol for ELF symbol ""
7: Creating defined graph symbol for ELF symbol "_GLOBAL__sub_I_incr_module_1"
8: Creating defined graph symbol for ELF symbol "$a.2"
9: Creating defined graph symbol for ELF symbol "$a.3"
10: Creating external graph symbol for ELF symbol "_Z35__clang_Interpreter_SetValueNoAllocPvS_S_y"
11: Creating external graph symbol for ELF symbol "a"
12: Creating external graph symbol for ELF symbol "__aeabi_unwind_cpp_pr0"
13: Creating defined graph symbol for ELF symbol "__orc_init_func.incr_module_1"
Processing relocations:
.text:
edge at 0x2c: 0x0 + 0x2c -- Arm_Call -> _Z35__clang_Interpreter_SetValueNoAllocPvS_S_y + -8
JIT session error: Unsupported aarch32 relocation 96: R_ARM_GOT_PREL
error: Failed to materialize symbols: { (main, { $.incr_module_1.__inits.0, __orc_init_func.incr_module_1 }) }
clang-repl> %quit
```
>From b1ff6fc3996a4e75bd11f7137295e1b9b92aeba5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Mon, 8 Jan 2024 15:05:08 +0100
Subject: [PATCH 1/3] [JITLink][AArch32] In warning output add decimal value
for CPUArch and missing newline
---
llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h b/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
index f346cfb2a93112..d7869377a8baaa 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
@@ -146,7 +146,7 @@ inline ArmConfig getArmConfigForCPUArch(ARMBuildAttrs::CPUArch CPUArch) {
default:
DEBUG_WITH_TYPE("jitlink", {
dbgs() << " Warning: ARM config not defined for CPU architecture "
- << getCPUArchName(CPUArch);
+ << getCPUArchName(CPUArch) << " (" << CPUArch << ")\n";
});
break;
}
>From 2111268adff1537e6dc1f0c443e0a62a327e7456 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Mon, 8 Jan 2024 15:06:33 +0100
Subject: [PATCH 2/3] [Orc] Make JITLink default in LLJIT for ARM ELF-based
systems
---
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index e259c393d07e03..17a319b8ff05e2 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -734,6 +734,9 @@ Error LLJITBuilderState::prepareForConstruction() {
case Triple::aarch64:
UseJITLink = !TT.isOSBinFormatCOFF();
break;
+ case Triple::arm:
+ UseJITLink = !TT.isOSBinFormatCOFF();
+ break;
case Triple::x86_64:
UseJITLink = !TT.isOSBinFormatCOFF();
break;
>From 470daa17d4a2e1cc6926746e7d2059508b3b2c5f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Mon, 8 Jan 2024 15:07:55 +0100
Subject: [PATCH 3/3] [Hack] Add armv6 cases for CPUArch in JITLink AArch32
(wip)
---
llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h | 1 +
llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp | 1 +
2 files changed, 2 insertions(+)
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h b/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
index d7869377a8baaa..f8bb13159663f6 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
@@ -138,6 +138,7 @@ struct ArmConfig {
inline ArmConfig getArmConfigForCPUArch(ARMBuildAttrs::CPUArch CPUArch) {
ArmConfig ArmCfg;
switch (CPUArch) {
+ case ARMBuildAttrs::v6:
case ARMBuildAttrs::v7:
case ARMBuildAttrs::v8_A:
ArmCfg.J1J2BranchEncoding = true;
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
index 132989fcbce021..b3bdebd9748ffd 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
@@ -254,6 +254,7 @@ createLinkGraphFromELFObject_aarch32(MemoryBufferRef ObjectBuffer) {
using namespace ARMBuildAttrs;
auto Arch = static_cast<CPUArch>(ARM::getArchAttr(AK));
switch (Arch) {
+ case v6:
case v7:
case v8_A:
ArmCfg = aarch32::getArmConfigForCPUArch(Arch);
More information about the llvm-commits
mailing list