Skip to content

Commit

Permalink
[llvm-objdump] Decrease instruction indentation for non-x86
Browse files Browse the repository at this point in the history
Place the instruction at the 24th column (0-based indexing), matching
GNU objdump ARM/AArch64/powerpc/etc when the address is low.

This is beneficial for non-x86 targets which have short instruction
lengths.

```
// GNU objdump AArch64
   0:   91001062        add     x2, x3, #0x4
  400078:       91001062        add     x2, x3, #0x4
// llvm-objdump, with this patch
       0: 62 10 00 91   add     x2, x3, #4
  400078: 62 10 00 91   add     x2, x3, #4
// llvm-objdump, if we change to print a word instead of bytes in the future
       0: 91001062      add     x2, x3, #4
  400078: 91001062      add     x2, x3, #4

// GNU objdump Thumb
   0:   bf00            nop

// GNU objdump Power ISA 3.1 64-bit instruction
// 0:   00 00 10 04     plwa    r3,0
// 4:   00 00 60 a4
```

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D81590
  • Loading branch information
MaskRay committed Jun 11, 2020
1 parent fac7259 commit 5ee5717
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions llvm/test/tools/llvm-objdump/ELF/AArch64/disassemble-align.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t
# RUN: llvm-objdump -d %t | tr '\t' '|' | FileCheck --match-full-lines --strict-whitespace %s

## Use '|' to show where the tabs line up.
# CHECK:0000000000000000 <$x.0>:
# CHECK-NEXT: 0: 62 10 00 91 |add|x2, x3, #4
# CHECK-EMPTY:
# CHECK-NEXT:0000000000000004 <$d.1>:
# CHECK-NEXT: 4:|ff ff 00 00|.word|0x0000ffff

add x2, x3, #4
.word 0xffff
8 changes: 5 additions & 3 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,11 @@ class PrettyPrinter {
dumpBytes(Bytes, OS);
}

// The output of printInst starts with a tab. Print some spaces so that
// the tab has 1 column and advances to the target tab stop.
unsigned TabStop = NoShowRawInsn ? 16 : 40;
// The output of printInst starts with a tab. Print some spaces so that the
// tab has 1 column and advances to the target tab stop. Give more columns
// to x86 which may encode an instruction with many bytes.
unsigned TabStop =
NoShowRawInsn ? 16 : STI.getTargetTriple().isX86() ? 40 : 24;
unsigned Column = OS.tell() - Start;
OS.indent(Column < TabStop - 1 ? TabStop - 1 - Column : 7 - Column % 8);

Expand Down

0 comments on commit 5ee5717

Please sign in to comment.