From a42da31d2c31923ff2d3a0b4629c1b8bc6034c5b Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Thu, 18 Dec 2014 19:24:35 +0000 Subject: [PATCH] =?UTF-8?q?Add=20printing=20the=20LC=5FSUB=5FFRAMEWORK=20l?= =?UTF-8?q?oad=20command=20with=20llvm-objdump=E2=80=99s=20-private-header?= =?UTF-8?q?s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224534 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 2 ++ include/llvm/Support/MachO.h | 6 ++++++ lib/Object/MachOObjectFile.cpp | 4 ++++ .../X86/Inputs/dylibSubFramework.macho-x86_64 | Bin 0 -> 4240 bytes .../X86/macho-private-headers.test | 7 +++++++ tools/llvm-objdump/MachODump.cpp | 19 ++++++++++++++++++ 6 files changed, 38 insertions(+) create mode 100755 test/tools/llvm-objdump/X86/Inputs/dylibSubFramework.macho-x86_64 diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 19558a3c34b..2cab6c49898 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -368,6 +368,8 @@ public: getEncryptionInfoCommand(const LoadCommandInfo &L) const; MachO::encryption_info_command_64 getEncryptionInfoCommand64(const LoadCommandInfo &L) const; + MachO::sub_framework_command + getSubFrameworkCommand(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 342bdd569ff..1cb42991e1a 100644 --- a/include/llvm/Support/MachO.h +++ b/include/llvm/Support/MachO.h @@ -1107,6 +1107,12 @@ namespace llvm { sys::swapByteOrder(d.dylib.compatibility_version); } + inline void swapStruct(sub_framework_command &s) { + sys::swapByteOrder(s.cmd); + sys::swapByteOrder(s.cmdsize); + sys::swapByteOrder(s.umbrella); + }; + 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 5bc1110823c..a5031f17939 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -2309,6 +2309,10 @@ MachOObjectFile::getEncryptionInfoCommand64(const LoadCommandInfo &L) const { return getStruct(this, L.Ptr); } +MachO::sub_framework_command +MachOObjectFile::getSubFrameworkCommand(const LoadCommandInfo &L) const { + return getStruct(this, L.Ptr); +} MachO::any_relocation_info MachOObjectFile::getRelocation(DataRefImpl Rel) const { diff --git a/test/tools/llvm-objdump/X86/Inputs/dylibSubFramework.macho-x86_64 b/test/tools/llvm-objdump/X86/Inputs/dylibSubFramework.macho-x86_64 new file mode 100755 index 0000000000000000000000000000000000000000..3036c27f52cf06bb31831796bbad51f67af6eed3 GIT binary patch literal 4240 zcmeHKu}U0K6uqNHmvs{du`n1gNC+`8YYLGCQv^{_j3Gn=HuBib&az9gJ1{$otCfv~ z*i09{zz;~1DwQ8#V;xLknIEtSo-^-_j#Ee)yLaKt+;iW1_uW0S%{jgN`)@$R=@pTF z;1M7o`{FW_$3V#uQEFpxb0aR@e&}sCHN(+U9sumiP%8Agq0TkG-7gx_Yn*{W-ltRj z?32ATRjSk4ZnUbZ(W?1a$j*0U`YoG7FI@RzjM=X)SM$vep{wh zOsO01R_guAhtzK(~;N&xRo*Q-0<8kO}@v;3v* zzwVZ1)$EMOgvj2T>n?XBn1iEG8{V-A!n}(&`5^ESNC)RgkgoqvK88)~J8>LN9j?s{ z|M>YQIL)7(KSPakNIoCqWx`oQ6o3-Iv-&&!!r#M@=}tSCh7`p5PCN9P#ra|^4mKi& z0rutj`Enr74R=w@A)hpSG`?KqRf@kuZo?{I6|f3e1*`&A0jq#jz$#!BunOFl0-u); zF1Ajhi2mw{xg`Cj_n|k2#f$OX_)>EE(E>b?d*c+H5!4vY?k91&uHzO4a&dEA#)7K( zzT|o(8fQsAMJ|6AXy4xgiR~Ogjay!r8m&6V8BAF(P;HC3FoctduQ$Fn=_OAkz86ld Os@h?vqAD=+ULaRlvty$G 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 2bbd340c51f..bbb90863fa8 100644 --- a/test/tools/llvm-objdump/X86/macho-private-headers.test +++ b/test/tools/llvm-objdump/X86/macho-private-headers.test @@ -5,6 +5,8 @@ // RUN: | FileCheck %s -check-prefix=LOAD // RUN: llvm-objdump -p %p/Inputs/linkerOption.macho-x86_64 \ // RUN: | FileCheck %s -check-prefix=LD_OPT +// RUN: llvm-objdump -p %p/Inputs/dylibSubFramework.macho-x86_64 \ +// RUN: | FileCheck %s -check-prefix=SUB_FRAME CHECK: Mach header CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags @@ -379,3 +381,8 @@ LD_OPT: cmdsize 40 LD_OPT: count 2 LD_OPT: string #1 -framework LD_OPT: string #2 Foundation + +SUB_FRAME: Load command 10 +SUB_FRAME: cmd LC_SUB_FRAMEWORK +SUB_FRAME: cmdsize 16 +SUB_FRAME: umbrella Bar (offset 12) diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 7446e3214fd..f5feeed3171 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -3674,6 +3674,22 @@ static void PrintLinkerOptionCommand(MachO::linker_option_command lo, << "\n"; } +static void PrintSubFrameworkCommand(MachO::sub_framework_command sub, + const char *Ptr) { + outs() << " cmd LC_SUB_FRAMEWORK\n"; + outs() << " cmdsize " << sub.cmdsize; + if (sub.cmdsize < sizeof(struct MachO::sub_framework_command)) + outs() << " Incorrect size\n"; + else + outs() << "\n"; + if (sub.umbrella < sub.cmdsize) { + const char *P = Ptr + sub.umbrella; + outs() << " umbrella " << P << " (offset " << sub.umbrella << ")\n"; + } else { + outs() << " umbrella ?(bad offset " << sub.umbrella << ")\n"; + } +} + static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) { if (dl.cmd == MachO::LC_ID_DYLIB) outs() << " cmd LC_ID_DYLIB\n"; @@ -3830,6 +3846,9 @@ static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds, } else if (Command.C.cmd == MachO::LC_LINKER_OPTION) { MachO::linker_option_command Lo = Obj->getLinkerOptionLoadCommand(Command); PrintLinkerOptionCommand(Lo, Command.Ptr); + } else if (Command.C.cmd == MachO::LC_SUB_FRAMEWORK) { + MachO::sub_framework_command Sf = Obj->getSubFrameworkCommand(Command); + PrintSubFrameworkCommand(Sf, 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 ||