Skip to content

Commit 55f40c8

Browse files
authored
[llvm-otool] Add -a option to print archive headers (llvm#189411)
Wire up llvm-otool's -a to the existing --archive-headers machinery with a default of displaying all architectures to match classic otool behaviour.
1 parent d05b3e0 commit 55f40c8

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

llvm/docs/CommandGuide/llvm-otool.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ It attempts to be command-line-compatible and output-compatible with macOS's
1919
OPTIONS
2020
-------
2121

22+
.. option:: -a
23+
24+
Print archive header.
25+
2226
.. option:: -arch <value>
2327

2428
Select slice of universal Mach-O file.

llvm/test/tools/llvm-objdump/MachO/archive-headers.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ RUN: | FileCheck %s -check-prefix=OFFSETS
55
RUN: llvm-objdump %p/Inputs/macho-universal-archive.x86_64.i386 --macho --archive-headers --arch all --non-verbose \
66
RUN: | FileCheck %s -check-prefix=NON-VERBOSE
77

8+
# llvm-otool -a shows all architectures by default.
9+
RUN: llvm-otool -a %p/Inputs/macho-universal-archive.x86_64.i386 \
10+
RUN: | FileCheck %s -check-prefix=NON-VERBOSE
11+
12+
# llvm-otool -a -arch filters to one slice.
13+
RUN: llvm-otool -a -arch x86_64 %p/Inputs/macho-universal-archive.x86_64.i386 \
14+
RUN: | FileCheck %s -check-prefix=OTOOL-ARCH --implicit-check-not="(architecture i386)"
15+
816
# Note the date as printed by ctime(3) is time zone dependent and not checked.
917
CHECK: Archive : {{.*}}/macho-universal-archive.x86_64.i386 (architecture x86_64)
1018
CHECK: -rw-r--r--124/11 44 {{.*}} __.SYMDEF SORTED
@@ -26,3 +34,7 @@ NON-VERBOSE: 0100644 124/0 860 1399501499 #1/12
2634
NON-VERBOSE: Archive : {{.*}}/macho-universal-archive.x86_64.i386 (architecture i386)
2735
NON-VERBOSE: 0100644 124/11 60 1399572709 #1/20
2836
NON-VERBOSE: 0100644 124/0 388 1399572697 #1/12
37+
38+
OTOOL-ARCH: Archive : {{.*}}macho-universal-archive.x86_64.i386
39+
OTOOL-ARCH-NEXT: 0100644 124/11 44
40+
OTOOL-ARCH-NEXT: 0100644 124/0 860

llvm/tools/llvm-objdump/MachODump.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,8 +2675,9 @@ void objdump::parseInputMachO(MachOUniversalBinary *UB) {
26752675
return;
26762676
}
26772677
// No architecture flags were specified so if this contains a slice that
2678-
// matches the host architecture dump only that.
2679-
if (!ArchAll) {
2678+
// matches the host architecture dump only that. For otool -a dump all
2679+
// architectures to match classic otool behaviour.
2680+
if (!ArchAll && !(IsOtool && ArchiveHeaders)) {
26802681
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
26812682
E = UB->end_objects();
26822683
I != E; ++I) {

llvm/tools/llvm-objdump/OtoolOpts.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ def help : Flag<["--"], "help">, HelpText<"print help">;
44
def help_hidden : Flag<["--"], "help-hidden">,
55
HelpText<"print help for hidden flags">;
66

7+
def a : Flag<["-"], "a">, HelpText<"print archive header">;
78
def arch : Separate<["-"], "arch">,
89
HelpText<"select slice of universal Mach-O file">;
910
def C : Flag<["-"], "C">, HelpText<"print linker optimization hints">;
@@ -43,7 +44,6 @@ def dyld_info : Flag<["-"], "dyld_info">,
4344
HelpText<"print bind and rebase information">;
4445

4546
// Not (yet?) implemented:
46-
// def a : Flag<["-"], "a">, HelpText<"print archive header">;
4747
// -c print argument strings of a core file
4848
// -m don't use archive(member) syntax
4949
// -dyld_opcodes

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,6 +3660,7 @@ static void parseOtoolOptions(const llvm::opt::InputArgList &InputArgs) {
36603660
ArchName = InputArgs.getLastArgValue(OTOOL_arch).str();
36613661
if (!ArchName.empty())
36623662
ArchFlags.push_back(ArchName);
3663+
ArchiveHeaders = InputArgs.hasArg(OTOOL_a);
36633664
LinkOptHints = InputArgs.hasArg(OTOOL_C);
36643665
if (InputArgs.hasArg(OTOOL_d))
36653666
FilterSections.push_back("__DATA,__data");

0 commit comments

Comments
 (0)