Skip to content

Commit bfb0932

Browse files
[JITLink][AArch32] Implement ELF relocation R_ARM_TARGET1
Prepare a configuration switch and default to R_ARM_ABS32
1 parent c553212 commit bfb0932

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ enum class StubsFlavor {
135135
struct ArmConfig {
136136
bool J1J2BranchEncoding = false;
137137
StubsFlavor Stubs = StubsFlavor::Unsupported;
138+
// In the long term, we might want a linker switch like --target1-rel
139+
bool Target1Rel = false;
138140
};
139141

140142
/// Obtain the sub-arch configuration for a given Arm CPU model.

llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ namespace llvm {
3131
namespace jitlink {
3232

3333
/// Translate from ELF relocation type to JITLink-internal edge kind.
34-
Expected<aarch32::EdgeKind_aarch32> getJITLinkEdgeKind(uint32_t ELFType) {
34+
Expected<aarch32::EdgeKind_aarch32>
35+
getJITLinkEdgeKind(uint32_t ELFType, const aarch32::ArmConfig &ArmCfg) {
3536
switch (ELFType) {
3637
case ELF::R_ARM_ABS32:
3738
return aarch32::Data_Pointer32;
@@ -47,6 +48,9 @@ Expected<aarch32::EdgeKind_aarch32> getJITLinkEdgeKind(uint32_t ELFType) {
4748
return aarch32::Arm_MovwAbsNC;
4849
case ELF::R_ARM_MOVT_ABS:
4950
return aarch32::Arm_MovtAbs;
51+
case ELF::R_ARM_TARGET1:
52+
return (ArmCfg.Target1Rel) ? aarch32::Data_Delta32
53+
: aarch32::Data_Pointer32;
5054
case ELF::R_ARM_THM_CALL:
5155
return aarch32::Thumb_Call;
5256
case ELF::R_ARM_THM_JUMP24:
@@ -171,7 +175,7 @@ class ELFLinkGraphBuilder_aarch32
171175
inconvertibleErrorCode());
172176

173177
uint32_t Type = Rel.getType(false);
174-
Expected<aarch32::EdgeKind_aarch32> Kind = getJITLinkEdgeKind(Type);
178+
Expected<aarch32::EdgeKind_aarch32> Kind = getJITLinkEdgeKind(Type, ArmCfg);
175179
if (!Kind)
176180
return Kind.takeError();
177181

llvm/test/ExecutionEngine/JITLink/AArch32/ELF_relocations_data.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ rel32:
2929
.word target - .
3030
.size rel32, .-rel32
3131

32+
# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_TARGET1 target
33+
# jitlink-check: *{4}(target1_abs32) = target
34+
.global target1_abs32
35+
target1_abs32:
36+
.word target(target1)
37+
.size target1_abs32, .-target1_abs32
38+
3239
# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_GOT_PREL target
3340
#
3441
# The GOT entry contains the absolute address of the external:

llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ struct MutableWord {
3939
namespace llvm {
4040
namespace jitlink {
4141

42-
Expected<aarch32::EdgeKind_aarch32> getJITLinkEdgeKind(uint32_t ELFType);
42+
Expected<aarch32::EdgeKind_aarch32>
43+
getJITLinkEdgeKind(uint32_t ELFType, const aarch32::ArmConfig &Cfg);
4344
Expected<uint32_t> getELFRelocationType(Edge::Kind Kind);
4445

4546
} // namespace jitlink
4647
} // namespace llvm
4748

4849
TEST(AArch32_ELF, EdgeKinds) {
4950
// Fails: Invalid ELF type -> JITLink kind
50-
Expected<uint32_t> ErrKind = getJITLinkEdgeKind(ELF::R_ARM_NONE);
51+
aarch32::ArmConfig Cfg;
52+
Expected<uint32_t> ErrKind = getJITLinkEdgeKind(ELF::R_ARM_NONE, Cfg);
5153
EXPECT_TRUE(errorToBool(ErrKind.takeError()));
5254

5355
// Fails: Invalid JITLink kind -> ELF type
@@ -59,7 +61,7 @@ TEST(AArch32_ELF, EdgeKinds) {
5961
EXPECT_FALSE(errorToBool(ELFType.takeError()))
6062
<< "Failed to translate JITLink kind -> ELF type";
6163

62-
Expected<Edge::Kind> JITLinkKind = getJITLinkEdgeKind(*ELFType);
64+
Expected<Edge::Kind> JITLinkKind = getJITLinkEdgeKind(*ELFType, Cfg);
6365
EXPECT_FALSE(errorToBool(JITLinkKind.takeError()))
6466
<< "Failed to translate ELF type -> JITLink kind";
6567

0 commit comments

Comments
 (0)