Index: test/tools/llvm-objdump/X86/disassemble-align.s =================================================================== --- /dev/null +++ test/tools/llvm-objdump/X86/disassemble-align.s @@ -0,0 +1,30 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t +# RUN: llvm-objdump -d -print-imm-hex %t | sed 'y/\t/ /' | FileCheck -strict-whitespace %s + +# -w/--wide is ignored. llvm-objdump always produces wide output. +# RUN: llvm-objdump -wd -print-imm-hex %t | sed 'y/\t/ /' | FileCheck -strict-whitespace %s +# RUN: llvm-objdump --wide -d -print-imm-hex %t | sed 's/\t/ /g' | FileCheck -strict-whitespace %s + +# RUN: llvm-objdump -d -print-imm-hex -no-show-raw-insn %t | sed 's/\t/ /g' | \ +# RUN: FileCheck -check-prefix=NORAW -strict-whitespace %s + +# Instructions are expected to be aligned if the instruction in hex is not too long. + +# CHECK: 0: 55 pushq %rbp +# CHECK-NEXT: 1: 48 8b 05 56 34 12 00 movq 0x123456(%rip), %rax +# CHECK-NEXT: 8: 48 b8 54 55 55 55 55 55 55 55 movabsq $0x5555555555555554, %rax +# CHECK-NEXT: 12: c3 retq +# CHECK-NEXT: 13: ff ff + +# NORAW: 0: pushq %rbp +# NORAW-NEXT: 1: movq 0x123456(%rip), %rax +# NORAW-NEXT: 8: movabsq $0x5555555555555554, %rax +# NORAW-NEXT: 12: retq +# NORAW-NEXT: 13: + +.text + pushq %rbp + movq 0x123456(%rip),%rax + movabs $0x5555555555555554,%rax + ret + .word 0xffff Index: tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- tools/llvm-objdump/llvm-objdump.cpp +++ tools/llvm-objdump/llvm-objdump.cpp @@ -605,12 +605,23 @@ std::vector *Rels = nullptr) { if (SP && (PrintSource || PrintLines)) SP->printSourceLine(OS, Address); - if (!NoLeadingAddr) - OS << format("%8" PRIx64 ":", Address.Address); - if (!NoShowRawInsn) { - OS << "\t"; - dumpBytes(Bytes, OS); + + { + formatted_raw_ostream FOS(OS); + if (!NoLeadingAddr) + FOS << format("%8" PRIx64 ":", Address.Address); + if (!NoShowRawInsn) { + FOS << ' '; + dumpBytes(Bytes, FOS); + } + FOS.flush(); + // The output of printInst starts with a tab. Print some spaces so that + // the tab has 1 column and advances to a target tab stop. + unsigned TabStop = NoShowRawInsn ? 16 : 40; + unsigned Column = FOS.getColumn(); + FOS.indent(Column < TabStop - 1 ? TabStop - 1 - Column : 7 - Column % 8); } + if (MI) IP.printInst(MI, OS, "", STI); else