llvm.org GIT mirror llvm / 206b84f
Add mach-o LC_RPATH support to llvm-objdump Summary: Add rpath load command support in Mach-O object and update llvm-objdump to use it. Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6512 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223343 91177308-0d34-0410-b5e6-96231b3b80d8 Jean-Daniel Dupas 5 years ago
5 changed file(s) with 39 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
359359 getDylinkerCommand(const LoadCommandInfo &L) const;
360360 MachO::uuid_command
361361 getUuidCommand(const LoadCommandInfo &L) const;
362 MachO::rpath_command
363 getRpathCommand(const LoadCommandInfo &L) const;
362364 MachO::source_version_command
363365 getSourceVersionCommand(const LoadCommandInfo &L) const;
364366 MachO::entry_point_command
11081108 sys::swapByteOrder(u.cmdsize);
11091109 }
11101110
1111 inline void swapStruct(rpath_command &r) {
1112 sys::swapByteOrder(r.cmd);
1113 sys::swapByteOrder(r.cmdsize);
1114 sys::swapByteOrder(r.path);
1115 }
1116
11111117 inline void swapStruct(source_version_command &s) {
11121118 sys::swapByteOrder(s.cmd);
11131119 sys::swapByteOrder(s.cmdsize);
22982298 return getStruct(this, L.Ptr);
22992299 }
23002300
2301 MachO::rpath_command
2302 MachOObjectFile::getRpathCommand(const LoadCommandInfo &L) const {
2303 return getStruct(this, L.Ptr);
2304 }
2305
23012306 MachO::source_version_command
23022307 MachOObjectFile::getSourceVersionCommand(const LoadCommandInfo &L) const {
23032308 return getStruct(this, L.Ptr);
11 RUN: | FileCheck %s -check-prefix ELF-i386
22 RUN: llvm-objdump -p %p/Inputs/program-headers.elf-x86-64 \
33 RUN: | FileCheck %s -check-prefix ELF-x86-64
4 RUN: llvm-objdump -p %p/Inputs/macho-rpath-x86_64 \
5 RUN: | FileCheck %s -check-prefix MACHO-x86_64
46
57 ELF-i386: Program Header:
68 ELF-i386: LOAD off 0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12
1517 ELF-x86-64: filesz 0x0000000000000014 memsz 0x0000000000000014 flags r--
1618 ELF-x86-64: STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**3
1719 ELF-x86-64: filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
20
21 MACHO-x86_64: Load command 12
22 MACHO-x86_64: cmd LC_RPATH
23 MACHO-x86_64: cmdsize 32
24 MACHO-x86_64: path @executable_path/. (offset 12)
32983298 outs() << "\n";
32993299 }
33003300
3301 static void PrintRpathLoadCommand(MachO::rpath_command rpath,
3302 const char *Ptr) {
3303 outs() << " cmd LC_RPATH\n";
3304 outs() << " cmdsize " << rpath.cmdsize;
3305 if (rpath.cmdsize < sizeof(struct MachO::rpath_command))
3306 outs() << " Incorrect size\n";
3307 else
3308 outs() << "\n";
3309 if (rpath.path >= rpath.cmdsize)
3310 outs() << " path ?(bad offset " << rpath.path << ")\n";
3311 else {
3312 const char *P = (const char *)(Ptr) + rpath.path;
3313 outs() << " path " << P << " (offset " << rpath.path << ")\n";
3314 }
3315 }
3316
33013317 static void PrintVersionMinLoadCommand(MachO::version_min_command vd) {
33023318 if (vd.cmd == MachO::LC_VERSION_MIN_MACOSX)
33033319 outs() << " cmd LC_VERSION_MIN_MACOSX\n";
34933509 } else if (Command.C.cmd == MachO::LC_UUID) {
34943510 MachO::uuid_command Uuid = Obj->getUuidCommand(Command);
34953511 PrintUuidLoadCommand(Uuid);
3512 } else if (Command.C.cmd == MachO::LC_RPATH) {
3513 MachO::rpath_command Rpath = Obj->getRpathCommand(Command);
3514 PrintRpathLoadCommand(Rpath, Command.Ptr);
34963515 } else if (Command.C.cmd == MachO::LC_VERSION_MIN_MACOSX) {
34973516 MachO::version_min_command Vd = Obj->getVersionMinLoadCommand(Command);
34983517 PrintVersionMinLoadCommand(Vd);