[llvm] 62f793e - [JITLink][AArch32] Implement ELF::R_ARM_JUMP24 relocation
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 08:17:29 PDT 2023
Author: Eymen Ünay
Date: 2023-09-13T17:16:29+02:00
New Revision: 62f793ec9cac250fa396ea95e1d7c4333aea6e8a
URL: https://github.com/llvm/llvm-project/commit/62f793ec9cac250fa396ea95e1d7c4333aea6e8a
DIFF: https://github.com/llvm/llvm-project/commit/62f793ec9cac250fa396ea95e1d7c4333aea6e8a.diff
LOG: [JITLink][AArch32] Implement ELF::R_ARM_JUMP24 relocation
Added support and test for ELF::R_ARM_JUMP24
Reviewed By: sgraenitz
Differential Revision: https://reviews.llvm.org/D157541
Added:
Modified:
llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
llvm/test/ExecutionEngine/JITLink/AArch32/ELF_static_arm_reloc.s
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h b/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
index d33b422745c2d9d..1c89280a10fd213 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
@@ -52,7 +52,10 @@ enum EdgeKind_aarch32 : Edge::Kind {
/// Arm and Thumb).
Arm_Call = FirstArmRelocation,
- LastArmRelocation = Arm_Call,
+ /// Write immediate value for (unconditional) PC-relative branch without link.
+ Arm_Jump24,
+
+ LastArmRelocation = Arm_Jump24,
///
/// Relocations of class Thumb16 and Thumb32 (covers Thumb instruction subset)
@@ -149,12 +152,16 @@ struct HalfWords {
///
template <EdgeKind_aarch32 Kind> struct FixupInfo {};
-template <> struct FixupInfo<Arm_Call> {
+template <> struct FixupInfo<Arm_Jump24> {
static constexpr uint32_t Opcode = 0x0a000000;
- static constexpr uint32_t OpcodeMask = 0x0e000000;
+ static constexpr uint32_t OpcodeMask = 0x0f000000;
static constexpr uint32_t ImmMask = 0x00ffffff;
static constexpr uint32_t Unconditional = 0xe0000000;
static constexpr uint32_t CondMask = 0xe0000000; // excluding BLX bit
+};
+
+template <> struct FixupInfo<Arm_Call> : public FixupInfo<Arm_Jump24> {
+ static constexpr uint32_t OpcodeMask = 0x0e000000;
static constexpr uint32_t BitH = 0x01000000;
static constexpr uint32_t BitBlx = 0x10000000;
};
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
index a1bc4c853323102..17eba673eb4fa06 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
@@ -40,6 +40,8 @@ Expected<aarch32::EdgeKind_aarch32> getJITLinkEdgeKind(uint32_t ELFType) {
return aarch32::Data_Delta32;
case ELF::R_ARM_CALL:
return aarch32::Arm_Call;
+ case ELF::R_ARM_JUMP24:
+ return aarch32::Arm_Jump24;
case ELF::R_ARM_THM_CALL:
return aarch32::Thumb_Call;
case ELF::R_ARM_THM_JUMP24:
@@ -64,6 +66,8 @@ Expected<uint32_t> getELFRelocationType(Edge::Kind Kind) {
return ELF::R_ARM_ABS32;
case aarch32::Arm_Call:
return ELF::R_ARM_CALL;
+ case aarch32::Arm_Jump24:
+ return ELF::R_ARM_JUMP24;
case aarch32::Thumb_Call:
return ELF::R_ARM_THM_CALL;
case aarch32::Thumb_Jump24:
diff --git a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
index ac91d0bd6e6724f..ef278e39982c06a 100644
--- a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
@@ -292,6 +292,11 @@ Expected<int64_t> readAddendArm(LinkGraph &G, Block &B, const Edge &E) {
return makeUnexpectedOpcodeError(G, R, Kind);
return decodeImmBA1BlA1BlxA2(R.Wd);
+ case Arm_Jump24:
+ if (!checkOpcode<Arm_Jump24>(R))
+ return makeUnexpectedOpcodeError(G, R, Kind);
+ return decodeImmBA1BlA1BlxA2(R.Wd);
+
default:
return make_error<JITLinkError>(
"In graph " + G.getName() + ", section " + B.getSection().getName() +
@@ -399,10 +404,25 @@ Error applyFixupArm(LinkGraph &G, Block &B, const Edge &E) {
TargetAddress |= 0x01;
switch (Kind) {
+ case Arm_Jump24: {
+ if (!checkOpcode<Arm_Jump24>(R))
+ return makeUnexpectedOpcodeError(G, R, Kind);
+ if (hasTargetFlags(TargetSymbol, ThumbSymbol))
+ return make_error<JITLinkError>("Branch relocation needs interworking "
+ "stub when bridging to Thumb: " +
+ StringRef(G.getEdgeKindName(Kind)));
+
+ int64_t Value = TargetAddress - FixupAddress + Addend;
+
+ if (!isInt<26>(Value))
+ return makeTargetOutOfRangeError(G, B, E);
+ writeImmediate<Arm_Jump24>(R, encodeImmBA1BlA1BlxA2(Value));
+
+ return Error::success();
+ }
case Arm_Call: {
if (!checkOpcode<Arm_Call>(R))
return makeUnexpectedOpcodeError(G, R, Kind);
-
if ((R.Wd & FixupInfo<Arm_Call>::CondMask) !=
FixupInfo<Arm_Call>::Unconditional)
return make_error<JITLinkError>("Relocation expects an unconditional "
@@ -577,6 +597,7 @@ const char *getEdgeKindName(Edge::Kind K) {
KIND_NAME_CASE(Data_Delta32)
KIND_NAME_CASE(Data_Pointer32)
KIND_NAME_CASE(Arm_Call)
+ KIND_NAME_CASE(Arm_Jump24)
KIND_NAME_CASE(Thumb_Call)
KIND_NAME_CASE(Thumb_Jump24)
KIND_NAME_CASE(Thumb_MovwAbsNC)
diff --git a/llvm/test/ExecutionEngine/JITLink/AArch32/ELF_static_arm_reloc.s b/llvm/test/ExecutionEngine/JITLink/AArch32/ELF_static_arm_reloc.s
index 30bba4c09e75046..f91635f80f8b367 100644
--- a/llvm/test/ExecutionEngine/JITLink/AArch32/ELF_static_arm_reloc.s
+++ b/llvm/test/ExecutionEngine/JITLink/AArch32/ELF_static_arm_reloc.s
@@ -30,6 +30,26 @@ call_target:
bx lr
.size call_target, .-call_target
+# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_JUMP24 jump24_target
+# CHECK-INSTR: 00000008 <jump24_site>:
+# CHECK-INSTR: 8: eafffffe b 0x8 <jump24_site>
+# CHECK-INSTR: 0000000c <jump24_target>:
+# CHECK-INSTR: c: e12fff1e bx lr
+# jitlink-check: decode_operand(jump24_site, 0) = jump24_target - (jump24_site + 8)
+ .globl jump24_site
+ .type jump24_site,%function
+ .p2align 2
+jump24_site:
+ b.w jump24_target
+ .size jump24_site, .-jump24_site
+
+ .globl jump24_target
+ .type jump24_target,%function
+ .p2align 2
+jump24_target:
+ bx lr
+ .size jump24_target, .-jump24_target
+
# Empty main function for jitlink to be happy
.globl main
.type main,%function
More information about the llvm-commits
mailing list