forked from OSchip/llvm-project
[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 llvm-svn: 321980
This commit is contained in:
parent
9f5859e3ee
commit
b3f802265e
|
@ -0,0 +1,26 @@
|
||||||
|
# RUN: yaml2obj %s -o %t.o
|
||||||
|
# RUN: llvm-readobj -needed-libs %t.o | FileCheck %s
|
||||||
|
|
||||||
|
# CHECK: NeededLibraries [
|
||||||
|
# CHECK-NEXT: /usr/lib/libSystem.B.dylib
|
||||||
|
# CHECK-NEXT: ]
|
||||||
|
|
||||||
|
!mach-o
|
||||||
|
FileHeader:
|
||||||
|
magic: 0xFEEDFACF
|
||||||
|
cputype: 0x01000007
|
||||||
|
cpusubtype: 0x00000003
|
||||||
|
filetype: 0x00000001
|
||||||
|
ncmds: 1
|
||||||
|
sizeofcmds: 56
|
||||||
|
flags: 0x00002000
|
||||||
|
reserved: 0x00000000
|
||||||
|
LoadCommands:
|
||||||
|
- cmd: LC_LOAD_DYLIB
|
||||||
|
cmdsize: 56
|
||||||
|
dylib:
|
||||||
|
name: 24
|
||||||
|
timestamp: 2
|
||||||
|
current_version: 81985536
|
||||||
|
compatibility_version: 65536
|
||||||
|
PayloadString: /usr/lib/libSystem.B.dylib
|
|
@ -39,6 +39,8 @@ public:
|
||||||
void printUnwindInfo() override;
|
void printUnwindInfo() override;
|
||||||
void printStackMap() const override;
|
void printStackMap() const override;
|
||||||
|
|
||||||
|
void printNeededLibraries() override;
|
||||||
|
|
||||||
// MachO-specific.
|
// MachO-specific.
|
||||||
void printMachODataInCode() override;
|
void printMachODataInCode() override;
|
||||||
void printMachOVersionMin() override;
|
void printMachOVersionMin() override;
|
||||||
|
@ -675,6 +677,34 @@ void MachODumper::printStackMap() const {
|
||||||
StackMapV2Parser<support::big>(StackMapContentsArray));
|
StackMapV2Parser<support::big>(StackMapContentsArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MachODumper::printNeededLibraries() {
|
||||||
|
ListScope D(W, "NeededLibraries");
|
||||||
|
|
||||||
|
using LibsTy = std::vector<StringRef>;
|
||||||
|
LibsTy Libs;
|
||||||
|
|
||||||
|
for (const auto &Command : Obj->load_commands()) {
|
||||||
|
if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
|
||||||
|
Command.C.cmd == MachO::LC_ID_DYLIB ||
|
||||||
|
Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
|
||||||
|
Command.C.cmd == MachO::LC_REEXPORT_DYLIB ||
|
||||||
|
Command.C.cmd == MachO::LC_LAZY_LOAD_DYLIB ||
|
||||||
|
Command.C.cmd == MachO::LC_LOAD_UPWARD_DYLIB) {
|
||||||
|
MachO::dylib_command Dl = Obj->getDylibIDLoadCommand(Command);
|
||||||
|
if (Dl.dylib.name < Dl.cmdsize) {
|
||||||
|
auto *P = static_cast<const char*>(Command.Ptr) + Dl.dylib.name;
|
||||||
|
Libs.push_back(P);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stable_sort(Libs.begin(), Libs.end());
|
||||||
|
|
||||||
|
for (const auto &L : Libs) {
|
||||||
|
outs() << " " << L << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MachODumper::printMachODataInCode() {
|
void MachODumper::printMachODataInCode() {
|
||||||
for (const auto &Load : Obj->load_commands()) {
|
for (const auto &Load : Obj->load_commands()) {
|
||||||
if (Load.C.cmd == MachO::LC_DATA_IN_CODE) {
|
if (Load.C.cmd == MachO::LC_DATA_IN_CODE) {
|
||||||
|
|
Loading…
Reference in New Issue