[llvm-objdump] Print memory operand addresses as regular comments

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
This commit is contained in:
Igor Kudrin 2021-06-28 14:24:39 +07:00
parent e7fffa6f03
commit d25e572421
12 changed files with 51 additions and 39 deletions

View File

@ -3,13 +3,13 @@
# RUN: %lld -lSystem %t.o -o %t # RUN: %lld -lSystem %t.o -o %t
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
# CHECK: leaq {{.*}} # 0x100000000 # CHECK: leaq {{.*}} ## 0x100000000
# CHECK-NEXT: leaq {{.*}} # 0x100000000 # CHECK-NEXT: leaq {{.*}} ## 0x100000000
# RUN: %lld -dylib %t.o -o %t.dylib # 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 # 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: leaq {{.*}} ## 0x0
# DYLIB-CHECK-NEXT: leaq {{.*}} # 0x0 # DYLIB-CHECK-NEXT: leaq {{.*}} ## 0x0
# DYLIB-LABEL: Sections: # DYLIB-LABEL: Sections:
# DYLIB: __data 00000008 [[#%x,DATA:]] DATA # DYLIB: __data 00000008 [[#%x,DATA:]] DATA

View File

@ -10,8 +10,8 @@
# CHECK: callq 0x[[#%x,FOO_OFF:]] # CHECK: callq 0x[[#%x,FOO_OFF:]]
# CHECK-NEXT: callq 0x[[#%x,BAR_OFF:]] # CHECK-NEXT: callq 0x[[#%x,BAR_OFF:]]
# CHECK: [[#%x,BAR_OFF]]: jmpq {{.*}} # 0x[[#%x,BAR_BIND:]] # CHECK: [[#%x,BAR_OFF]]: jmpq {{.*}} ## 0x[[#%x,BAR_BIND:]]
# CHECK: [[#%x,FOO_OFF]]: jmpq {{.*}} # 0x[[#%x,FOO_BIND:]] # CHECK: [[#%x,FOO_OFF]]: jmpq {{.*}} ## 0x[[#%x,FOO_BIND:]]
# CHECK-LABEL: Lazy bind table: # CHECK-LABEL: Lazy bind table:
# CHECK-DAG: __DATA __la_symbol_ptr 0x[[#%x,FOO_BIND]] Foo _foo # CHECK-DAG: __DATA __la_symbol_ptr 0x[[#%x,FOO_BIND]] Foo _foo

View File

@ -18,7 +18,8 @@
; NO-FMA: <_foo>: ; NO-FMA: <_foo>:
; NO-FMA-NEXT: vrcpss %xmm0, %xmm0, %xmm1 ; NO-FMA-NEXT: vrcpss %xmm0, %xmm0, %xmm1
; NO-FMA-NEXT: vmulss %xmm1, %xmm0, %xmm0 ; 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: vsubss %xmm0, %xmm2, %xmm0
; NO-FMA-NEXT: vmulss %xmm0, %xmm1, %xmm0 ; NO-FMA-NEXT: vmulss %xmm0, %xmm1, %xmm0
; NO-FMA-NEXT: vaddss %xmm0, %xmm1, %xmm0 ; NO-FMA-NEXT: vaddss %xmm0, %xmm1, %xmm0

View File

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

View File

@ -14,7 +14,7 @@
# RUN: llvm-objdump --bind --no-show-raw-insn -d -r %t/with-reexport | FileCheck %s # RUN: llvm-objdump --bind --no-show-raw-insn -d -r %t/with-reexport | FileCheck %s
# CHECK: Disassembly of section __TEXT,__text: # CHECK: Disassembly of section __TEXT,__text:
# CHECK: movq {{.*}} # 0x[[ADDR:[0-9a-f]+]] # CHECK: movq {{.*}} ## 0x[[ADDR:[0-9a-f]+]]
# CHECK: Bind table: # CHECK: Bind table:
# CHECK-DAG: __DATA_CONST __got 0x[[ADDR]] pointer 0 libSystem ___nan # CHECK-DAG: __DATA_CONST __got 0x[[ADDR]] pointer 0 libSystem ___nan

View File

@ -17,9 +17,9 @@
# RUN: %lld -lSystem -L%t -ltlv %t/test.o -o %t/test # 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 # RUN: llvm-objdump --bind -d --no-show-raw-insn %t/test | FileCheck %s
# CHECK: movq [[#]](%rip), %rax # 0x[[#%x, FOO:]] # CHECK: movq [[#]](%rip), %rax ## 0x[[#%x, FOO:]]
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%x, BAR:]] # CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%x, BAR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%x, BAZ:]] # CHECK-NEXT: movq [[#]](%rip), %rax ## 0x[[#%x, BAZ:]]
# CHECK-LABEL: Bind table: # CHECK-LABEL: Bind table:
# CHECK-DAG: __DATA __thread_ptrs 0x{{0*}}[[#%x, FOO]] pointer 0 libtlv _foo # CHECK-DAG: __DATA __thread_ptrs 0x{{0*}}[[#%x, FOO]] pointer 0 libtlv _foo

View File

