Skip to content

Commit 164b5e2

Browse files
committed
Teach evalNextPC to decode addition expression with a symbol
1 parent 8b06eca commit 164b5e2

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,41 @@ class RuntimeDyldCheckerExprEval {
354354
EvalResult(("Cannot decode unknown symbol '" + Symbol + "'").str()),
355355
"");
356356

357+
// if there is an offset number expr
358+
int64_t SymbolOffset = 0;
359+
BinOpToken BinOp;
360+
std::tie(BinOp, RemainingExpr) = parseBinOpToken(RemainingExpr);
361+
switch (BinOp) {
362+
case BinOpToken::Add: {
363+
EvalResult Number;
364+
std::tie(Number, RemainingExpr) = evalNumberExpr(RemainingExpr);
365+
SymbolOffset = Number.getValue();
366+
break;
367+
}
368+
case BinOpToken::Invalid:
369+
break;
370+
default:
371+
return std::make_pair(
372+
unexpectedToken(RemainingExpr, RemainingExpr,
373+
"expected '+' for offset or ')' if no offset"),
374+
"");
375+
}
376+
357377
if (!RemainingExpr.starts_with(")"))
358378
return std::make_pair(
359379
unexpectedToken(RemainingExpr, RemainingExpr, "expected ')'"), "");
360380
RemainingExpr = RemainingExpr.substr(1).ltrim();
361381

362382
MCInst Inst;
363383
uint64_t InstSize;
364-
if (!decodeInst(Symbol, Inst, InstSize, 0))
384+
if (!decodeInst(Symbol, Inst, InstSize, SymbolOffset))
365385
return std::make_pair(
366386
EvalResult(("Couldn't decode instruction at '" + Symbol + "'").str()),
367387
"");
368388

369-
uint64_t SymbolAddr = PCtx.IsInsideLoad
370-
? Checker.getSymbolLocalAddr(Symbol)
371-
: Checker.getSymbolRemoteAddr(Symbol);
389+
uint64_t SymbolAddr =
390+
PCtx.IsInsideLoad ? Checker.getSymbolLocalAddr(Symbol)
391+
: Checker.getSymbolRemoteAddr(Symbol) + SymbolOffset;
372392

373393
// ARM mode adds an offset of 4 bytes to PC
374394
auto TT = Checker.getTripleForSymbol(Checker.getTargetFlag(Symbol));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# CHECK-INSTR: 0000000c <call_target_arm>
3030
# CHECK-INSTR: 00000010 <call_target_thumb>
3131
# jitlink-check: decode_operand(call_site + 0, 0) = call_target_arm - next_pc(call_site)
32-
# jitlink-check: decode_operand(call_site + 4, 0) = call_target_thumb - (call_site + 12)
32+
# jitlink-check: decode_operand(call_site + 4, 0) = call_target_thumb - next_pc(call_site + 4)
3333
.globl call_site
3434
.type call_site,%function
3535
.p2align 2

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)