Skip to content

Commit 1a3f886

Browse files
committed
[llvm-objdump] Add an llvm-otool tool
This implements an LLVM tool that's flag- and output-compatible with macOS's `otool` -- except for bugs, but from testing with both `otool` and `xcrun otool-classic`, llvm-otool matches vanilla otool's behavior very well already. It's not 100% perfect, but it's a very solid start. This uses the same approach as llvm-objcopy: llvm-objdump uses a different OptTable when it's invoked as llvm-otool. This is possible thanks to D100433. Differential Revision: https://reviews.llvm.org/D100583
1 parent 8a6772f commit 1a3f886

29 files changed

Lines changed: 509 additions & 68 deletions

‎llvm/docs/CommandGuide/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Basic Commands
2929
llvm-link
3030
llvm-lipo
3131
llvm-mca
32+
llvm-otool
3233
llvm-profdata
3334
llvm-readobj
3435
llvm-stress

‎llvm/docs/CommandGuide/llvm-objdump.rst‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,5 @@ To report bugs, please visit <https://bugs.llvm.org/>.
390390
SEE ALSO
391391
--------
392392

393-
:manpage:`llvm-nm(1)`, :manpage:`llvm-readelf(1)`, :manpage:`llvm-readobj(1)`
393+
:manpage:`llvm-nm(1)`, :manpage:`llvm-otool(1)`, :manpage:`llvm-readelf(1)`,
394+
:manpage:`llvm-readobj(1)`
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
llvm-otool - Mach-O dumping tool
2+
================================
3+
4+
.. program:: llvm-otool
5+
6+
SYNOPSIS
7+
--------
8+
9+
:program:`llvm-otool` [*option...*] *[file...]*
10+
11+
DESCRIPTION
12+
-----------
13+
14+
:program:`llvm-otool` is a tool for dumping Mach-O files.
15+
16+
It attempts to be command-line-compatible and output-compatible with macOS's
17+
:program:`otool`.
18+
19+
OPTIONS
20+
-------
21+
22+
.. option:: -arch <value>
23+
24+
Select slice of universal Mach-O file.
25+
26+
.. option:: -C
27+
28+
Print linker optimization hints.
29+
30+
.. option:: -D
31+
32+
Print shared library id.
33+
34+
.. option:: -d
35+
36+
Print data section.
37+
38+
.. option:: -f
39+
40+
Print universal headers.
41+
42+
.. option:: -G
43+
44+
Print data-in-code table.
45+
46+
.. option:: --help-hidden
47+
48+
Print help for hidden flags.
49+
50+
.. option:: --help
51+
52+
Print help.
53+
54+
.. option:: -h
55+
56+
Print mach header.
57+
58+
.. option:: -I
59+
60+
Print indirect symbol table.
61+
62+
.. option:: -j
63+
64+
Print opcode bytes.
65+
66+
.. option:: -L
67+
68+
Print used shared libraries.
69+
70+
.. option:: -l
71+
72+
Print load commnads.
73+
74+
.. option:: -mcpu=<value>
75+
76+
Select cpu for disassembly.
77+
78+
.. option:: -o
79+
80+
Print Objective-C segment.
81+
82+
.. option:: -P
83+
84+
Print __TEXT,__info_plist section as strings.
85+
86+
.. option:: -p <function name>
87+
88+
Start disassembly at <function name>.
89+
90+
.. option:: -r
91+
92+
Print relocation entries.
93+
94+
.. option:: -s <segname> <sectname>
95+
96+
Print contents of section.
97+
98+
.. option:: -t
99+
100+
Print text section.
101+
102+
.. option:: --version
103+
104+
Print version.
105+
106+
.. option:: -V
107+
108+
Symbolize disassembled operands (implies :option:`-v`).
109+
110+
.. option:: -v
111+
112+
Verbose output / disassemble when printing text sections.
113+
114+
.. option:: -X
115+
116+
Omit leading addresses or headers.
117+
118+
.. option:: -x
119+
120+
Print all text sections.
121+
122+
.. option:: @<FILE>
123+
124+
Read command-line options and commands from response file `<FILE>`.
125+
126+
EXIT STATUS
127+
-----------
128+
129+
:program:`llvm-otool` exits with a non-zero exit code if there is an error.
130+
Otherwise, it exits with code 0.
131+
132+
BUGS
133+
----
134+
135+
To report bugs, please visit <https://bugs.llvm.org/>.
136+
137+
SEE ALSO
138+
--------
139+
140+
:manpage:`llvm-nm(1)`, :manpage:`llvm-objdump(1)`

