Skip to content

Commit

Permalink
[JITLink][AArch32] Implement ELF relocation R_ARM_NONE
Browse files Browse the repository at this point in the history
  • Loading branch information
weliveindetail committed Jan 22, 2024
1 parent bfb0932 commit 565470e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
12 changes: 9 additions & 3 deletions llvm/include/llvm/ExecutionEngine/JITLink/aarch32.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ enum EdgeKind_aarch32 : Edge::Kind {
Thumb_MovtPrel,

LastThumbRelocation = Thumb_MovtPrel,
LastRelocation = LastThumbRelocation,

/// No-op relocation
None,

LastRelocation = None,
};

/// Flags enum for AArch32-specific symbol properties
Expand Down Expand Up @@ -293,7 +297,8 @@ inline Expected<int64_t> readAddend(LinkGraph &G, Block &B,
if (Kind <= LastThumbRelocation)
return readAddendThumb(G, B, Offset, Kind, ArmCfg);

llvm_unreachable("Relocation must be of class Data, Arm or Thumb");
assert(Kind == None && "Not associated with a relocation class");
return 0;
}

/// Helper function to apply the fixup for Data-class relocations.
Expand All @@ -320,7 +325,8 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
if (Kind <= LastThumbRelocation)
return applyFixupThumb(G, B, E, ArmCfg);

llvm_unreachable("Relocation must be of class Data, Arm or Thumb");
assert(Kind == None && "Not associated with a relocation class");
return Error::success();
}

/// Populate a Global Offset Table from edges that request it.
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ getJITLinkEdgeKind(uint32_t ELFType, const aarch32::ArmConfig &ArmCfg) {
return aarch32::Arm_MovwAbsNC;
case ELF::R_ARM_MOVT_ABS:
return aarch32::Arm_MovtAbs;
case ELF::R_ARM_NONE:
return aarch32::None;
case ELF::R_ARM_TARGET1:
return (ArmCfg.Target1Rel) ? aarch32::Data_Delta32
: aarch32::Data_Pointer32;
Expand Down Expand Up @@ -99,6 +101,8 @@ Expected<uint32_t> getELFRelocationType(Edge::Kind Kind) {
return ELF::R_ARM_THM_MOVW_PREL_NC;
case aarch32::Thumb_MovtPrel:
return ELF::R_ARM_THM_MOVT_PREL;
case aarch32::None:
return ELF::R_ARM_NONE;
}

return make_error<JITLinkError>(formatv("Invalid aarch32 edge {0:d}: ",
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ const char *getEdgeKindName(Edge::Kind K) {
KIND_NAME_CASE(Thumb_MovtAbs)
KIND_NAME_CASE(Thumb_MovwPrelNC)
KIND_NAME_CASE(Thumb_MovtPrel)
KIND_NAME_CASE(None)
default:
return getGenericEdgeKindName(K);
}
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/ExecutionEngine/JITLink/AArch32/ELF_relocations_data.s
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ got_prel_offset:
.size got_prel_offset, .-got_prel_offset
.size got_prel, .-got_prel

# EH personality routine
# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_NONE __aeabi_unwind_cpp_pr0
.globl __aeabi_unwind_cpp_pr0
.type __aeabi_unwind_cpp_pr0,%function
.align 2
__aeabi_unwind_cpp_pr0:
bx lr

# Generate reference to EH personality (right now we ignore the resulting
# R_ARM_PREL31 relocation since it's in .ARM.exidx)
.globl prel31
.type prel31,%function
.align 2
prel31:
.fnstart
.save {r11, lr}
push {r11, lr}
.setfp r11, sp
mov r11, sp
pop {r11, lr}
mov pc, lr
.size prel31,.-prel31
.fnend

# This test is executable with any 4-byte external target:
# > echo "unsigned target = 42;" | clang -target armv7-linux-gnueabihf -o target.o -c -xc -
# > llvm-jitlink target.o armv7/out.o
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Expected<uint32_t> getELFRelocationType(Edge::Kind Kind);
TEST(AArch32_ELF, EdgeKinds) {
// Fails: Invalid ELF type -> JITLink kind
aarch32::ArmConfig Cfg;
Expected<uint32_t> ErrKind = getJITLinkEdgeKind(ELF::R_ARM_NONE, Cfg);
Expected<uint32_t> ErrKind = getJITLinkEdgeKind(ELF::R_ARM_ME_TOO, Cfg);
EXPECT_TRUE(errorToBool(ErrKind.takeError()));

// Fails: Invalid JITLink kind -> ELF type
Expand Down

0 comments on commit 565470e

Please sign in to comment.