Skip to content

Commit

Permalink
[llvm-objdump] Print memory operand addresses as regular comments
Browse files Browse the repository at this point in the history
The patch reuses the common code to print memory operand addresses as
instruction comments. This helps to align the comments and enables using
target-specific comment markers when `evaluateMemoryOperandAddress()` is
implemented for them.

Differential Revision: https://reviews.llvm.org/D104861
  • Loading branch information
igorkudrin committed Jun 28, 2021
1 parent e7fffa6 commit d25e572
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 39 deletions.
8 changes: 4 additions & 4 deletions lld/test/MachO/dso-handle.s
Expand Up @@ -3,13 +3,13 @@

# RUN: %lld -lSystem %t.o -o %t
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
# CHECK: leaq {{.*}} # 0x100000000
# CHECK-NEXT: leaq {{.*}} # 0x100000000
# CHECK: leaq {{.*}} ## 0x100000000
# CHECK-NEXT: leaq {{.*}} ## 0x100000000

# RUN: %lld -dylib %t.o -o %t.dylib
# RUN: llvm-objdump -d --no-show-raw-insn --rebase --section-headers %t.dylib | FileCheck %s --check-prefix=DYLIB-CHECK
# DYLIB-CHECK: leaq {{.*}} # 0x0
# DYLIB-CHECK-NEXT: leaq {{.*}} # 0x0
# DYLIB-CHECK: leaq {{.*}} ## 0x0
# DYLIB-CHECK-NEXT: leaq {{.*}} ## 0x0

# DYLIB-LABEL: Sections:
# DYLIB: __data 00000008 [[#%x,DATA:]] DATA
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/dylink-ordinal.s
Expand Up @@ -10,8 +10,8 @@
# CHECK: callq 0x[[#%x,FOO_OFF:]]
# CHECK-NEXT: callq 0x[[#%x,BAR_OFF:]]

# CHECK: [[#%x,BAR_OFF]]: jmpq {{.*}} # 0x[[#%x,BAR_BIND:]]
# CHECK: [[#%x,FOO_OFF]]: jmpq {{.*}} # 0x[[#%x,FOO_BIND:]]
# CHECK: [[#%x,BAR_OFF]]: jmpq {{.*}} ## 0x[[#%x,BAR_BIND:]]
# CHECK: [[#%x,FOO_OFF]]: jmpq {{.*}} ## 0x[[#%x,FOO_BIND:]]

