Skip to content

[RuntimeDyldChecker][AArch32] Add a PC offset to next_PC for ARM targets #91746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ class RuntimeDyldCheckerExprEval {
uint64_t SymbolAddr = PCtx.IsInsideLoad
? Checker.getSymbolLocalAddr(Symbol)
: Checker.getSymbolRemoteAddr(Symbol);
uint64_t NextPC = SymbolAddr + InstSize;

// ARM PC offset is 8 instead of 4, because it accounts for an additional
// prefetch instruction that increments PC even though it is implicit.
auto TT = Checker.getTripleForSymbol(Checker.getTargetFlag(Symbol));
uint64_t PCOffset = TT.getArch() == Triple::ArchType::arm ? 4 : 0;

uint64_t NextPC = SymbolAddr + InstSize + PCOffset;

return std::make_pair(EvalResult(NextPC), RemainingExpr);
}
Expand Down
38 changes: 22 additions & 16 deletions llvm/test/ExecutionEngine/JITLink/AArch32/ELF_relocations_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,29 @@
.syntax unified

# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_CALL call_target_arm
# CHECK-INSTR: 00000000 <call_site>:
# CHECK-INSTR: 00000000 <call_site_a2a>:
# CHECK-INSTR: 0: ebfffffe bl
# CHECK-INSTR: 4: ebfffffe bl
# CHECK-INSTR: 0000000c <call_target_arm>
# CHECK-INSTR: 00000010 <call_target_thumb>
# ARM branch offset is 8, because it accounts for an additional prefetch
# instruction that increments PC even though it is implicit
# jitlink-check: decode_operand(call_site + 0, 0) = call_target_arm - (call_site + 8)
# jitlink-check: decode_operand(call_site + 4, 0) = call_target_thumb - (call_site + 12)
.globl call_site
.type call_site,%function
# CHECK-INSTR: 00000008 <call_site_a2t>:
# CHECK-INSTR: 8: ebfffffe bl
# CHECK-INSTR: 00000010 <call_target_arm>
# CHECK-INSTR: 00000014 <call_target_thumb>
# jitlink-check: decode_operand(call_site_a2a, 0) = call_target_arm - next_pc(call_site_a2a)
# jitlink-check: decode_operand(call_site_a2t, 0) = call_target_thumb - next_pc(call_site_a2t)
.globl call_site_a2a
.type call_site_a2a, %function
.p2align 2
call_site:
call_site_a2a:
bl call_target_arm
bx lr
.size call_site_a2a, .-call_site_a2a

.globl call_site_a2t
.type call_site_a2t,%function
.p2align 2
call_site_a2t:
bl call_target_thumb
bx lr
.size call_site, .-call_site
.size call_site_a2t, .-call_site_a2t

.globl call_target_arm
.type call_target_arm,%function
Expand All @@ -59,10 +65,10 @@ call_target_thumb:
.code 32

# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_JUMP24 jump24_target
# CHECK-INSTR: 00000014 <jump24_site>:
# CHECK-INSTR: 14: eafffffe b
# CHECK-INSTR: 00000018 <jump24_target>
# jitlink-check: decode_operand(jump24_site, 0) = jump24_target - (jump24_site + 8)
# CHECK-INSTR: 00000018 <jump24_site>:
# CHECK-INSTR: 18: eafffffe b
# CHECK-INSTR: 0000001c <jump24_target>
# jitlink-check: decode_operand(jump24_site, 0) = jump24_target - next_pc(jump24_site)
.globl jump24_site
.type jump24_site,%function
.p2align 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ target1_abs32:
# The +12 accounts for the ARM branch offset (8) and the .LPC offset (4), which
# is stored as initial addend inline.
# FIXME: We shouldn't need to substract the 64-bit sign-extension manually.
# jitlink-check: *{4}got_prel_offset = got_addr(out.o, target) - (got_prel + 12) - 0xffffffff00000000
# jitlink-check: *{4}got_prel_offset = got_addr(out.o, target) - (next_pc(got_prel) + 4) - 0xffffffff00000000
.globl got_prel
.type got_prel,%function
.p2align 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# CHECK-INSTR: f7ff fffe bl
# We decode the operand with index 2, because bl generates two leading implicit
# predicate operands that we have to skip in order to decode the call_target operand
# jitlink-check: decode_operand(call_site, 2) = call_target_thumb - (call_site + 4)
# jitlink-check: decode_operand(call_site, 2) = call_target_thumb - next_pc(call_site)
.globl call_site
.type call_site,%function
.p2align 1
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/ExecutionEngine/JITLink/AArch32/ELF_stubs_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# hard-code it in the immediate field.

# The external function ext will return to the caller directly.
# jitlink-check: decode_operand(test_arm_jump, 0) = stub_addr(out.o, ext) - (test_arm_jump + 8)
# jitlink-check: decode_operand(test_arm_jump, 0) = stub_addr(out.o, ext) - next_pc(test_arm_jump)
.globl test_arm_jump
.type test_arm_jump,%function
.p2align 2
Expand All @@ -38,7 +38,7 @@ test_arm_jump:
# The branch-with-link sets the LR register so that the external function ext
# returns to us. We have to save the register (push) and return to main manually
# (pop). This adds the +4 offset for the bl instruction we decode:
# jitlink-check: decode_operand(test_arm_call + 4, 0) = stub_addr(out.o, ext) - (test_arm_call + 8) - 4
# jitlink-check: decode_operand(test_arm_call + 4, 0) = stub_addr(out.o, ext) - next_pc(test_arm_call) - 4
.globl test_arm_call
.type test_arm_call,%function
.p2align 2
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/ExecutionEngine/JITLink/AArch32/ELF_stubs_multi.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# ascending size (because the default memory manager lays out blocks by size).

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

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