[JITLink][AArch32] Implement ELF relocation R_ARM_NONE

This commit is contained in:
Stefan Gränitz
2024-01-20 18:06:14 +01:00
parent bfb09326be
commit 565470ed27
5 changed files with 39 additions and 4 deletions

View File

@@ -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
@@ -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.
@@ -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.

View File

@@ -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;
@@ -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}: ",

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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