# CHECK-LABEL: Lazy bind table:
# CHECK-DAG: __DATA __la_symbol_ptr 0x[[#%x,FOO_BIND]] Foo _foo
Expand Down
3 changes: 2 additions & 1 deletion lld/test/MachO/mattrs.ll
Expand Up @@ -18,7 +18,8 @@
; NO-FMA: <_foo>:
; NO-FMA-NEXT: vrcpss %xmm0, %xmm0, %xmm1
; NO-FMA-NEXT: vmulss %xmm1, %xmm0, %xmm0
; NO-FMA-NEXT: vmovss [[#]](%rip), %xmm2
; NO-FMA-NEXT: vmovss [[#]](%rip), %xmm2 ## xmm2 =
; NO-FMA-NEXT: ## 0x
; NO-FMA-NEXT: vsubss %xmm0, %xmm2, %xmm0
; NO-FMA-NEXT: vmulss %xmm0, %xmm1, %xmm0
; NO-FMA-NEXT: vaddss %xmm0, %xmm1, %xmm0
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/static-link.s
Expand Up @@ -15,7 +15,7 @@

# CHECK: Disassembly of section __TEXT,__text
# CHECK-LABEL: <_main>:
# CHECK: leaq {{.*}}(%rip), %rsi # 0x[[ADDR]] <_goodbye_world>
# CHECK: leaq {{.*}}(%rip), %rsi ## 0x[[ADDR]] <_goodbye_world>

.section __TEXT,__text
.global _main
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/tapi-link.s
Expand Up @@ -14,7 +14,7 @@
# RUN: llvm-objdump --bind --no-show-raw-insn -d -r %t/with-reexport | FileCheck %s

# CHECK: Disassembly of section __TEXT,__text:
# CHECK: movq {{.*}} # 0x[[ADDR:[0-9a-f]+]]
# CHECK: movq {{.*}} ## 0x[[ADDR:[0-9a-f]+]]

# CHECK: Bind table:
# CHECK-DAG: __DATA_CONST __got 0x[[ADDR]] pointer 0 libSystem ___nan
Expand Down
6 changes: 3 additions & 3 deletions lld/test/MachO/tlv-dylib.s
Expand Up @@ -17,9 +17,9 @@
# RUN: %lld -lSystem -L%t -ltlv %t/test.o -o %t/test
# RUN: llvm-objdump --bind -d --no-show-raw-insn %t/test | FileCheck %s

# CHECK: movq [[#]](%rip), %rax # 0x[[#%x, FOO:]]
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%x, BAR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%x, BAZ:]]
# CHECK: movq [[#]](%rip), %rax ## 0x[[#%x, FOO:]]
# CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%x, BAR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%x, BAZ:]]

# CHECK-LABEL: Bind table:
# CHECK-DAG: __DATA __thread_ptrs 0x{{0*}}[[#%x, FOO]] pointer 0 libtlv _foo
Expand Down
8 changes: 4 additions & 4 deletions lld/test/MachO/tlv.s
Expand Up @@ -34,13 +34,13 @@
# HEADER: MH_HAS_TLV_DESCRIPTORS

# REG: <_main>:
# REG-NEXT: leaq {{.*}}(%rip), %rax # {{.*}} <_foo>
# REG-NEXT: leaq {{.*}}(%rip), %rax # {{.*}} <_bar>
# REG-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_foo>
# REG-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_bar>
# REG-NEXT: retq

# TBSS: <_f>:
# TBSS-NEXT: leaq {{.*}}(%rip), %rax # {{.*}} <_baz>
# TBSS-NEXT: leaq {{.*}}(%rip), %rax # {{.*}} <_qux>
# TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_baz>
# TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_qux>
# TBSS-NEXT: retq

# REG-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Expand Down
12 changes: 6 additions & 6 deletions lld/test/MachO/weak-binding.s
Expand Up @@ -19,12 +19,12 @@
# CHECK-NEXT: {{[0-9a-f]+}} {{[0-9a-f ]*[1-9a-f]+[0-9a-f ]*}}

# CHECK: <_main>:
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%X,WEAK_DY_GOT_ADDR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%X,WEAK_EXT_GOT_ADDR:]]
# CHECK-NEXT: leaq [[#]](%rip), %rax # 0x[[#%X,WEAK_INT_GOT_ADDR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%X,WEAK_TLV_ADDR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%X,WEAK_DY_TLV_ADDR:]]
# CHECK-NEXT: leaq [[#]](%rip), %rax # 0x[[#%X,WEAK_INT_TLV_ADDR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%X,WEAK_DY_GOT_ADDR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%X,WEAK_EXT_GOT_ADDR:]]
# CHECK-NEXT: leaq [[#]](%rip), %rax ## 0x[[#%X,WEAK_INT_GOT_ADDR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%X,WEAK_TLV_ADDR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%X,WEAK_DY_TLV_ADDR:]]
# CHECK-NEXT: leaq [[#]](%rip), %rax ## 0x[[#%X,WEAK_INT_TLV_ADDR:]]
# CHECK-NEXT: callq 0x{{[0-9a-f]*}}
# CHECK-NEXT: callq 0x{{[0-9a-f]*}}
# CHECK-NEXT: callq 0x{{[0-9a-f]*}}
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/x86-64-reloc-got-load.s
Expand Up @@ -6,7 +6,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: %lld -o %t %t.o
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
# CHECK: leaq [[#]](%rip), %rax # {{.*}} <_foo>
# CHECK: leaq [[#]](%rip), %rax ## {{.*}} <_foo>

.globl _main, _foo

Expand Down
14 changes: 8 additions & 6 deletions lld/test/MachO/x86-64-reloc-signed.s
Expand Up @@ -12,18 +12,20 @@

# CHECK-LABEL: Disassembly of section
# CHECK: <_main>:
# CHECK-NEXT: movl {{.*}} # 0x[[#S]]
# CHECK-NEXT: movl {{.*}} ## imm =
# CHECK-NEXT: ## 0x[[#S]]
# CHECK-NEXT: callq {{.*}}
# CHECK-NEXT: movl {{.*}} # 0x[[#S + 2]]
# CHECK-NEXT: movl {{.*}} ## 0x[[#S + 2]]
# CHECK-NEXT: callq {{.*}}
# CHECK-NEXT: movb {{.*}} # 0x[[#S]]
# CHECK-NEXT: movb {{.*}} ## 0x[[#S]]
# CHECK-NEXT: callq {{.*}}
# CHECK: <__not_text>:
# CHECK-NEXT: movl {{.*}} # 0x[[#FOO + 8]]
# CHECK-NEXT: movl {{.*}} ## imm =
# CHECK-NEXT: ## 0x[[#FOO + 8]]
# CHECK-NEXT: callq {{.*}}
# CHECK-NEXT: movl {{.*}} # 0x[[#FOO + 8 + 2]]
# CHECK-NEXT: movl {{.*}} ## 0x[[#FOO + 8 + 2]]
# CHECK-NEXT: callq {{.*}}
# CHECK-NEXT: movb {{.*}} # 0x[[#FOO + 8]]
# CHECK-NEXT: movb {{.*}} ## 0x[[#FOO + 8]]
# CHECK-NEXT: callq {{.*}}

