[PATCH] D105528: [RuntimeDyldChecker] Support offset in decode_operand expr
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 18 04:16:15 PDT 2021
StephenFan updated this revision to Diff 359611.
StephenFan added a comment.
Address @jrtc27 and @lhames 's comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105528/new/
https://reviews.llvm.org/D105528
Files:
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
Index: llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
===================================================================
--- llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
+++ llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
@@ -18,7 +18,8 @@
.size main, .-main
# Test R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO
-# jitlink-check: decode_operand(test_pcrel32, 1) = ((named_data - test_pcrel32) + 0x800)[31:12]
+# jitlink-check: decode_operand(test_pcrel32, 1) = ((named_data - test_pcrel32) + 0x800)[31:12]
+# jitlink-check: decode_operand(test_pcrel32+4, 2)[11:0] = ((named_data - test_pcrel32) & 0xfff)[11:0]
.globl test_pcrel32
.p2align 1
.type test_pcrel32, at function
Index: llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
===================================================================
--- llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
+++ llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
@@ -232,6 +232,26 @@
EvalResult(("Cannot decode unknown symbol '" + Symbol + "'").str()),
"");
+ // if there is an offset number expr
+ int64_t Offset = 0;
+ BinOpToken BinOp;
+ std::tie(BinOp, RemainingExpr) = parseBinOpToken(RemainingExpr);
+ switch (BinOp) {
+ case BinOpToken::Add:
+ case BinOpToken::Sub: {
+ EvalResult Number;
+ std::tie(Number, RemainingExpr) = evalNumberExpr(RemainingExpr);
+ Offset =
+ BinOp == BinOpToken::Add ? Number.getValue() : -Number.getValue();
+ break;
+ }
+ case BinOpToken::Invalid:
+ break;
+ default:
+ return std::make_pair(unexpectedToken(RemainingExpr, RemainingExpr,
+ "expected '+ or -' for offset or ',' if no offset"), "");
+ }
+
if (!RemainingExpr.startswith(","))
return std::make_pair(
unexpectedToken(RemainingExpr, RemainingExpr, "expected ','"), "");
@@ -249,7 +269,7 @@
MCInst Inst;
uint64_t Size;
- if (!decodeInst(Symbol, Inst, Size))
+ if (!decodeInst(Symbol, Inst, Size, Offset))
return std::make_pair(
EvalResult(("Couldn't decode instruction at '" + Symbol + "'").str()),
"");
@@ -307,7 +327,7 @@
MCInst Inst;
uint64_t InstSize;
- if (!decodeInst(Symbol, Inst, InstSize))
+ if (!decodeInst(Symbol, Inst, InstSize, 0))
return std::make_pair(
EvalResult(("Couldn't decode instruction at '" + Symbol + "'").str()),
"");
@@ -664,10 +684,12 @@
return evalComplexExpr(std::make_pair(ThisResult, RemainingExpr), PCtx);
}
- bool decodeInst(StringRef Symbol, MCInst &Inst, uint64_t &Size) const {
+ bool decodeInst(StringRef Symbol, MCInst &Inst, uint64_t &Size,
+ int64_t Offset) const {
MCDisassembler *Dis = Checker.Disassembler;
StringRef SymbolMem = Checker.getSymbolContent(Symbol);
- ArrayRef<uint8_t> SymbolBytes(SymbolMem.bytes_begin(), SymbolMem.size());
+ ArrayRef<uint8_t> SymbolBytes(SymbolMem.bytes_begin() + Offset,
+ SymbolMem.size() - Offset);
MCDisassembler::DecodeStatus S =
Dis->getInstruction(Inst, Size, SymbolBytes, 0, nulls());
@@ -675,7 +697,7 @@
return (S == MCDisassembler::Success);
}
};
-}
+} // namespace llvm
RuntimeDyldCheckerImpl::RuntimeDyldCheckerImpl(
IsSymbolValidFunction IsSymbolValid, GetSymbolInfoFunction GetSymbolInfo,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105528.359611.patch
Type: text/x-patch
Size: 3463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210718/696277d5/attachment-0001.bin>
More information about the llvm-commits
mailing list