From 728b8cfc76e6cdce8a113bfb86effb162a4b014f Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Fri, 19 Dec 2014 21:06:24 +0000 Subject: [PATCH] =?utf8?q?Add=20printing=20the=20LC=5FSUB=5FCLIENT=20load?= =?utf8?q?=20command=20with=20llvm-objdump=E2=80=99s=20-private-headers.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224616 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 2 ++ include/llvm/Support/MachO.h | 6 ++++++ lib/Object/MachOObjectFile.cpp | 5 +++++ .../X86/Inputs/dylibSubClient.macho-x86_64 | Bin 0 -> 4240 bytes .../X86/macho-private-headers.test | 7 +++++++ tools/llvm-objdump/MachODump.cpp | 18 ++++++++++++++++++ 6 files changed, 38 insertions(+) create mode 100755 test/tools/llvm-objdump/X86/Inputs/dylibSubClient.macho-x86_64 diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index a869d4d4d00..f002352fcef 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -374,6 +374,8 @@ public: getSubUmbrellaCommand(const LoadCommandInfo &L) const; MachO::sub_library_command getSubLibraryCommand(const LoadCommandInfo &L) const; + MachO::sub_client_command + getSubClientCommand(const LoadCommandInfo &L) const; MachO::any_relocation_info getRelocation(DataRefImpl Rel) const; MachO::data_in_code_entry getDice(DataRefImpl Rel) const; diff --git a/include/llvm/Support/MachO.h b/include/llvm/Support/MachO.h index d4320e5dd48..ceb168582be 100644 --- a/include/llvm/Support/MachO.h +++ b/include/llvm/Support/MachO.h @@ -1125,6 +1125,12 @@ namespace llvm { sys::swapByteOrder(s.sub_library); } + inline void swapStruct(sub_client_command &s) { + sys::swapByteOrder(s.cmd); + sys::swapByteOrder(s.cmdsize); + sys::swapByteOrder(s.client); + } + inline void swapStruct(dylinker_command &d) { sys::swapByteOrder(d.cmd); sys::swapByteOrder(d.cmdsize); diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index f1348b9e633..b03c360d44c 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -2327,6 +2327,11 @@ MachOObjectFile::getSubLibraryCommand(const LoadCommandInfo &L) const { return getStruct(this, L.Ptr); } +MachO::sub_client_command +MachOObjectFile::getSubClientCommand(const LoadCommandInfo &L) const { + return getStruct(this, L.Ptr); +} + MachO::any_relocation_info MachOObjectFile::getRelocation(DataRefImpl Rel) const { DataRefImpl Sec; diff --git a/test/tools/llvm-objdump/X86/Inputs/dylibSubClient.macho-x86_64 b/test/tools/llvm-objdump/X86/Inputs/dylibSubClient.macho-x86_64 new file mode 100755 index 0000000000000000000000000000000000000000..e7f95428e2349be13cf921284d973406ec0c2c81 GIT binary patch literal 4240 zcmeHKJxd%>6g?9)F1m?RSQr!xK|;RJ1VXS#p+P}WB&Y!!eYor_F6b`o2U)EokRsi5 zTKX%3jg>#ZB7Ly23|L!)oHOr@J1z-YrFs|6ynF9^bMBkNH0SK<*Y92+=mKz`ct~8{ z1HK|;20S7r1HhQo*|pWAb@O45wR^56Cwd6+DvW7Ft%l8QeUmR9uzR|LLUp%I?Xw&E z+0vM1<#V}GH04UE%8kzZ9Xh@__mXOU)<46TXv>spn>&#`(#d!3_=X&V>h#+-0J}Pk{Z`N^T3z)o5uU z&NUXwTU=H56Ca6eXl{yZ|1SA34~ci7=ljy=-kVp)KcBH-5`iIB>pH zx%_CJ9w}@)#Xx>Y5$r7^XoW$T@69FTw#^MgABkKS;!(Bi6S(@BmwkUvq_%UAJspu9 rRZmu3*Xhq#F_zXAYh!??QeW?UZOVnmNaoVN7EQg;ESLh#d{o09|2AA% literal 0 HcmV?d00001 diff --git a/test/tools/llvm-objdump/X86/macho-private-headers.test b/test/tools/llvm-objdump/X86/macho-private-headers.test index a650cc8e161..2b26921d357 100644 --- a/test/tools/llvm-objdump/X86/macho-private-headers.test +++ b/test/tools/llvm-objdump/X86/macho-private-headers.test @@ -11,6 +11,8 @@ // RUN: | FileCheck %s -check-prefix=SUB_UMB // RUN: llvm-objdump -p %p/Inputs/dylibSubLibrary.macho-x86_64 \ // RUN: | FileCheck %s -check-prefix=SUB_LIB +// RUN: llvm-objdump -p %p/Inputs/dylibSubClient.macho-x86_64 \ +// RUN: | FileCheck %s -check-prefix=SUB_CLI CHECK: Mach header CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags @@ -400,3 +402,8 @@ SUB_LIB: Load command 5 SUB_LIB: cmd LC_SUB_LIBRARY SUB_LIB: cmdsize 20 SUB_LIB: sub_library libfoo (offset 12) + +SUB_CLI: Load command 10 +SUB_CLI: cmd LC_SUB_CLIENT +SUB_CLI: cmdsize 16 +SUB_CLI: client bar (offset 12) diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 577cdcdf25a..c84111115f2 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -3722,6 +3722,21 @@ static void PrintSubLibraryCommand(MachO::sub_library_command sub, } } +static void PrintSubClientCommand(MachO::sub_client_command sub, + const char *Ptr) { + outs() << " cmd LC_SUB_CLIENT\n"; + outs() << " cmdsize " << sub.cmdsize; + if (sub.cmdsize < sizeof(struct MachO::sub_client_command)) + outs() << " Incorrect size\n"; + else + outs() << "\n"; + if (sub.client < sub.cmdsize) { + const char *P = Ptr + sub.client; + outs() << " client " << P << " (offset " << sub.client << ")\n"; + } else { + outs() << " client ?(bad offset " << sub.client << ")\n"; + } +} static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) { if (dl.cmd == MachO::LC_ID_DYLIB) @@ -3888,6 +3903,9 @@ static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds, } 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_SUB_CLIENT) { + MachO::sub_client_command Sc = Obj->getSubClientCommand(Command); + PrintSubClientCommand(Sc, 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 || -- 2.34.1