[llvm] 95e4db8 - [llvm-objdump] --adjust-vma: Call getInstruction with adjusted address
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 20 08:54:56 PDT 2025
Author: Fangrui Song
Date: 2025-05-20T08:54:53-07:00
New Revision: 95e4db8fa7d4adf1cd629e3fa7877ec95a1adfaa
URL: https://github.com/llvm/llvm-project/commit/95e4db8fa7d4adf1cd629e3fa7877ec95a1adfaa
DIFF: https://github.com/llvm/llvm-project/commit/95e4db8fa7d4adf1cd629e3fa7877ec95a1adfaa.diff
LOG: [llvm-objdump] --adjust-vma: Call getInstruction with adjusted address
llvm-objdump currently calls MCDisassembler::getInstruction with
unadjusted address and MCInstPrinter::printInst with adjusted address.
The decoded branch targets will be adjusted as expected for most targets
(as the getInstruction address is insignificant) but not for SystemZ
(where the getInstruction address is displayed).
Specify an adjust address to fix SystemZInstPrinter output.
The added test utilizes llvm/utils/update_test_body.py to make updates
easier and additionally checks that we don't adjust SHN_ABS symbol
addresses.
Pull Request: https://github.com/llvm/llvm-project/pull/140471
Added:
llvm/test/tools/llvm-objdump/ELF/SystemZ/adjust-vma.test
Modified:
llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
llvm/tools/llvm-objdump/llvm-objdump.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objdump/ELF/SystemZ/adjust-vma.test b/llvm/test/tools/llvm-objdump/ELF/SystemZ/adjust-vma.test
new file mode 100644
index 0000000000000..4f6eb8fa0f76d
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/ELF/SystemZ/adjust-vma.test
@@ -0,0 +1,98 @@
+## SystemZDisassembler sets the branch target information during getInstruction instead of printInst.
+## Test we display the branch targets correctly in the presence of --adjust-vma.
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: yaml2obj a.yaml -o out
+# RUN: llvm-objdump -td --adjust-vma=0x200000 --no-show-raw-insn out | FileCheck %s --match-full-lines
+
+# CHECK: SYMBOL TABLE:
+# CHECK-NEXT: 0000000001200104 l .text 0000000000000000 f1
+# CHECK-NEXT: 0000000001200106 l .text 0000000000000000 f2
+# CHECK-NEXT: 0000000000000800 l *ABS* 0000000000000000 abs
+
+# CHECK: 00000000012000f8 <_start>:
+# CHECK-NEXT: 12000f8: brasl %r14, 0x1200104
+# CHECK-NEXT: 12000fe: brasl %r14, 0x1200106
+# CHECK-EMPTY:
+# CHECK-NEXT: 0000000001200104 <f1>:
+# CHECK-NEXT: 1200104: br %r14
+# CHECK-EMPTY:
+# CHECK-NEXT: 0000000001200106 <f2>:
+# CHECK-NEXT: 1200106: br %r14
+
+#--- a.s
+.globl _start
+_start:
+ brasl %r14, f1
+ brasl %r14, f2
+
+f1:
+ br %r14
+f2:
+ br %r14
+
+abs = 0x800
+#--- gen
+LLD_IN_TEST=1 clang --target=s390x-linux -no-pie -nostdlib -Wl,--no-rosegment,-zseparate-code,-znorelro,-znognustack -fuse-ld=lld a.s -o a
+obj2yaml a
+#--- a.yaml
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2MSB
+ Type: ET_EXEC
+ Machine: EM_S390
+ Entry: 0x10000F8
+ProgramHeaders:
+ - Type: PT_PHDR
+ Flags: [ PF_R ]
+ VAddr: 0x1000040
+ Align: 0x8
+ Offset: 0x40
+ - Type: PT_INTERP
+ Flags: [ PF_R ]
+ FirstSec: .interp
+ LastSec: .interp
+ VAddr: 0x10000E8
+ Offset: 0xE8
+ - Type: PT_LOAD
+ Flags: [ PF_X, PF_R ]
+ FirstSec: .interp
+ LastSec: .text
+ VAddr: 0x1000000
+ Align: 0x1000
+ Offset: 0x0
+Sections:
+ - Name: .interp
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ Address: 0x10000E8
+ AddressAlign: 0x1
+ Content: 2F6C69622F6C6436342E736F2E3100
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x10000F8
+ AddressAlign: 0x4
+ Content: C0E500000006C0E50000000407FE07FE
+ - Name: .comment
+ Type: SHT_PROGBITS
+ Flags: [ SHF_MERGE, SHF_STRINGS ]
+ AddressAlign: 0x1
+ EntSize: 0x1
+ Offset: 0x1000
+ Content: 4C696E6B65723A204C4C442032312E302E3000
+Symbols:
+ - Name: f1
+ Section: .text
+ Value: 0x1000104
+ - Name: f2
+ Section: .text
+ Value: 0x1000106
+ - Name: abs
+ Index: SHN_ABS
+ Value: 0x800
+ - Name: _start
+ Section: .text
+ Binding: STB_GLOBAL
+ Value: 0x10000F8
+...
diff --git a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
index c3dcc2dfd2e1e..eb4c170f766c3 100644
--- a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
+++ b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
@@ -4,6 +4,9 @@
# RUN: llvm-objdump %t -d --symbolize-operands -M att --no-show-raw-insn --no-leading-addr | \
# RUN: FileCheck %s --match-full-lines --check-prefix=ATT
+# RUN: llvm-objdump %t -d --symbolize-operands -M intel --no-show-raw-insn --no-leading-addr --adjust-vma=0x2000 | \
+# RUN: FileCheck %s --match-full-lines --check-prefix=INTEL
+
## Expect to find the branch labels and global variable name.
# ATT: <_start>:
# ATT-NEXT: pushq %rax
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 7a778da2d3a49..99bb41f5b95a7 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2323,7 +2323,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
// provided
MCInst Inst;
ArrayRef<uint8_t> ThisBytes = Bytes.slice(Index);
- uint64_t ThisAddr = SectionAddr + Index;
+ uint64_t ThisAddr = SectionAddr + Index + VMAAdjustment;
bool Disassembled = DT->DisAsm->getInstruction(
Inst, Size, ThisBytes, ThisAddr, CommentStream);
if (Size == 0)
More information about the llvm-commits
mailing list