summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Object/MachO.h2
-rw-r--r--llvm/include/llvm/Support/MachO.h6
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp5
-rwxr-xr-xllvm/test/tools/llvm-objdump/X86/Inputs/dylibSubLibrary.macho-x86_64bin0 -> 4220 bytes
-rw-r--r--llvm/test/tools/llvm-objdump/X86/macho-private-headers.test7
-rw-r--r--llvm/tools/llvm-objdump/MachODump.cpp20
6 files changed, 40 insertions, 0 deletions
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 494b62217f1..a869d4d4d00 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -372,6 +372,8 @@ public:
getSubFrameworkCommand(const LoadCommandInfo &L) const;
MachO::sub_umbrella_command
getSubUmbrellaCommand(const LoadCommandInfo &L) const;
+ MachO::sub_library_command
+ getSubLibraryCommand(const LoadCommandInfo &L) const;
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const;
MachO::data_in_code_entry getDice(DataRefImpl Rel) const;
diff --git a/llvm/include/llvm/Support/MachO.h b/llvm/include/llvm/Support/MachO.h
index 70b1e7f5c9d..d4320e5dd48 100644
--- a/llvm/include/llvm/Support/MachO.h
+++ b/llvm/include/llvm/Support/MachO.h
@@ -1119,6 +1119,12 @@ namespace llvm {
sys::swapByteOrder(s.sub_umbrella);
}
+ inline void swapStruct(sub_library_command &s) {
+ sys::swapByteOrder(s.cmd);
+ sys::swapByteOrder(s.cmdsize);
+ sys::swapByteOrder(s.sub_library);
+ }
+
inline void swapStruct(dylinker_command &d) {
sys::swapByteOrder(d.cmd);
sys::swapByteOrder(d.cmdsize);
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 92981fe6b7e..f1348b9e633 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -2322,6 +2322,11 @@ MachOObjectFile::getSubUmbrellaCommand(const LoadCommandInfo &L) const {
return getStruct<MachO::sub_umbrella_command>(this, L.Ptr);
}
+MachO::sub_library_command
+MachOObjectFile::getSubLibraryCommand(const LoadCommandInfo &L) const {
+ return getStruct<MachO::sub_library_command>(this, L.Ptr);
+}
+
MachO::any_relocation_info
MachOObjectFile::getRelocation(DataRefImpl Rel) const {
DataRefImpl Sec;
diff --git a/llvm/test/tools/llvm-objdump/X86/Inputs/dylibSubLibrary.macho-x86_64 b/llvm/test/tools/llvm-objdump/X86/Inputs/dylibSubLibrary.macho-x86_64
new file mode 100755
index 00000000000..dafee5f8db3
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/X86/Inputs/dylibSubLibrary.macho-x86_64
Binary files differ
diff --git a/llvm/test/tools/llvm-objdump/X86/macho-private-headers.test b/llvm/test/tools/llvm-objdump/X86/macho-private-headers.test
index c2023527bab..a650cc8e161 100644
--- a/llvm/test/tools/llvm-objdump/X86/macho-private-headers.test
+++ b/llvm/test/tools/llvm-objdump/X86/macho-private-headers.test
@@ -9,6 +9,8 @@
// RUN: | FileCheck %s -check-prefix=SUB_FRAME
// RUN: llvm-objdump -p %p/Inputs/dylibSubUmbrella.macho-x86_64 \
// RUN: | FileCheck %s -check-prefix=SUB_UMB
+// RUN: llvm-objdump -p %p/Inputs/dylibSubLibrary.macho-x86_64 \
+// RUN: | FileCheck %s -check-prefix=SUB_LIB
CHECK: Mach header
CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
@@ -393,3 +395,8 @@ SUB_UMB: Load command 5
SUB_UMB: cmd LC_SUB_UMBRELLA
SUB_UMB: cmdsize 16
SUB_UMB: sub_umbrella Foo (offset 12)
+
+SUB_LIB: Load command 5
+SUB_LIB: cmd LC_SUB_LIBRARY
+SUB_LIB: cmdsize 20
+SUB_LIB: sub_library libfoo (offset 12)
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index c2a825fa8b9..577cdcdf25a 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -3706,6 +3706,23 @@ static void PrintSubUmbrellaCommand(MachO::sub_umbrella_command sub,
}
}
+static void PrintSubLibraryCommand(MachO::sub_library_command sub,
+ const char *Ptr) {
+ outs() << " cmd LC_SUB_LIBRARY\n";
+ outs() << " cmdsize " << sub.cmdsize;
+ if (sub.cmdsize < sizeof(struct MachO::sub_library_command))
+ outs() << " Incorrect size\n";
+ else
+ outs() << "\n";
+ if (sub.sub_library < sub.cmdsize) {
+ const char *P = Ptr + sub.sub_library;
+ outs() << " sub_library " << P << " (offset " << sub.sub_library << ")\n";
+ } else {
+ outs() << " sub_library ?(bad offset " << sub.sub_library << ")\n";
+ }
+}
+
+
static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) {
if (dl.cmd == MachO::LC_ID_DYLIB)
outs() << " cmd LC_ID_DYLIB\n";
@@ -3868,6 +3885,9 @@ static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds,
} else if (Command.C.cmd == MachO::LC_SUB_UMBRELLA) {
MachO::sub_umbrella_command Sf = Obj->getSubUmbrellaCommand(Command);
PrintSubUmbrellaCommand(Sf, Command.Ptr);
+ } else if (Command.C.cmd == MachO::LC_SUB_LIBRARY) {
+ MachO::sub_library_command Sl = Obj->getSubLibraryCommand(Command);
+ PrintSubLibraryCommand(Sl, Command.Ptr);
} else if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
Command.C.cmd == MachO::LC_ID_DYLIB ||
Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
OpenPOWER on IntegriCloud