Skip to content

Commit 565470e

Browse files
[JITLink][AArch32] Implement ELF relocation R_ARM_NONE
1 parent bfb0932 commit 565470e

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ enum EdgeKind_aarch32 : Edge::Kind {
101101
Thumb_MovtPrel,
102102

103103
LastThumbRelocation = Thumb_MovtPrel,
104-
LastRelocation = LastThumbRelocation,
104+
105+
/// No-op relocation
106+
None,
107+
108+
LastRelocation = None,
105109
};
106110

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

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

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

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

326332
/// Populate a Global Offset Table from edges that request it.

llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ getJITLinkEdgeKind(uint32_t ELFType, const aarch32::ArmConfig &ArmCfg) {
4848
return aarch32::Arm_MovwAbsNC;
4949
case ELF::R_ARM_MOVT_ABS:
5050
return aarch32::Arm_MovtAbs;
51+
case ELF::R_ARM_NONE:
52+
return aarch32::None;
5153
case ELF::R_ARM_TARGET1:
5254
return (ArmCfg.Target1Rel) ? aarch32::Data_Delta32
5355
: aarch32::Data_Pointer32;
@@ -99,6 +101,8 @@ Expected<uint32_t> getELFRelocationType(Edge::Kind Kind) {
99101
return ELF::R_ARM_THM_MOVW_PREL_NC;
100102
case aarch32::Thumb_MovtPrel:
101103
return ELF::R_ARM_THM_MOVT_PREL;
104+
case aarch32::None:
105+
return ELF::R_ARM_NONE;
102106
}
103107

104108
return make_error<JITLinkError>(formatv("Invalid aarch32 edge {0:d}: ",

llvm/lib/ExecutionEngine/JITLink/aarch32.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ const char *getEdgeKindName(Edge::Kind K) {
766766
KIND_NAME_CASE(Thumb_MovtAbs)
767767
KIND_NAME_CASE(Thumb_MovwPrelNC)
768768
KIND_NAME_CASE(Thumb_MovtPrel)
769+
KIND_NAME_CASE(None)
769770
default:
770771
return getGenericEdgeKindName(K);
771772
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ got_prel_offset:
6464
.size got_prel_offset, .-got_prel_offset
6565
.size got_prel, .-got_prel
6666

67+
# EH personality routine
68+
# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_NONE __aeabi_unwind_cpp_pr0
69+
.globl __aeabi_unwind_cpp_pr0
70+
.type __aeabi_unwind_cpp_pr0,%function
71+
.align 2
72+
__aeabi_unwind_cpp_pr0:
73+
bx lr
74+
75+
# Generate reference to EH personality (right now we ignore the resulting
76+
# R_ARM_PREL31 relocation since it's in .ARM.exidx)
77+
.globl prel31
78+
.type prel31,%function
79+
.align 2
80+
prel31:
81+
.fnstart
82+
.save {r11, lr}
83+
push {r11, lr}
84+
.setfp r11, sp
85+
mov r11, sp
86+
pop {r11, lr}
87+
mov pc, lr
88+
.size prel31,.-prel31
89+
.fnend
90+
6791
# This test is executable with any 4-byte external target:
6892
# > echo "unsigned target = 42;" | clang -target armv7-linux-gnueabihf -o target.o -c -xc -
6993
# > llvm-jitlink target.o armv7/out.o

llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Expected<uint32_t> getELFRelocationType(Edge::Kind Kind);
4949
TEST(AArch32_ELF, EdgeKinds) {
5050
// Fails: Invalid ELF type -> JITLink kind
5151
aarch32::ArmConfig Cfg;
52-
Expected<uint32_t> ErrKind = getJITLinkEdgeKind(ELF::R_ARM_NONE, Cfg);
52+
Expected<uint32_t> ErrKind = getJITLinkEdgeKind(ELF::R_ARM_ME_TOO, Cfg);
5353
EXPECT_TRUE(errorToBool(ErrKind.takeError()));
5454

5555
// Fails: Invalid JITLink kind -> ELF type

0 commit comments

Comments
 (0)