Skip to content

Commit

Permalink
[JITLink][AArch32] Implement ELF relocation R_ARM_TARGET1
Browse files Browse the repository at this point in the history
Prepare a configuration switch and default to R_ARM_ABS32
  • Loading branch information
weliveindetail committed Jan 22, 2024
1 parent c553212 commit bfb0932
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ enum class StubsFlavor {
struct ArmConfig {
bool J1J2BranchEncoding = false;
StubsFlavor Stubs = StubsFlavor::Unsupported;
// In the long term, we might want a linker switch like --target1-rel
bool Target1Rel = false;
};

/// Obtain the sub-arch configuration for a given Arm CPU model.
Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace llvm {
namespace jitlink {

/// Translate from ELF relocation type to JITLink-internal edge kind.
Expected<aarch32::EdgeKind_aarch32> getJITLinkEdgeKind(uint32_t ELFType) {
Expected<aarch32::EdgeKind_aarch32>
getJITLinkEdgeKind(uint32_t ELFType, const aarch32::ArmConfig &ArmCfg) {
switch (ELFType) {
case ELF::R_ARM_ABS32:
return aarch32::Data_Pointer32;
Expand All @@ -47,6 +48,9 @@ Expected<aarch32::EdgeKind_aarch32> getJITLinkEdgeKind(uint32_t ELFType) {
return aarch32::Arm_MovwAbsNC;
case ELF::R_ARM_MOVT_ABS:
return aarch32::Arm_MovtAbs;
case ELF::R_ARM_TARGET1:
return (ArmCfg.Target1Rel) ? aarch32::Data_Delta32
: aarch32::Data_Pointer32;
case ELF::R_ARM_THM_CALL:
return aarch32::Thumb_Call;
case ELF::R_ARM_THM_JUMP24:
Expand Down Expand Up @@ -171,7 +175,7 @@ class ELFLinkGraphBuilder_aarch32
inconvertibleErrorCode());

uint32_t Type = Rel.getType(false);
Expected<aarch32::EdgeKind_aarch32> Kind = getJITLinkEdgeKind(Type);
Expected<aarch32::EdgeKind_aarch32> Kind = getJITLinkEdgeKind(Type, ArmCfg);
if (!Kind)
return Kind.takeError();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ rel32:
.word target - .
.size rel32, .-rel32

# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_TARGET1 target
# jitlink-check: *{4}(target1_abs32) = target
.global target1_abs32
target1_abs32:
.word target(target1)
.size target1_abs32, .-target1_abs32

# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_GOT_PREL target
#
# The GOT entry contains the absolute address of the external:
Expand Down
8 changes: 5 additions & 3 deletions llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ struct MutableWord {
namespace llvm {
namespace jitlink {

Expected<aarch32::EdgeKind_aarch32> getJITLinkEdgeKind(uint32_t ELFType);
Expected<aarch32::EdgeKind_aarch32>
getJITLinkEdgeKind(uint32_t ELFType, const aarch32::ArmConfig &Cfg);
Expected<uint32_t> getELFRelocationType(Edge::Kind Kind);

} // namespace jitlink
} // namespace llvm

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

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

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

Expand Down

0 comments on commit bfb0932

Please sign in to comment.