‎llvm/test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ set(LLVM_TEST_DEPENDS
100100
llvm-objdump
101101
llvm-opt-fuzzer
102102
llvm-opt-report
103+
llvm-otool
103104
llvm-pdbutil
104105
llvm-profdata
105106
llvm-profgen

‎llvm/test/lit.cfg.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def get_asan_rtlib():
160160
'llvm-isel-fuzzer', 'llvm-ifs',
161161
'llvm-install-name-tool', 'llvm-jitlink', 'llvm-opt-fuzzer', 'llvm-lib',
162162
'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mca',
163-
'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump',
163+
'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump', 'llvm-otool',
164164
'llvm-pdbutil', 'llvm-profdata', 'llvm-ranlib', 'llvm-rc', 'llvm-readelf',
165165
'llvm-readobj', 'llvm-rtdyld', 'llvm-size', 'llvm-split', 'llvm-strings',
166166
'llvm-strip', 'llvm-tblgen', 'llvm-undname', 'llvm-c-test', 'llvm-cxxfilt',

‎llvm/test/tools/llvm-objdump/MachO/AArch64/macho-link-opt-hints.test‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
RUN: llvm-objdump -m --link-opt-hints %p/Inputs/link-opt-hints.macho-aarch64 | FileCheck %s
2+
RUN: llvm-otool -C %p/Inputs/link-opt-hints.macho-aarch64 | FileCheck %s
23

34
CHECK: Linker optimiztion hints (8 total bytes)
45
CHECK: identifier 8 AdrpLdrGot

‎llvm/test/tools/llvm-objdump/MachO/ARM/data-in-code.test‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
RUN: llvm-objdump -m --data-in-code %p/Inputs/data-in-code.macho-arm | FileCheck %s
2+
RUN: llvm-otool -Gv %p/Inputs/data-in-code.macho-arm | FileCheck %s
23
RUN: llvm-objdump -m --data-in-code --non-verbose %p/Inputs/data-in-code.macho-arm | FileCheck %s --check-prefix=NON_VERBOSE
4+
RUN: llvm-otool -G %p/Inputs/data-in-code.macho-arm | FileCheck %s --check-prefix=NON_VERBOSE
35

46
CHECK: Data in code table (4 entries)
57
CHECK: offset length kind

‎llvm/test/tools/llvm-objdump/MachO/ARM/mcpu-arm.test‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
@ RUN: llvm-mc < %s -triple thumbv7-apple-darwin -mcpu=cortex-a7 -filetype=obj | llvm-objdump --triple thumbv7-apple-darwin10 -m -d --mcpu=cortex-a7 - | FileCheck %s
1+
@ RUN: llvm-mc %s -triple thumbv7-apple-darwin -mcpu=cortex-a7 -filetype=obj -o %t.o
2+
@ RUN: llvm-objdump --triple thumbv7-apple-darwin10 -m -d --mcpu=cortex-a7 %t.o | FileCheck %s
3+
@ RUN: llvm-otool -tv -mcpu=cortex-a7 %t.o | FileCheck %s
24

35
.thumb
46
.thumb_func _t

‎llvm/test/tools/llvm-objdump/MachO/data-in-code.ll‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; RUN: llc --mtriple x86_64-apple-darwin -filetype=obj -O0 %s -o %t.o
22
; RUN: llvm-objdump --macho -d --no-show-raw-insn %t.o | FileCheck %s
3+
; RUN: llvm-otool -tv %t.o | FileCheck %s
34

45
; CHECK: .long {{[0-9]+}} @ KIND_JUMP_TABLE32
56
; CHECK: .long {{[0-9]+}} @ KIND_JUMP_TABLE32

‎llvm/test/tools/llvm-objdump/MachO/dis-no-leading-addr.test‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# RUN: llvm-objdump --macho -d %p/Inputs/hello.obj.macho-x86_64 --no-show-raw-insn --print-imm-hex --no-leading-addr | FileCheck %s
1+
# RUN: llvm-objdump --macho -d %p/Inputs/hello.obj.macho-x86_64 --no-show-raw-insn --print-imm-hex --no-leading-addr | FileCheck --check-prefixes=CHECK,HEAD %s
2+
# RUN: llvm-otool -tVX %p/Inputs/hello.obj.macho-x86_64 | FileCheck --implicit-check-not=section %s
23

3-
# CHECK: (__TEXT,__text) section
4+
# HEAD: (__TEXT,__text) section
45
# CHECK: _main:
56
# CHECK: pushq %rbp
67
# CHECK: movq %rsp, %rbp

0 commit comments

Comments
 (0)