llvm.org GIT mirror llvm / 793616c
[llvm-readobj] MachO -- dump LinkerOptions load command. Example output: Linker Options { Size: 32 Count: 2 Strings [ Value: -framework Value: Cocoa ] } There were only two tests using this -- so I converted them as part of this commit rather than separately. Differential Revision: http://reviews.llvm.org/D12702 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247106 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 5 years ago
5 changed file(s) with 63 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
None // RUN: llvm-mc -n -triple x86_64-apple-darwin10 %s -filetype=obj | macho-dump | FileCheck %s
1
2 // CHECK: ('load_commands_size', 120)
3 // CHECK: ('load_commands', [
4 // CHECK: # Load Command 2
5 // CHECK: (('command', 45)
6 // CHECK: ('size', 16)
7 // CHECK: ('count', 1)
8 // CHECK: ('_strings', [
9 // CHECK: "a",
10 // CHECK: ])
11 // CHECK: ),
12 // CHECK: # Load Command 3
13 // CHECK: (('command', 45)
14 // CHECK: ('size', 16)
15 // CHECK: ('count', 2)
16 // CHECK: ('_strings', [
17 // CHECK: "a",
18 // CHECK: "b",
19 // CHECK: ])
20 // CHECK: ),
21 // CHECK: ])
0 // RUN: llvm-mc -n -triple x86_64-apple-darwin10 %s -filetype=obj | llvm-readobj -macho-linker-options | FileCheck %s
221
232 .linker_option "a"
243 .linker_option "a", "b"
4
5 // CHECK: Linker Options {
6 // CHECK: Size: 16
7 // CHECK: Strings [
8 // CHECK: Value: a
9 // CHECK: ]
10 // CHECK: }
11 // CHECK: Linker Options {
12 // CHECK: Size: 16
13 // CHECK: Strings [
14 // CHECK: Value: a
15 // CHECK: Value: b
16 // CHECK: ]
17 // CHECK: }
33 ; CHECK-ASM: .linker_option "-lz"
44 ; CHECK-ASM-NEXT: .linker_option "-framework", "Cocoa"
55
6 ; RUN: llc -O0 -mtriple=x86_64-apple-darwin -filetype=obj -o - %s | macho-dump > %t
6 ; RUN: llc -O0 -mtriple=x86_64-apple-darwin -filetype=obj -o - %s | llvm-readobj -macho-linker-options > %t
77 ; RUN: FileCheck --check-prefix=CHECK-OBJ < %t %s
88
9 ; CHECK-OBJ: ('load_commands', [
10 ; CHECK-OBJ: # Load Command 1
11 ; CHECK-OBJ: (('command', 45)
12 ; CHECK-OBJ: ('size', 16)
13 ; CHECK-OBJ: ('count', 1)
14 ; CHECK-OBJ: ('_strings', [
15 ; CHECK-OBJ: "-lz",
16 ; CHECK-OBJ: ])
17 ; CHECK-OBJ: ),
18 ; CHECK-OBJ: # Load Command 2
19 ; CHECK-OBJ: (('command', 45)
20 ; CHECK-OBJ: ('size', 32)
21 ; CHECK-OBJ: ('count', 2)
22 ; CHECK-OBJ: ('_strings', [
23 ; CHECK-OBJ: "-framework",
24 ; CHECK-OBJ: "Cocoa",
25 ; CHECK-OBJ: ])
26 ; CHECK-OBJ: # Load Command 3
27 ; CHECK-OBJ: (('command', 45)
28 ; CHECK-OBJ: ('size', 24)
29 ; CHECK-OBJ: ('count', 1)
30 ; CHECK-OBJ: ('_strings', [
31 ; CHECK-OBJ: "-lmath",
32 ; CHECK-OBJ: ])
33 ; CHECK-OBJ: ),
34 ; CHECK-OBJ: ])
9 ; CHECK-OBJ: Linker Options {
10 ; CHECK-OBJ: Size: 16
11 ; CHECK-OBJ: Strings [
12 ; CHECK-OBJ: Value: -lz
13 ; CHECK-OBJ: ]
14 ; CHECK-OBJ: }
15 ; CHECK-OBJ: Linker Options {
16 ; CHECK-OBJ: Size: 32
17 ; CHECK-OBJ: Strings [
18 ; CHECK-OBJ: Value: -framework
19 ; CHECK-OBJ: Value: Cocoa
20 ; CHECK-OBJ: ]
21 ; CHECK-OBJ: }
22 ; CHECK-OBJ: Linker Options {
23 ; CHECK-OBJ: Size: 24
24 ; CHECK-OBJ: Strings [
25 ; CHECK-OBJ: Value: -lmath
26 ; CHECK-OBJ: ]
27 ; CHECK-OBJ: }
3528
3629 !0 = !{i32 6, !"Linker Options", !{!{!"-lz"}, !{!"-framework", !"Cocoa"}, !{!"-lmath"}}}
3730
4545 void printMachODysymtab() override;
4646 void printMachOSegment() override;
4747 void printMachOIndirectSymbols() override;
48 void printMachOLinkerOptions () override;
4849
4950 private:
5051 template
790791 }
791792 }
792793 }
794
795 void MachODumper::printMachOLinkerOptions() {
796 for (const auto &Load : Obj->load_commands()) {
797 if (Load.C.cmd == MachO::LC_LINKER_OPTION) {
798 MachO::linker_option_command LOLC = Obj->getLinkerOptionLoadCommand(Load);
799 DictScope Group(W, "Linker Options");
800 W.printNumber("Size", LOLC.cmdsize);
801 ListScope D(W, "Strings");
802 uint64_t DataSize = LOLC.cmdsize - sizeof(MachO::linker_option_command);
803 const char *P = Load.Ptr + sizeof(MachO::linker_option_command);
804 StringRef Data(P, DataSize);
805 for (unsigned i = 0; i < LOLC.count; ++i) {
806 std::pair Split = Data.split('\0');
807 W.printString("Value", Split.first);
808 Data = Split.second;
809 }
810 }
811 }
812 }
6060 virtual void printMachODysymtab() { }
6161 virtual void printMachOSegment() { }
6262 virtual void printMachOIndirectSymbols() { }
63 virtual void printMachOLinkerOptions() { }
6364
6465 virtual void printStackMap() const = 0;
6566
190190 cl::opt
191191 MachOIndirectSymbols("macho-indirect-symbols",
192192 cl::desc("Display MachO indirect symbols"));
193
194 // -macho-linker-options
195 cl::opt
196 MachOLinkerOptions("macho-linker-options",
197 cl::desc("Display MachO linker options"));
193198
194199 // -macho-segment
195200 cl::opt
342347 Dumper->printMachODataInCode();
343348 if (opts::MachOIndirectSymbols)
344349 Dumper->printMachOIndirectSymbols();
350 if (opts::MachOLinkerOptions)
351 Dumper->printMachOLinkerOptions();
345352 if (opts::MachOSegment)
346353 Dumper->printMachOSegment();
347354 if (opts::MachOVersionMin)