aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
diff options
context:
space:
mode:
authorStefan Gränitz <stefan.graenitz@gmail.com>2023-03-23 11:10:39 +0100
committerStefan Gränitz <stefan.graenitz@gmail.com>2023-03-24 10:18:08 +0100
commit5c1d160cd979dd6099f4266db600020a0cb4867a (patch)
tree19e58f38bd80cbee1e439fd4f58de1ebfa5f34d1 /llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
parent410a239996725e68b431e7e3e43e270290be93d2 (diff)
downloadllvm-5c1d160cd979dd6099f4266db600020a0cb4867a.zip
llvm-5c1d160cd979dd6099f4266db600020a0cb4867a.tar.gz
llvm-5c1d160cd979dd6099f4266db600020a0cb4867a.tar.bz2
Reland "[JITLink] Initial AArch32 backend"
This first version lays the foundations for AArch32 support in JITLink. ELFLinkGraphBuilder_aarch32 processes REL-type relocations and populates LinkGraphs from ELF object files for both big- and little-endian systems. The ArmCfg member controls subarchitecture-specific details throughout the linking process (i.e. it's passed to ELFJITLinker_aarch32). Relocation types follow the ABI documentation's division into classes: Data (endian-sensitive), Arm (32-bit little-endian) and Thumb (2x 16-bit little-endian, "Thumb32" in the docs). The implementation of instruction encoding/decoding for relocation resolution is implemented symmetrically and is testable in isolation (see AArch32 category in JITLinkTests). Callable Thumb functions are marked with a ThumbSymbol target-flag and stored in the LinkGraph with their real addresses. The thumb-bit is added back in when the owning JITDylib requests the address for such a symbol. The StubsManager can generate (absolute) Thumb-state stubs for branch range extensions on v7+ targets. Proper GOT/PLT handling is not yet implemented. This patch is based on the backend implementation in ez-clang and has just enough functionality to model the infrastructure and link a Thumb function `main()` that calls `printf()` to dump "Hello Arm!" on Armv7a. It was tested on Raspberry Pi with 32-bit Raspbian OS. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D144083
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp')
-rw-r--r--llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
index 2c270cd..9103c62 100644
--- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
@@ -8,6 +8,7 @@
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"
+#include "llvm/ExecutionEngine/JITLink/aarch32.h"
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
#include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
#include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
@@ -39,8 +40,20 @@ bool hasInitializerSection(jitlink::LinkGraph &G) {
return false;
}
-JITTargetAddress getJITSymbolPtrForSymbol(Symbol &Sym) {
- return Sym.getAddress().getValue();
+JITTargetAddress getJITSymbolPtrForSymbol(Symbol &Sym, const Triple &TT) {
+ uint64_t CallableAddr = Sym.getAddress().getValue();
+ switch (TT.getArch()) {
+ case Triple::arm:
+ case Triple::armeb:
+ case Triple::thumb:
+ case Triple::thumbeb:
+ if (Sym.hasTargetFlags(aarch32::ThumbSymbol) && Sym.isCallable())
+ CallableAddr |= 0x01; // LSB is thumb bit
+ break;
+ default:
+ break;
+ }
+ return CallableAddr;
}
JITSymbolFlags getJITSymbolFlagsForSymbol(Symbol &Sym) {
@@ -219,7 +232,7 @@ public:
for (auto *Sym : G.defined_symbols())
if (Sym->hasName() && Sym->getScope() != Scope::Local) {
auto InternedName = ES.intern(Sym->getName());
- auto Ptr = getJITSymbolPtrForSymbol(*Sym);
+ auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple());
auto Flags = getJITSymbolFlagsForSymbol(*Sym);
InternedResult[InternedName] = JITEvaluatedSymbol(Ptr, Flags);
if (AutoClaim && !MR->getSymbols().count(InternedName)) {
@@ -232,7 +245,7 @@ public:
for (auto *Sym : G.absolute_symbols())
if (Sym->hasName() && Sym->getScope() != Scope::Local) {
auto InternedName = ES.intern(Sym->getName());
- auto Ptr = getJITSymbolPtrForSymbol(*Sym);
+ auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple());
auto Flags = getJITSymbolFlagsForSymbol(*Sym);
InternedResult[InternedName] = JITEvaluatedSymbol(Ptr, Flags);
if (AutoClaim && !MR->getSymbols().count(InternedName)) {