Skip to content

Commit 5c67ab4

Browse files
committed
[RuntimeDyldChecker][AArch32] Add a PC offset to next_PC for ARM targets
In ARM mode, the Program Counter (PC) points to the current instruction's address + 8 instead of + 4. This offset is added to RuntimeDyldChecker to use `next_pc` expression in JITLink tests.
1 parent 23b673e commit 5c67ab4

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,19 @@ class RuntimeDyldCheckerExprEval {
369369
uint64_t SymbolAddr = PCtx.IsInsideLoad
370370
? Checker.getSymbolLocalAddr(Symbol)
371371
: Checker.getSymbolRemoteAddr(Symbol);
372-
uint64_t NextPC = SymbolAddr + InstSize;
372+
373+
uint64_t PCOffset = 0;
374+
auto TT = Checker.getTripleForSymbol(Checker.getTargetFlag(Symbol));
375+
switch (TT.getArch()) {
376+
case Triple::ArchType::arm:
377+
// ARM mode adds an offset of 4 bytes to PC
378+
PCOffset = 4;
379+
break;
380+
default:
381+
PCOffset = 0;
382+
}
383+
384+
uint64_t NextPC = SymbolAddr + InstSize + PCOffset;
373385

374386
return std::make_pair(EvalResult(NextPC), RemainingExpr);
375387
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
# CHECK-INSTR: 4: ebfffffe bl
2929
# CHECK-INSTR: 0000000c <call_target_arm>
3030
# 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)
31+
# jitlink-check: decode_operand(call_site + 0, 0) = call_target_arm - next_pc(call_site)
3432
# jitlink-check: decode_operand(call_site + 4, 0) = call_target_thumb - (call_site + 12)
3533
.globl call_site
3634
.type call_site,%function
@@ -62,7 +60,7 @@ call_target_thumb:
6260
# CHECK-INSTR: 00000014 <jump24_site>:
6361
# CHECK-INSTR: 14: eafffffe b
6462
# CHECK-INSTR: 00000018 <jump24_target>
65-
# jitlink-check: decode_operand(jump24_site, 0) = jump24_target - (jump24_site + 8)
63+
# jitlink-check: decode_operand(jump24_site, 0) = jump24_target - next_pc(jump24_site)
6664
.globl jump24_site
6765
.type jump24_site,%function
6866
.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

0 commit comments

Comments
 (0)