diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp index 5f517b47..e8eb59f6 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp @@ -369,8 +369,10 @@ AArch64MCCodeEmitter::getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx, const MCOperand &MO = MI.getOperand(OpIdx); // If the destination is an immediate, we have nothing to do. - if (MO.isImm()) - return MO.getImm(); + if (MO.isImm()) { + // encode relative address + return (MO.getImm() * 4 - MI.getAddress()) / 4; + } assert(MO.isExpr() && "Unexpected ADR target type!"); MCFixupKind Kind = MI.getOpcode() == AArch64::BL