llvm.org GIT mirror llvm / d0ae994
Merging r321980: ------------------------------------------------------------------------ r321980 | phosek | 2018-01-07 18:23:10 -0800 (Sun, 07 Jan 2018) | 5 lines [llvm-readobj] Support -needed-libs option for Mach-O files This implements the -needed-libs option in Mach-O dumper. Differential Revision: https://reviews.llvm.org/D41527 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@322561 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 2 years ago
2 changed file(s) with 56 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 # RUN: yaml2obj %s -o %t.o
1 # RUN: llvm-readobj -needed-libs %t.o | FileCheck %s
2
3 # CHECK: NeededLibraries [
4 # CHECK-NEXT: /usr/lib/libSystem.B.dylib
5 # CHECK-NEXT: ]
6
7 !mach-o
8 FileHeader:
9 magic: 0xFEEDFACF
10 cputype: 0x01000007
11 cpusubtype: 0x00000003
12 filetype: 0x00000001
13 ncmds: 1
14 sizeofcmds: 56
15 flags: 0x00002000
16 reserved: 0x00000000
17 LoadCommands:
18 - cmd: LC_LOAD_DYLIB
19 cmdsize: 56
20 dylib:
21 name: 24
22 timestamp: 2
23 current_version: 81985536
24 compatibility_version: 65536
25 PayloadString: /usr/lib/libSystem.B.dylib
3737 void printDynamicSymbols() override;
3838 void printUnwindInfo() override;
3939 void printStackMap() const override;
40
41 void printNeededLibraries() override;
4042
4143 // MachO-specific.
4244 void printMachODataInCode() override;
674676 StackMapV2Parser(StackMapContentsArray));
675677 }
676678
679 void MachODumper::printNeededLibraries() {
680 ListScope D(W, "NeededLibraries");
681
682 using LibsTy = std::vector;
683 LibsTy Libs;
684
685 for (const auto &Command : Obj->load_commands()) {
686 if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
687 Command.C.cmd == MachO::LC_ID_DYLIB ||
688 Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
689 Command.C.cmd == MachO::LC_REEXPORT_DYLIB ||
690 Command.C.cmd == MachO::LC_LAZY_LOAD_DYLIB ||
691 Command.C.cmd == MachO::LC_LOAD_UPWARD_DYLIB) {
692 MachO::dylib_command Dl = Obj->getDylibIDLoadCommand(Command);
693 if (Dl.dylib.name < Dl.cmdsize) {
694 auto *P = static_cast(Command.Ptr) + Dl.dylib.name;
695 Libs.push_back(P);
696 }
697 }
698 }
699
700 std::stable_sort(Libs.begin(), Libs.end());
701
702 for (const auto &L : Libs) {
703 outs() << " " << L << "\n";
704 }
705 }
706
677707 void MachODumper::printMachODataInCode() {
678708 for (const auto &Load : Obj->load_commands()) {
679709 if (Load.C.cmd == MachO::LC_DATA_IN_CODE) {