.section __TEXT,__text
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/tools/llvm-objdump/X86/disassemble-align.s
Expand Up @@ -10,14 +10,14 @@
# Instructions are expected to be aligned if the instruction in hex is not too long.

# CHECK: 0: c3 |retq
# CHECK-NEXT: 1: 48 8b 05 56 34 12 00 |movq|0x123456(%rip), %rax # 0x12345e <.text+0x12345e>
# CHECK-NEXT: 1: 48 8b 05 56 34 12 00 |movq|0x123456(%rip), %rax # 0x12345e <.text+0x12345e>
# CHECK-NEXT: 8: 48 b8 54 55 55 55 55 55 55 55|movabsq|$0x5555555555555554, %rax # imm = 0x5555555555555554
# CHECK-NEXT: 12: 8f ea 00 12 4c 02 40 00 00 00 00 |lwpval|$0x0, 0x40(%rdx,%rax), %r15d
# CHECK-NEXT: 1d: 8f ea 00 12 04 25 f0 1c f0 1c 00 00 00 00 |lwpins|$0x0, 0x1cf01cf0, %r15d
# CHECK-NEXT: 2b: ff ff |<unknown>

# NORAW: 0: |retq
# NORAW-NEXT: 1: |movq|0x123456(%rip), %rax # 0x12345e <.text+0x12345e>
# NORAW-NEXT: 1: |movq|0x123456(%rip), %rax # 0x12345e <.text+0x12345e>
# NORAW-NEXT: 8: |movabsq|$0x5555555555555554, %rax # imm = 0x5555555555555554
# NORAW-NEXT: 12: |lwpval|$0x0, 0x40(%rdx,%rax), %r15d
# NORAW-NEXT: 1d: |lwpins|$0x0, 0x1cf01cf0, %r15d
Expand Down
25 changes: 17 additions & 8 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Expand Up @@ -1433,6 +1433,8 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
// address (jump target or memory operand address) and print it on the
// right of the instruction.
if (Disassembled && MIA) {
// Branch targets are printed just after the instructions.
llvm::raw_ostream *TargetOS = &FOS;
uint64_t Target;
bool PrintTarget =
MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target);
Expand All @@ -1443,8 +1445,11 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
Target = *MaybeTarget;
PrintTarget = true;
// Do not print real address when symbolizing.
if (!SymbolizeOperands)
FOS << " # 0x" << Twine::utohexstr(Target);
if (!SymbolizeOperands) {
// Memory operand addresses are printed as comments.
TargetOS = &CommentStream;
*TargetOS << "0x" << Twine::utohexstr(Target);
}
}
if (PrintTarget) {
// In a relocatable object, the target's section must reside in
Expand Down Expand Up @@ -1503,22 +1508,26 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
if (Demangle)
TargetName = demangle(TargetName);

FOS << " <";
*TargetOS << " <";
if (!Disp) {
// Always Print the binary symbol precisely corresponding to
// the target address.
FOS << TargetName;
*TargetOS << TargetName;
} else if (!LabelAvailable) {
// Always Print the binary symbol plus an offset if there's no
// local label corresponding to the target address.
FOS << TargetName << "+0x" << Twine::utohexstr(Disp);
*TargetOS << TargetName << "+0x" << Twine::utohexstr(Disp);
} else {
FOS << AllLabels[Target];
*TargetOS << AllLabels[Target];
}
FOS << ">";
*TargetOS << ">";
} else if (LabelAvailable) {
FOS << " <" << AllLabels[Target] << ">";
*TargetOS << " <" << AllLabels[Target] << ">";
}
// By convention, each record in the comment stream should be
// terminated.
if (TargetOS == &CommentStream)
*TargetOS << "\n";
}
}
}
Expand Down

0 comments on commit d25e572

Please sign in to comment.