[PATCH] D139407: [llvm-objdump][AArch64] Fix ADRP target label calculation
Kristina Bessonova via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 6 02:34:05 PST 2022
krisb created this revision.
krisb added reviewers: ikudrin, MaskRay, simon_tatham, rafauler.
Herald added subscribers: StephenFan, hiraditya, kristof.beyls, emaste.
Herald added a reviewer: jhenderson.
Herald added a project: All.
krisb requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch makes ADRP target label address calculations the same as
label address calculations (see AArch64InstPrinter::printAdrpLabel()).
Otherwise the target label looks misleading as ADRP's immediate offset is,
actually, not an offset to this PC, but an offset to the current PC's
page address in pages.
See for example, `llvm-objdump/ELF/AArch64/pcrel-address.yaml`.
Before this patch the target label `<_start+0x80>` represents the
address `0x200100 + 0x80` while `0x220000` is expected.
Note that with this patch llvm-objdump output matches GNU objdump.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D139407
Files:
llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
llvm/test/tools/llvm-objdump/ELF/AArch64/pcrel-address.yaml
Index: llvm/test/tools/llvm-objdump/ELF/AArch64/pcrel-address.yaml
===================================================================
--- llvm/test/tools/llvm-objdump/ELF/AArch64/pcrel-address.yaml
+++ llvm/test/tools/llvm-objdump/ELF/AArch64/pcrel-address.yaml
@@ -2,7 +2,7 @@
# RUN: llvm-objdump %t -d --no-show-raw-insn --no-leading-addr | FileCheck %s
# CHECK-LABEL: <_start>:
-# CHECK-NEXT: adrp x2, 0x220000 <_start+0x80>
+# CHECK-NEXT: adrp x2, 0x220000 <_start+0x1ff00>
--- !ELF
FileHeader:
@@ -16,10 +16,6 @@
Address: 0x200100
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Content: '02010090'
- - Name: .data
- Type: SHT_PROGBITS
- Flags: [SHF_ALLOC, SHF_WRITE]
- Address: 0x220000
Symbols:
- Name: _start
Section: .text
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
===================================================================
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
@@ -412,8 +412,11 @@
const auto &Desc = Info->get(Inst.getOpcode());
for (unsigned i = 0, e = Inst.getNumOperands(); i != e; i++) {
if (Desc.OpInfo[i].OperandType == MCOI::OPERAND_PCREL) {
- int64_t Imm = Inst.getOperand(i).getImm() * 4;
- Target = Addr + Imm;
+ int64_t Imm = Inst.getOperand(i).getImm();
+ if (Inst.getOpcode() == AArch64::ADRP)
+ Target = (Addr & -4096) + Imm * 4096;
+ else
+ Target = Addr + Imm * 4;
return true;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139407.480403.patch
Type: text/x-patch
Size: 1575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221206/1e25a22c/attachment.bin>
More information about the llvm-commits
mailing list