mirror of
https://github.com/keystone-engine/keystone
synced 2026-06-08 15:15:30 +00:00
ARM64, fix issue for PC-relative offset (#291)
b.cond/cbz/cbnz/tbz/tbnz/adrp
This commit is contained in:
@@ -1133,7 +1133,7 @@ public:
|
||||
return false;
|
||||
|
||||
if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
|
||||
int64_t Val = CE->getValue();
|
||||
int64_t Val = CE->getValue() - Ctx.getBaseAddress();
|
||||
int64_t Min = - (4096 * (1LL << (21 - 1)));
|
||||
int64_t Max = 4096 * ((1LL << (21 - 1)) - 1);
|
||||
return (Val % 4096) == 0 && Val >= Min && Val <= Max;
|
||||
|
||||
@@ -219,7 +219,7 @@ AArch64MCCodeEmitter::getAdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
|
||||
|
||||
// If the destination is an immediate, we have nothing to do.
|
||||
if (MO.isImm())
|
||||
return MO.getImm();
|
||||
return (MO.getImm() * 4096 - MI.getAddress()) / 4096;
|
||||
assert(MO.isExpr() && "Unexpected target type!");
|
||||
const MCExpr *Expr = MO.getExpr();
|
||||
|
||||
@@ -268,7 +268,7 @@ uint32_t AArch64MCCodeEmitter::getCondBranchTargetOpValue(
|
||||
|
||||
// If the destination is an immediate, we have nothing to do.
|
||||
if (MO.isImm())
|
||||
return MO.getImm();
|
||||
return (MO.getImm() * 4 - MI.getAddress()) / 4;
|
||||
assert(MO.isExpr() && "Unexpected target type!");
|
||||
|
||||
MCFixupKind Kind = MCFixupKind(AArch64::fixup_aarch64_pcrel_branch19);
|
||||
@@ -332,7 +332,7 @@ uint32_t AArch64MCCodeEmitter::getTestBranchTargetOpValue(
|
||||
|
||||
// If the destination is an immediate, we have nothing to do.
|
||||
if (MO.isImm())
|
||||
return MO.getImm();
|
||||
return (MO.getImm() * 4 - MI.getAddress()) / 4;
|
||||
assert(MO.isExpr() && "Unexpected ADR target type!");
|
||||
|
||||
MCFixupKind Kind = MCFixupKind(AArch64::fixup_aarch64_pcrel_branch14);
|
||||
|
||||
Reference in New Issue
Block a user