Skip to content

Commit f29352b

Browse files
authored
[RuntimeDyldChecker][AArch32] Add a PC offset to next_PC for ARM targets (#91746)
In ARM mode, the Program Counter (PC) points to the current instruction's address + 8 instead of + 4. An offset is added to RuntimeDyldChecker to use `next_pc` expression in JITLink tests with both Thumb and Arm.
1 parent aefcded commit f29352b

File tree

6 files changed

+35
-23
lines changed

6 files changed

+35
-23
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,13 @@ class RuntimeDyldCheckerExprEval {
369369
uint64_t SymbolAddr = PCtx.IsInsideLoad
370370
? Checker.getSymbolLocalAddr(Symbol)
371371
: Checker.getSymbolRemoteAddr(Symbol);
372-
uint64_t NextPC = SymbolAddr + InstSize;
372+
373+
// ARM PC offset is 8 instead of 4, because it accounts for an additional
374+
// prefetch instruction that increments PC even though it is implicit.
375+
auto TT = Checker.getTripleForSymbol(Checker.getTargetFlag(Symbol));
376+
uint64_t PCOffset = TT.getArch() == Triple::ArchType::arm ? 4 : 0;
377+
378+
uint64_t NextPC = SymbolAddr + InstSize + PCOffset;
373379

374380
return std::make_pair(EvalResult(NextPC), RemainingExpr);
375381
}

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,29 @@
2323
.syntax unified
2424

2525
# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_CALL call_target_arm
26-
# CHECK-INSTR: 00000000 <call_site>:
26+
# CHECK-INSTR: 00000000 <call_site_a2a>:
2727
# CHECK-INSTR: 0: ebfffffe bl
28-
# CHECK-INSTR: 4: ebfffffe bl
29-
# CHECK-INSTR: 0000000c <call_target_arm>
30-
# CHECK-INSTR: 00000010 <call_target_thumb>
31-
# ARM branch offset is 8, because it accounts for an additional prefetch
32-
# instruction that increments PC even though it is implicit
33-
# jitlink-check: decode_operand(call_site + 0, 0) = call_target_arm - (call_site + 8)
34-
# jitlink-check: decode_operand(call_site + 4, 0) = call_target_thumb - (call_site + 12)
35-
.globl call_site
36-
.type call_site,%function
28+
# CHECK-INSTR: 00000008 <call_site_a2t>:
29+
# CHECK-INSTR: 8: ebfffffe bl
30+
# CHECK-INSTR: 00000010 <call_target_arm>
31+
# CHECK-INSTR: 00000014 <call_target_thumb>
32+
# jitlink-check: decode_operand(call_site_a2a, 0) = call_target_arm - next_pc(call_site_a2a)
33+
# jitlink-check: decode_operand(call_site_a2t, 0) = call_target_thumb - next_pc(call_site_a2t)
34+
.globl call_site_a2a
35+
.type call_site_a2a, %function
3736
.p2align 2
38-
call_site:
37+
call_site_a2a:
3938
bl call_target_arm
39+
bx lr
40+
.size call_site_a2a, .-call_site_a2a
41+
42+
.globl call_site_a2t
43+
.type call_site_a2t,%function
44+
.p2align 2
45+
call_site_a2t:
4046
bl call_target_thumb
4147
bx lr
42-
.size call_site, .-call_site
48+
.size call_site_a2t, .-call_site_a2t
4349

4450
.globl call_target_arm
4551
.type call_target_arm,%function
@@ -59,10 +65,10 @@ call_target_thumb:
5965
.code 32
6066

6167
# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_JUMP24 jump24_target
62-
# CHECK-INSTR: 00000014 <jump24_site>:
63-
# CHECK-INSTR: 14: eafffffe b
64-
# CHECK-INSTR: 00000018 <jump24_target>
65-
# jitlink-check: decode_operand(jump24_site, 0) = jump24_target - (jump24_site + 8)
68+
# CHECK-INSTR: 00000018 <jump24_site>:
69+
# CHECK-INSTR: 18: eafffffe b
70+
# CHECK-INSTR: 0000001c <jump24_target>
71+
# jitlink-check: decode_operand(jump24_site, 0) = jump24_target - next_pc(jump24_site)
6672
.globl jump24_site
6773
.type jump24_site,%function
6874
.p2align 2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ target1_abs32:
5050
# The +12 accounts for the ARM branch offset (8) and the .LPC offset (4), which
5151
# is stored as initial addend inline.
5252
# FIXME: We shouldn't need to substract the 64-bit sign-extension manually.
53-
# jitlink-check: *{4}got_prel_offset = got_addr(out.o, target) - (got_prel + 12) - 0xffffffff00000000
53+
# jitlink-check: *{4}got_prel_offset = got_addr(out.o, target) - (next_pc(got_prel) + 4) - 0xffffffff00000000
5454
.globl got_prel
5555
.type got_prel,%function
5656
.p2align 2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# CHECK-INSTR: f7ff fffe bl
3131
# We decode the operand with index 2, because bl generates two leading implicit
3232
# predicate operands that we have to skip in order to decode the call_target operand
33-
# jitlink-check: decode_operand(call_site, 2) = call_target_thumb - (call_site + 4)
33+
# jitlink-check: decode_operand(call_site, 2) = call_target_thumb - next_pc(call_site)
3434
.globl call_site
3535
.type call_site,%function
3636
.p2align 1

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# hard-code it in the immediate field.
2828

2929
# The external function ext will return to the caller directly.
30-
# jitlink-check: decode_operand(test_arm_jump, 0) = stub_addr(out.o, ext) - (test_arm_jump + 8)
30+
# jitlink-check: decode_operand(test_arm_jump, 0) = stub_addr(out.o, ext) - next_pc(test_arm_jump)
3131
.globl test_arm_jump
3232
.type test_arm_jump,%function
3333
.p2align 2
@@ -38,7 +38,7 @@ test_arm_jump:
3838
# The branch-with-link sets the LR register so that the external function ext
3939
# returns to us. We have to save the register (push) and return to main manually
4040
# (pop). This adds the +4 offset for the bl instruction we decode:
41-
# jitlink-check: decode_operand(test_arm_call + 4, 0) = stub_addr(out.o, ext) - (test_arm_call + 8) - 4
41+
# jitlink-check: decode_operand(test_arm_call + 4, 0) = stub_addr(out.o, ext) - next_pc(test_arm_call) - 4
4242
.globl test_arm_call
4343
.type test_arm_call,%function
4444
.p2align 2

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# ascending size (because the default memory manager lays out blocks by size).
1414

1515
# Thumb relocation site emits thumb stub
16-
# jitlink-check: decode_operand(test_stub_thumb, 0) = stub_addr(out.o, ext, thumb) - (test_stub_thumb + 4)
16+
# jitlink-check: decode_operand(test_stub_thumb, 0) = stub_addr(out.o, ext, thumb) - next_pc(test_stub_thumb)
1717
.globl test_stub_thumb
1818
.type test_stub_thumb,%function
1919
.p2align 1
@@ -24,7 +24,7 @@ test_stub_thumb:
2424
.size test_stub_thumb, .-test_stub_thumb
2525

2626
# Arm relocation site emits arm stub
27-
# jitlink-check: decode_operand(test_stub_arm, 0) = stub_addr(out.o, ext, arm) - (test_stub_arm + 8)
27+
# jitlink-check: decode_operand(test_stub_arm, 0) = stub_addr(out.o, ext, arm) - next_pc(test_stub_arm)
2828
.globl test_stub_arm
2929
.type test_stub_arm,%function
3030
.p2align 2

0 commit comments

Comments
 (0)