From 5ebdee51db184f910b6f8ecac0c7d674b7ae8f30 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Fri, 19 Dec 2014 22:25:22 +0000 Subject: [PATCH] =?utf8?q?Add=20printing=20the=20LC=5FROUTINES=20load=20co?= =?utf8?q?mmands=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@224627 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 4 ++ include/llvm/Support/MachO.h | 26 ++++++++++++ lib/Object/MachOObjectFile.cpp | 10 +++++ .../X86/Inputs/dylibRoutines.macho-x86_64 | Bin 0 -> 4288 bytes .../X86/macho-private-headers.test | 14 ++++++ tools/llvm-objdump/MachODump.cpp | 40 ++++++++++++++++++ 6 files changed, 94 insertions(+) create mode 100755 test/tools/llvm-objdump/X86/Inputs/dylibRoutines.macho-x86_64 diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index f002352fcef..eca7142c5f9 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -376,6 +376,10 @@ public: getSubLibraryCommand(const LoadCommandInfo &L) const; MachO::sub_client_command getSubClientCommand(const LoadCommandInfo &L) const; + MachO::routines_command + getRoutinesCommand(const LoadCommandInfo &L) const; + MachO::routines_command_64 + getRoutinesCommand64(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 ceb168582be..9fb6336ca43 100644 --- a/include/llvm/Support/MachO.h +++ b/include/llvm/Support/MachO.h @@ -1131,6 +1131,32 @@ namespace llvm { sys::swapByteOrder(s.client); } + inline void swapStruct(routines_command &r) { + sys::swapByteOrder(r.cmd); + sys::swapByteOrder(r.cmdsize); + sys::swapByteOrder(r.init_address); + sys::swapByteOrder(r.init_module); + sys::swapByteOrder(r.reserved1); + sys::swapByteOrder(r.reserved2); + sys::swapByteOrder(r.reserved3); + sys::swapByteOrder(r.reserved4); + sys::swapByteOrder(r.reserved5); + sys::swapByteOrder(r.reserved6); + } + + inline void swapStruct(routines_command_64 &r) { + sys::swapByteOrder(r.cmd); + sys::swapByteOrder(r.cmdsize); + sys::swapByteOrder(r.init_address); + sys::swapByteOrder(r.init_module); + sys::swapByteOrder(r.reserved1); + sys::swapByteOrder(r.reserved2); + sys::swapByteOrder(r.reserved3); + sys::swapByteOrder(r.reserved4); + sys::swapByteOrder(r.reserved5); + sys::swapByteOrder(r.reserved6); + } + 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 b03c360d44c..45439482ca2 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -2332,6 +2332,16 @@ MachOObjectFile::getSubClientCommand(const LoadCommandInfo &L) const { return getStruct(this, L.Ptr); } +MachO::routines_command +MachOObjectFile::getRoutinesCommand(const LoadCommandInfo &L) const { + return getStruct(this, L.Ptr); +} + +MachO::routines_command_64 +MachOObjectFile::getRoutinesCommand64(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/dylibRoutines.macho-x86_64 b/test/tools/llvm-objdump/X86/Inputs/dylibRoutines.macho-x86_64 new file mode 100755 index 0000000000000000000000000000000000000000..35680452a09904da9a5d66f75d73d3ad4eda442e GIT binary patch literal 4288 zcmeHLK}%Fo6h2QgMJJtwMp@(_5@Uf%D7a`5kuXw-n1UNQDDws%KB@FKw=;sf(Yit&=ktGo=sCxir-z+)uJN!x!hh9LZ|eO$+grPCG%{ zg{rOiRTNh>ifeTg^7ngh=2grl;vRQEE>;b9wbt0)3$sFg-VZZx&g>($Z_ABJA$jB3 zs?U~Jo-RFEw%l31a_g6Lmk4CK-hRe*0 e3wa74=cHB=<(<^t2|~B3&7`%XxMMYJ*uFCx1aVaW 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 2b26921d357..9f971d1c311 100644 --- a/test/tools/llvm-objdump/X86/macho-private-headers.test +++ b/test/tools/llvm-objdump/X86/macho-private-headers.test @@ -13,6 +13,8 @@ // RUN: | FileCheck %s -check-prefix=SUB_LIB // RUN: llvm-objdump -p %p/Inputs/dylibSubClient.macho-x86_64 \ // RUN: | FileCheck %s -check-prefix=SUB_CLI +// RUN: llvm-objdump -p %p/Inputs/dylibRoutines.macho-x86_64 \ +// RUN: | FileCheck %s -check-prefix=ROUTINE CHECK: Mach header CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags @@ -407,3 +409,15 @@ SUB_CLI: Load command 10 SUB_CLI: cmd LC_SUB_CLIENT SUB_CLI: cmdsize 16 SUB_CLI: client bar (offset 12) + +ROUTINE: Load command 6 +ROUTINE: cmd LC_ROUTINES_64 +ROUTINE: cmdsize 72 +ROUTINE: init_address 0x0000000000000f80 +ROUTINE: init_module 0 +ROUTINE: reserved1 0 +ROUTINE: reserved2 0 +ROUTINE: reserved3 0 +ROUTINE: reserved4 0 +ROUTINE: reserved5 0 +ROUTINE: reserved6 0 diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index c84111115f2..9f5216bffae 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -3738,6 +3738,40 @@ static void PrintSubClientCommand(MachO::sub_client_command sub, } } +static void PrintRoutinesCommand(MachO::routines_command r) { + outs() << " cmd LC_ROUTINES\n"; + outs() << " cmdsize " << r.cmdsize; + if (r.cmdsize != sizeof(struct MachO::routines_command)) + outs() << " Incorrect size\n"; + else + outs() << "\n"; + outs() << " init_address " << format("0x%08" PRIx32, r.init_address) << "\n"; + outs() << " init_module " << r.init_module << "\n"; + outs() << " reserved1 " << r.reserved1 << "\n"; + outs() << " reserved2 " << r.reserved2 << "\n"; + outs() << " reserved3 " << r.reserved3 << "\n"; + outs() << " reserved4 " << r.reserved4 << "\n"; + outs() << " reserved5 " << r.reserved5 << "\n"; + outs() << " reserved6 " << r.reserved6 << "\n"; +} + +static void PrintRoutinesCommand64(MachO::routines_command_64 r) { + outs() << " cmd LC_ROUTINES_64\n"; + outs() << " cmdsize " << r.cmdsize; + if (r.cmdsize != sizeof(struct MachO::routines_command_64)) + outs() << " Incorrect size\n"; + else + outs() << "\n"; + outs() << " init_address " << format("0x%016" PRIx64, r.init_address) << "\n"; + outs() << " init_module " << r.init_module << "\n"; + outs() << " reserved1 " << r.reserved1 << "\n"; + outs() << " reserved2 " << r.reserved2 << "\n"; + outs() << " reserved3 " << r.reserved3 << "\n"; + outs() << " reserved4 " << r.reserved4 << "\n"; + outs() << " reserved5 " << r.reserved5 << "\n"; + outs() << " reserved6 " << r.reserved6 << "\n"; +} + static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) { if (dl.cmd == MachO::LC_ID_DYLIB) outs() << " cmd LC_ID_DYLIB\n"; @@ -3906,6 +3940,12 @@ static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds, } 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_ROUTINES) { + MachO::routines_command Rc = Obj->getRoutinesCommand(Command); + PrintRoutinesCommand(Rc); + } else if (Command.C.cmd == MachO::LC_ROUTINES_64) { + MachO::routines_command_64 Rc = Obj->getRoutinesCommand64(Command); + PrintRoutinesCommand64(Rc); } 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