Index: include/llvm/Object/MachO.h =================================================================== --- include/llvm/Object/MachO.h +++ include/llvm/Object/MachO.h @@ -360,6 +360,8 @@ getDylinkerCommand(const LoadCommandInfo &L) const; MachO::uuid_command getUuidCommand(const LoadCommandInfo &L) const; + MachO::rpath_command + getRpathCommand(const LoadCommandInfo &L) const; MachO::source_version_command getSourceVersionCommand(const LoadCommandInfo &L) const; MachO::entry_point_command Index: include/llvm/Support/MachO.h =================================================================== --- include/llvm/Support/MachO.h +++ include/llvm/Support/MachO.h @@ -1109,6 +1109,12 @@ sys::swapByteOrder(u.cmdsize); } + inline void swapStruct(rpath_command &r) { + sys::swapByteOrder(r.cmd); + sys::swapByteOrder(r.cmdsize); + sys::swapByteOrder(r.path); + } + inline void swapStruct(source_version_command &s) { sys::swapByteOrder(s.cmd); sys::swapByteOrder(s.cmdsize); Index: lib/Object/MachOObjectFile.cpp =================================================================== --- lib/Object/MachOObjectFile.cpp +++ lib/Object/MachOObjectFile.cpp @@ -2299,6 +2299,11 @@ return getStruct(this, L.Ptr); } +MachO::rpath_command +MachOObjectFile::getRpathCommand(const LoadCommandInfo &L) const { + return getStruct(this, L.Ptr); +} + MachO::source_version_command MachOObjectFile::getSourceVersionCommand(const LoadCommandInfo &L) const { return getStruct(this, L.Ptr); Index: test/Object/objdump-private-headers.test =================================================================== --- test/Object/objdump-private-headers.test +++ test/Object/objdump-private-headers.test @@ -2,6 +2,8 @@ RUN: | FileCheck %s -check-prefix ELF-i386 RUN: llvm-objdump -p %p/Inputs/program-headers.elf-x86-64 \ RUN: | FileCheck %s -check-prefix ELF-x86-64 +RUN: llvm-objdump -p %p/Inputs/macho-rpath-x86_64 \ +RUN: | FileCheck %s -check-prefix MACHO-x86_64 ELF-i386: Program Header: ELF-i386: LOAD off 0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12 @@ -16,3 +18,8 @@ ELF-x86-64: filesz 0x0000000000000014 memsz 0x0000000000000014 flags r-- ELF-x86-64: STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**3 ELF-x86-64: filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw- + +MACHO-x86_64: Load command 12 +MACHO-x86_64: cmd LC_RPATH +MACHO-x86_64: cmdsize 32 +MACHO-x86_64: path @executable_path/. (offset 12) Index: tools/llvm-objdump/MachODump.cpp =================================================================== --- tools/llvm-objdump/MachODump.cpp +++ tools/llvm-objdump/MachODump.cpp @@ -3299,6 +3299,22 @@ outs() << "\n"; } +static void PrintRpathLoadCommand(MachO::rpath_command rpath, + const char *Ptr) { + outs() << " cmd LC_RPATH\n"; + outs() << " cmdsize " << rpath.cmdsize; + if (rpath.cmdsize < sizeof(struct MachO::rpath_command)) + outs() << " Incorrect size\n"; + else + outs() << "\n"; + if (rpath.path >= rpath.cmdsize) + outs() << " path ?(bad offset " << rpath.path << ")\n"; + else { + const char *P = (const char *)(Ptr) + rpath.path; + outs() << " path " << P << " (offset " << rpath.path << ")\n"; + } +} + static void PrintVersionMinLoadCommand(MachO::version_min_command vd) { if (vd.cmd == MachO::LC_VERSION_MIN_MACOSX) outs() << " cmd LC_VERSION_MIN_MACOSX\n"; @@ -3494,6 +3510,9 @@ } else if (Command.C.cmd == MachO::LC_UUID) { MachO::uuid_command Uuid = Obj->getUuidCommand(Command); PrintUuidLoadCommand(Uuid); + } else if (Command.C.cmd == MachO::LC_RPATH) { + MachO::rpath_command Rpath = Obj->getRpathCommand(Command); + PrintRpathLoadCommand(Rpath, Command.Ptr); } else if (Command.C.cmd == MachO::LC_VERSION_MIN_MACOSX) { MachO::version_min_command Vd = Obj->getVersionMinLoadCommand(Command); PrintVersionMinLoadCommand(Vd);