[PATCH] D104446: [objdump][ARM] Fix evaluating the target address of a Thumb BLX(i)
Igor Kudrin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 17 20:42:26 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG85ec21075100: [objdump][ARM] Fix evaluating the target address of a Thumb BLX(i) (authored by ikudrin).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104446/new/
https://reviews.llvm.org/D104446
Files:
llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
llvm/test/tools/llvm-objdump/ELF/ARM/tblxi-target.s
Index: llvm/test/tools/llvm-objdump/ELF/ARM/tblxi-target.s
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/ELF/ARM/tblxi-target.s
@@ -0,0 +1,26 @@
+## Check that the disassembler reports the target address of a Thumb BLX(i)
+## instruction correctly even if the instruction is not 32-bit aligned.
+
+# RUN: llvm-mc %s --triple=armv8a -filetype=obj | \
+# RUN: llvm-objdump -dr - --triple armv8a --no-show-raw-insn | \
+# RUN: FileCheck %s
+
+# CHECK: <test>:
+# CHECK-NEXT: 4: nop
+# CHECK-NEXT: 6: blx #-8 <foo>
+# CHECK-NEXT: a: blx #4 <bar>
+
+ .arm
+foo:
+ nop
+
+ .thumb
+test:
+ nop
+ blx #-8
+ blx #4
+
+ .arm
+ .p2align 2
+bar:
+ nop
Index: llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
===================================================================
--- llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
+++ llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
@@ -429,6 +429,14 @@
// is 4 bytes.
uint64_t Offset = ((Desc.TSFlags & ARMII::FormMask) == ARMII::ThumbFrm) ? 4 : 8;
+ // A Thumb instruction BLX(i) can be 16-bit aligned while targets Arm code
+ // which is 32-bit aligned. The target address for the case is calculated as
+ // targetAddress = Align(PC,4) + imm32;
+ // where
+ // Align(x, y) = y * (x DIV y);
+ if (Inst.getOpcode() == ARM::tBLXi)
+ Addr &= ~0x3;
+
Target = Addr + Imm + Offset;
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104446.352909.patch
Type: text/x-patch
Size: 1493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210618/4b3411bb/attachment.bin>
More information about the llvm-commits
mailing list