Index: test/CodeGen/Mips/micromips-b-range.ll =================================================================== --- test/CodeGen/Mips/micromips-b-range.ll +++ test/CodeGen/Mips/micromips-b-range.ll @@ -44,8 +44,7 @@ ; CHECK-NEXT: 9a: ff fd 00 00 lw $ra, 0($sp) ; CHECK-NEXT: 9e: 00 01 0f 3c jr $1 ; CHECK-NEXT: a2: 33 bd 00 08 addiu $sp, $sp, 8 - -; CHECK: 10466: 00 00 00 00 nop +; CHECK: ... ; CHECK-NEXT: 1046a: 94 00 00 02 b 8 ; CHECK-NEXT: 1046e: 00 00 00 00 nop ; CHECK-NEXT: 10472: 33 bd ff f8 addiu $sp, $sp, -8 Index: test/ELF/mips-micro-jal.s =================================================================== --- test/ELF/mips-micro-jal.s +++ test/ELF/mips-micro-jal.s @@ -57,9 +57,7 @@ # EB-NEXT: 20022: 45 f9 jalrs16 $25 # EB-NEXT: 20024: 0f 83 move $gp, $3 # EB-NEXT: 20026: 0c 00 nop -# EB-NEXT: 20028: 00 00 00 00 nop -# EB-NEXT: 2002c: 00 00 00 00 nop - +# EB-NEXT: ... # EB-NEXT: 20030: 79 00 3f f7 addiupc $2, 65500 # EB-NEXT: 20034: ff 22 00 00 lw $25, 0($2) # EB-NEXT: 20038: 45 99 jr16 $25 @@ -76,9 +74,7 @@ # EL-NEXT: 20022: f9 45 jalrs16 $25 # EL-NEXT: 20024: 83 0f move $gp, $3 # EL-NEXT: 20026: 00 0c nop -# EL-NEXT: 20028: 00 00 00 00 nop -# EL-NEXT: 2002c: 00 00 00 00 nop - +# EL-NEXT: ... # EL-NEXT: 20030: 00 79 f7 3f addiupc $2, 65500 # EL-NEXT: 20034: 22 ff 00 00 lw $25, 0($2) # EL-NEXT: 20038: 99 45 jr16 $25 @@ -127,9 +123,7 @@ # MIXED-NEXT: 20032: 45 f9 jalrs16 $25 # MIXED-NEXT: 20034: 0f 83 move $gp, $3 # MIXED-NEXT: 20036: 0c 00 nop -# MIXED-NEXT: 20038: 00 00 00 00 nop -# MIXED-NEXT: 2003c: 00 00 00 00 nop - +# MIXED-NEXT: ... # MIXED-NEXT: 20040: 79 00 3f f3 addiupc $2, 65484 # MIXED-NEXT: 20044: ff 22 00 00 lw $25, 0($2) # MIXED-NEXT: 20048: 45 99 jr16 $25 Index: test/ELF/relocation-size-shared.s =================================================================== --- test/ELF/relocation-size-shared.s +++ test/ELF/relocation-size-shared.s @@ -28,20 +28,7 @@ // DISASM-NEXT: 20100c: 00 00 // DISASM-NEXT: 20100e: 00 00 // DISASM-NEXT: 201010: 1b 00 -// DISASM-NEXT: 201012: 00 00 -// DISASM-NEXT: 201014: 00 00 -// DISASM-NEXT: 201016: 00 00 -// DISASM-NEXT: 201018: 00 00 -// DISASM-NEXT: 20101a: 00 00 -// DISASM-NEXT: 20101c: 00 00 -// DISASM-NEXT: 20101e: 00 00 -// DISASM-NEXT: 201020: 00 00 -// DISASM-NEXT: 201022: 00 00 -// DISASM-NEXT: 201024: 00 00 -// DISASM-NEXT: 201026: 00 00 -// DISASM-NEXT: 201028: 00 00 -// DISASM-NEXT: 20102a: 00 00 -// DISASM-NEXT: 20102c: 00 00 +// DISASM-NEXT: ... // DISASM-NEXT: 20102e: 00 00 // DISASM: _start: // DISASM-NEXT: 201030: 8b 04 25 19 00 00 00 movl 25, %eax Index: test/ELF/relocation-size.s =================================================================== --- test/ELF/relocation-size.s +++ test/ELF/relocation-size.s @@ -57,18 +57,7 @@ // DISASMSHARED: Disassembly of section test: // DISASMSHARED-NEXT: _data: -// DISASMSHARED-NEXT: 1000: 00 00 -// DISASMSHARED-NEXT: 1002: 00 00 -// DISASMSHARED-NEXT: 1004: 00 00 -// DISASMSHARED-NEXT: 1006: 00 00 -// DISASMSHARED-NEXT: 1008: 00 00 -// DISASMSHARED-NEXT: 100a: 00 00 -// DISASMSHARED-NEXT: 100c: 00 00 -// DISASMSHARED-NEXT: 100e: 00 00 -// DISASMSHARED-NEXT: 1010: 00 00 -// DISASMSHARED-NEXT: 1012: 00 00 -// DISASMSHARED-NEXT: 1014: 00 00 -// DISASMSHARED-NEXT: 1016: 00 00 +// DISASMSHARED-NEXT: ... // DISASMSHARED-NEXT: 1018: 19 00 // DISASMSHARED-NEXT: 101a: 00 00 // DISASMSHARED-NEXT: 101c: 00 00 Index: test/MC/Mips/cpsetup.s =================================================================== --- test/MC/Mips/cpsetup.s +++ test/MC/Mips/cpsetup.s @@ -1,5 +1,5 @@ # RUN: llvm-mc -triple mips-unknown-linux -target-abi o32 -filetype=obj -o - %s | \ -# RUN: llvm-objdump -d -r - | FileCheck -check-prefixes=ALL,O32 %s +# RUN: llvm-objdump -d -r -z - | FileCheck -check-prefixes=ALL,O32 %s # RUN: llvm-mc -triple mips-unknown-linux -target-abi o32 %s | \ # RUN: FileCheck -check-prefixes=ALL,ASM,ASM-O32 %s @@ -7,14 +7,14 @@ # FIXME: Now we check .cpsetup expansion for `-mno-shared` case only. # We also need to implement/check the `-mshared` case. # RUN: llvm-mc -triple mips64-unknown-linux -target-abi n32 -filetype=obj -o - %s | \ -# RUN: llvm-objdump -d -r - | \ +# RUN: llvm-objdump -d -r -z - | \ # RUN: FileCheck -check-prefixes=ALL,NXX,N32 %s # RUN: llvm-mc -triple mips64-unknown-linux -target-abi n32 %s | \ # RUN: FileCheck -check-prefixes=ALL,ASM,ASM-N32 %s # RUN: llvm-mc -triple mips64-unknown-linux %s -filetype=obj -o - | \ -# RUN: llvm-objdump -d -r - | \ +# RUN: llvm-objdump -d -r -z - | \ # RUN: FileCheck -check-prefixes=ALL,NXX,N64 %s # RUN: llvm-mc -triple mips64-unknown-linux %s | \ Index: test/MC/Mips/nacl-mask.s =================================================================== --- test/MC/Mips/nacl-mask.s +++ test/MC/Mips/nacl-mask.s @@ -1,5 +1,5 @@ # RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-nacl %s \ -# RUN: | llvm-objdump -disassemble -no-show-raw-insn - | FileCheck %s +# RUN: | llvm-objdump -disassemble -z -no-show-raw-insn - | FileCheck %s # This test tests that address-masking sandboxing is added when given assembly # input. Index: test/MC/X86/disassemble-zeroes.s =================================================================== --- /dev/null +++ test/MC/X86/disassemble-zeroes.s @@ -0,0 +1,81 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t +// RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=NODISASM + +// The exact rules of skipping the bytes you can find in the code. +// This test checks that we follow these rules and that can force +// dissasembly of zero blocks with the -z and --disassemble-zeroes options. + +// NODISASM: Disassembly of section .text: +// NODISASM-NEXT: 0000000000000000 main: +// NODISASM-NEXT: 0: 00 00 addb %al, (%rax) +// NODISASM-NEXT: 2: 00 00 addb %al, (%rax) +// NODISASM-NEXT: 4: 00 00 addb %al, (%rax) +// NODISASM-NEXT: 6: 00 90 00 00 00 00 addb %dl, (%rax) +// NODISASM-NEXT: ... +// NODISASM-NEXT: 20: 90 nop +// NODISASM-NEXT: ... +// NODISASM: 0000000000000031 foo: +// NODISASM-NEXT: 31: 00 00 addb %al, (%rax) +// NODISASM-NEXT: 33: 00 00 addb %al, (%rax) +// NODISASM: 0000000000000035 bar: +// NODISASM-NEXT: ... + +// Check that with -z we disassemble zeroes blocks. +// RUN: llvm-objdump -d -z %t | FileCheck %s --check-prefix=DISASM + +// DISASM: Disassembly of section .text: +// DISASM-NEXT: 0000000000000000 main: +// DISASM-NEXT: 0: 00 00 addb %al, (%rax) +// DISASM-NEXT: 2: 00 00 addb %al, (%rax) +// DISASM-NEXT: 4: 00 00 addb %al, (%rax) +// DISASM-NEXT: 6: 00 90 00 00 00 00 addb %dl, (%rax) +// DISASM-NEXT: c: 00 00 addb %al, (%rax) +// DISASM-NEXT: e: 00 00 addb %al, (%rax) +// DISASM-NEXT: 10: 00 00 addb %al, (%rax) +// DISASM-NEXT: 12: 00 00 addb %al, (%rax) +// DISASM-NEXT: 14: 00 00 addb %al, (%rax) +// DISASM-NEXT: 16: 00 00 addb %al, (%rax) +// DISASM-NEXT: 18: 00 00 addb %al, (%rax) +// DISASM-NEXT: 1a: 00 00 addb %al, (%rax) +// DISASM-NEXT: 1c: 00 00 addb %al, (%rax) +// DISASM-NEXT: 1e: 00 00 addb %al, (%rax) +// DISASM-NEXT: 20: 90 nop +// DISASM-NEXT: 21: 00 00 addb %al, (%rax) +// DISASM-NEXT: 23: 00 00 addb %al, (%rax) +// DISASM-NEXT: 25: 00 00 addb %al, (%rax) +// DISASM-NEXT: 27: 00 00 addb %al, (%rax) +// DISASM-NEXT: 29: 00 00 addb %al, (%rax) +// DISASM-NEXT: 2b: 00 00 addb %al, (%rax) +// DISASM-NEXT: 2d: 00 00 addb %al, (%rax) +// DISASM-NEXT: 2f: 00 00 addb %al, (%rax) +// DISASM: 0000000000000031 foo: +// DISASM-NEXT: 31: 00 00 addb %al, (%rax) +// DISASM-NEXT: 33: 00 00 addb %al, (%rax) +// DISASM: 0000000000000035 bar: +// DISASM-NEXT: 35: 00 00 addb %al, (%rax) +// DISASM-NEXT: 37: 00 00 addb %al, (%rax) +// DISASM-NEXT: 39: 00 00 addb %al, (%rax) +// DISASM-NEXT: 3b: 00 00 addb %al, (%rax) + +// Check that --disassemble-zeroes work as alias for -z. +// RUN: llvm-objdump -d --disassemble-zeroes %t | FileCheck %s --check-prefix=DISASM + +.text +.globl main +.type main, @function +main: + .long 0 + .byte 0 + .byte 0 + .byte 0 + nop + .quad 0 + .quad 0 + .quad 0 + nop + .quad 0 + .quad 0 +foo: + .long 0 +bar: + .quad 0 Index: tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- tools/llvm-objdump/llvm-objdump.cpp +++ tools/llvm-objdump/llvm-objdump.cpp @@ -267,6 +267,14 @@ cl::opt StopAddress("stop-address", cl::desc("Stop disassembly at address"), cl::value_desc("address"), cl::init(UINT64_MAX)); + +cl::opt DisassembleZeroes("disassemble-zeroes", + cl::desc("Do not skip blocks of zeroes when " + "disassembling the blocks of zeroes")); +cl::alias DisassembleZeroesShort("z", + cl::desc("Alias for --disassemble-zeroes"), + cl::aliasopt(DisassembleZeroes)); + static StringRef ToolName; typedef std::vector> SectionSymbolsTy; @@ -1298,6 +1306,29 @@ } } +// Normally the disassembly output will skip blocks of zeroes. This function for +// the given buffer Buf with the instructions returns the number of zero bytes +// that can be skipped during dumping the disassembly output. +static size_t skipZeroesBlock(ArrayRef Buf) { + // When -z or --disassemble-zeroes are given we always dissasemble them. + if (DisassembleZeroes) + return 0; + + // Find the amount of leading zeroes. + size_t Amount = 0; + while (Amount < Buf.size() && !Buf[Amount]) + ++Amount; + + // We may want to skip blocks of zero bytes, but not earlier + // than we see at least 8 of them in a row. + if (Amount < 8) + return 0; + + // We skip zeroes in multiples of 4 because do not want to truncate an + // instruction if it starts with a zero byte. + return Amount & ~0x3; +} + static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (StartAddress > StopAddress) error("Start address should be less than stop address"); @@ -1732,6 +1763,13 @@ if (Index >= End) break; + if (size_t N = skipZeroesBlock(Bytes.slice(Index, End - Index))) { + outs() << "\t\t..." << '\n'; + Index += N; + if (Index >= End) + break; + } + // Disassemble a real instruction or a data when disassemble all is // provided bool Disassembled = DisAsm->getInstruction(Inst, Size, Bytes.slice(Index),