@ -34,13 +34,13 @@
# HEADER: MH_HAS_TLV_DESCRIPTORS # HEADER: MH_HAS_TLV_DESCRIPTORS
# REG: <_main>: # REG: <_main>:
# REG-NEXT: leaq {{.*}}(%rip), %rax # {{.*}} <_foo> # REG-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_foo>
# REG-NEXT: leaq {{.*}}(%rip), %rax # {{.*}} <_bar> # REG-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_bar>
# REG-NEXT: retq # REG-NEXT: retq
# TBSS: <_f>: # TBSS: <_f>:
# TBSS-NEXT: leaq {{.*}}(%rip), %rax # {{.*}} <_baz> # TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_baz>
# TBSS-NEXT: leaq {{.*}}(%rip), %rax # {{.*}} <_qux> # TBSS-NEXT: leaq {{.*}}(%rip), %rax ## {{.*}} <_qux>
# TBSS-NEXT: retq # TBSS-NEXT: retq
# REG-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # REG-TLVP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

View File

@ -19,12 +19,12 @@
# CHECK-NEXT: {{[0-9a-f]+}} {{[0-9a-f ]*[1-9a-f]+[0-9a-f ]*}} # CHECK-NEXT: {{[0-9a-f]+}} {{[0-9a-f ]*[1-9a-f]+[0-9a-f ]*}}
# CHECK: <_main>: # CHECK: <_main>:
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%X,WEAK_DY_GOT_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: movq [[#]](%rip), %rax ## 0x[[#%X,WEAK_EXT_GOT_ADDR:]]
# CHECK-NEXT: leaq [[#]](%rip), %rax # 0x[[#%X,WEAK_INT_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_TLV_ADDR:]]
# CHECK-NEXT: movq [[#]](%rip), %rax # 0x[[#%X,WEAK_DY_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: 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]*}} # CHECK-NEXT: callq 0x{{[0-9a-f]*}}
# CHECK-NEXT: callq 0x{{[0-9a-f]*}} # CHECK-NEXT: callq 0x{{[0-9a-f]*}}

View File

@ -6,7 +6,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: %lld -o %t %t.o # RUN: %lld -o %t %t.o
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
# CHECK: leaq [[#]](%rip), %rax # {{.*}} <_foo> # CHECK: leaq [[#]](%rip), %rax ## {{.*}} <_foo>
.globl _main, _foo .globl _main, _foo

View File

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

View File

@ -10,14 +10,14 @@
# Instructions are expected to be aligned if the instruction in hex is not too long. # Instructions are expected to be aligned if the instruction in hex is not too long.
# CHECK: 0: c3 |retq # 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: 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: 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: 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> # CHECK-NEXT: 2b: ff ff |<unknown>
# NORAW: 0: |retq # 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: 8: |movabsq|$0x5555555555555554, %rax # imm = 0x5555555555555554
# NORAW-NEXT: 12: |lwpval|$0x0, 0x40(%rdx,%rax), %r15d # NORAW-NEXT: 12: |lwpval|$0x0, 0x40(%rdx,%rax), %r15d
# NORAW-NEXT: 1d: |lwpins|$0x0, 0x1cf01cf0, %r15d # NORAW-NEXT: 1d: |lwpins|$0x0, 0x1cf01cf0, %r15d

View File

@ -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 // address (jump target or memory operand address) and print it on the
// right of the instruction. // right of the instruction.
if (Disassembled && MIA) { if (Disassembled && MIA) {
// Branch targets are printed just after the instructions.
llvm::raw_ostream *TargetOS = &FOS;
uint64_t Target; uint64_t Target;
bool PrintTarget = bool PrintTarget =
MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target); MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target);
@ -1443,8 +1445,11 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
Target = *MaybeTarget; Target = *MaybeTarget;
PrintTarget = true; PrintTarget = true;
// Do not print real address when symbolizing. // Do not print real address when symbolizing.
if (!SymbolizeOperands) if (!SymbolizeOperands) {
FOS << " # 0x" << Twine::utohexstr(Target); // Memory operand addresses are printed as comments.
TargetOS = &CommentStream;
*TargetOS << "0x" << Twine::utohexstr(Target);
}
} }
if (PrintTarget) { if (PrintTarget) {
// In a relocatable object, the target's section must reside in // In a relocatable object, the target's section must reside in
@ -1503,22 +1508,26 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
if (Demangle) if (Demangle)
TargetName = demangle(TargetName); TargetName = demangle(TargetName);
FOS << " <"; *TargetOS << " <";
if (!Disp) { if (!Disp) {
// Always Print the binary symbol precisely corresponding to // Always Print the binary symbol precisely corresponding to
// the target address. // the target address.
FOS << TargetName; *TargetOS << TargetName;
} else if (!LabelAvailable) { } else if (!LabelAvailable) {
// Always Print the binary symbol plus an offset if there's no // Always Print the binary symbol plus an offset if there's no
// local label corresponding to the target address. // local label corresponding to the target address.
FOS << TargetName << "+0x" << Twine::utohexstr(Disp); *TargetOS << TargetName << "+0x" << Twine::utohexstr(Disp);
} else { } else {
FOS << AllLabels[Target]; *TargetOS << AllLabels[Target];
} }
FOS << ">"; *TargetOS << ">";
} else if (LabelAvailable) { } 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";
} }
} }
} }