llvm.org GIT mirror llvm / 37598b6
Adds the next bit of support for llvm-objdump’s -private-headers for executable Mach-O files. This adds the printing of more load commands, so that the normal load commands in a typical X86 Mach-O executable can all be printed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217172 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 6 years ago
9 changed file(s) with 597 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
250250 getVersionMinLoadCommand(const LoadCommandInfo &L) const;
251251 MachO::dylib_command
252252 getDylibIDLoadCommand(const LoadCommandInfo &L) const;
253 MachO::dyld_info_command
254 getDyldInfoLoadCommand(const LoadCommandInfo &L) const;
255 MachO::dylinker_command
256 getDylinkerCommand(const LoadCommandInfo &L) const;
257 MachO::uuid_command
258 getUuidCommand(const LoadCommandInfo &L) const;
259 MachO::source_version_command
260 getSourceVersionCommand(const LoadCommandInfo &L) const;
261 MachO::entry_point_command
262 getEntryPointCommand(const LoadCommandInfo &L) const;
253263
254264 MachO::any_relocation_info getRelocation(DataRefImpl Rel) const;
255265 MachO::data_in_code_entry getDice(DataRefImpl Rel) const;
846846 // LC_VERSION_MIN_IPHONEOS
847847 uint32_t cmdsize; // sizeof(struct version_min_command)
848848 uint32_t version; // X.Y.Z is encoded in nibbles xxxx.yy.zz
849 uint32_t reserved;
849 uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
850850 };
851851
852852 struct dyld_info_command {
11011101 sys::swapByteOrder(d.cmd);
11021102 sys::swapByteOrder(d.cmdsize);
11031103 sys::swapByteOrder(d.name);
1104 }
1105
1106 inline void swapStruct(uuid_command &u) {
1107 sys::swapByteOrder(u.cmd);
1108 sys::swapByteOrder(u.cmdsize);
1109 }
1110
1111 inline void swapStruct(source_version_command &s) {
1112 sys::swapByteOrder(s.cmd);
1113 sys::swapByteOrder(s.cmdsize);
1114 sys::swapByteOrder(s.version);
11041115 }
11051116
11061117 inline void swapStruct(entry_point_command &e) {
11721183 sys::swapByteOrder(C.cmd);
11731184 sys::swapByteOrder(C.cmdsize);
11741185 sys::swapByteOrder(C.version);
1175 sys::swapByteOrder(C.reserved);
1186 sys::swapByteOrder(C.sdk);
11761187 }
11771188
11781189 inline void swapStruct(data_in_code_entry &C) {
18601860 return getStruct(this, L.Ptr);
18611861 }
18621862
1863 MachO::dyld_info_command
1864 MachOObjectFile::getDyldInfoLoadCommand(const LoadCommandInfo &L) const {
1865 return getStruct(this, L.Ptr);
1866 }
1867
1868 MachO::dylinker_command
1869 MachOObjectFile::getDylinkerCommand(const LoadCommandInfo &L) const {
1870 return getStruct(this, L.Ptr);
1871 }
1872
1873 MachO::uuid_command
1874 MachOObjectFile::getUuidCommand(const LoadCommandInfo &L) const {
1875 return getStruct(this, L.Ptr);
1876 }
1877
1878 MachO::source_version_command
1879 MachOObjectFile::getSourceVersionCommand(const LoadCommandInfo &L) const {
1880 return getStruct(this, L.Ptr);
1881 }
1882
1883 MachO::entry_point_command
1884 MachOObjectFile::getEntryPointCommand(const LoadCommandInfo &L) const {
1885 return getStruct(this, L.Ptr);
1886 }
1887
18631888
18641889 MachO::any_relocation_info
18651890 MachOObjectFile::getRelocation(DataRefImpl Rel) const {
55 // CHECK: (('command', 37)
66 // CHECK: ('size', 16)
77 // CHECK: ('version, 6490119)
8 // CHECK: ('reserved, 0)
8 // CHECK: ('sdk, 0)
99 // CHECK: ),
55 // CHECK: (('command', 36)
66 // CHECK: ('size', 16)
77 // CHECK: ('version, 1639169)
8 // CHECK: ('reserved, 0)
8 // CHECK: ('sdk, 0)
99 // CHECK: ),
0 // RUN: llvm-objdump -p %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s
1 // RUN: llvm-objdump -p %p/Inputs/hello.exe.macho-x86_64 \
2 // RUN: | FileCheck %s -check-prefix=EXE
13
24 CHECK: Mach header
35 CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
9496 CHECK: nextrel 0
9597 CHECK: locreloff 0
9698 CHECK: nlocrel 0
99
100 EXE: Mach header
101 EXE: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
102 EXE: MH_MAGIC_64 X86_64 ALL LIB64 EXECUTE 16 1296 NOUNDEFS DYLDLINK TWOLEVEL PIE
103 EXE: Load command 0
104 EXE: cmd LC_SEGMENT_64
105 EXE: cmdsize 72
106 EXE: segname __PAGEZERO
107 EXE: vmaddr 0x0000000000000000
108 EXE: vmsize 0x0000000100000000
109 EXE: fileoff 0
110 EXE: filesize 0
111 EXE: maxprot ---
112 EXE: initprot ---
113 EXE: nsects 0
114 EXE: flags (none)
115 EXE: Load command 1
116 EXE: cmd LC_SEGMENT_64
117 EXE: cmdsize 552
118 EXE: segname __TEXT
119 EXE: vmaddr 0x0000000100000000
120 EXE: vmsize 0x0000000000001000
121 EXE: fileoff 0
122 EXE: filesize 4096
123 EXE: maxprot rwx
124 EXE: initprot r-x
125 EXE: nsects 6
126 EXE: flags (none)
127 EXE: Section
128 EXE: sectname __text
129 EXE: segname __TEXT
130 EXE: addr 0x0000000100000f30
131 EXE: size 0x000000000000003b
132 EXE: offset 3888
133 EXE: align 2^4 (16)
134 EXE: reloff 0
135 EXE: nreloc 0
136 EXE: type S_REGULAR
137 EXE: attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
138 EXE: reserved1 0
139 EXE: reserved2 0
140 EXE: Section
141 EXE: sectname __stubs
142 EXE: segname __TEXT
143 EXE: addr 0x0000000100000f6c
144 EXE: size 0x0000000000000006
145 EXE: offset 3948
146 EXE: align 2^1 (2)
147 EXE: reloff 0
148 EXE: nreloc 0
149 EXE: type S_SYMBOL_STUBS
150 EXE: attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
151 EXE: reserved1 0 (index into indirect symbol table)
152 EXE: reserved2 6 (size of stubs)
153 EXE: Section
154 EXE: sectname __stub_helper
155 EXE: segname __TEXT
156 EXE: addr 0x0000000100000f74
157 EXE: size 0x000000000000001a
158 EXE: offset 3956
159 EXE: align 2^2 (4)
160 EXE: reloff 0
161 EXE: nreloc 0
162 EXE: type S_REGULAR
163 EXE: attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
164 EXE: reserved1 0
165 EXE: reserved2 0
166 EXE: Section
167 EXE: sectname __cstring
168 EXE: segname __TEXT
169 EXE: addr 0x0000000100000f8e
170 EXE: size 0x000000000000000d
171 EXE: offset 3982
172 EXE: align 2^0 (1)
173 EXE: reloff 0
174 EXE: nreloc 0
175 EXE: type S_CSTRING_LITERALS
176 EXE: attributes (none)
177 EXE: reserved1 0
178 EXE: reserved2 0
179 EXE: Section
180 EXE: sectname __unwind_info
181 EXE: segname __TEXT
182 EXE: addr 0x0000000100000f9b
183 EXE: size 0x0000000000000048
184 EXE: offset 3995
185 EXE: align 2^0 (1)
186 EXE: reloff 0
187 EXE: nreloc 0
188 EXE: type S_REGULAR
189 EXE: attributes (none)
190 EXE: reserved1 0
191 EXE: reserved2 0
192 EXE: Section
193 EXE: sectname __eh_frame
194 EXE: segname __TEXT
195 EXE: addr 0x0000000100000fe8
196 EXE: size 0x0000000000000018
197 EXE: offset 4072
198 EXE: align 2^3 (8)
199 EXE: reloff 0
200 EXE: nreloc 0
201 EXE: type S_REGULAR
202 EXE: attributes (none)
203 EXE: reserved1 0
204 EXE: reserved2 0
205 EXE: Load command 2
206 EXE: cmd LC_SEGMENT_64
207 EXE: cmdsize 232
208 EXE: segname __DATA
209 EXE: vmaddr 0x0000000100001000
210 EXE: vmsize 0x0000000000001000
211 EXE: fileoff 4096
212 EXE: filesize 4096
213 EXE: maxprot rwx
214 EXE: initprot rw-
215 EXE: nsects 2
216 EXE: flags (none)
217 EXE: Section
218 EXE: sectname __nl_symbol_ptr
219 EXE: segname __DATA
220 EXE: addr 0x0000000100001000
221 EXE: size 0x0000000000000010
222 EXE: offset 4096
223 EXE: align 2^3 (8)
224 EXE: reloff 0
225 EXE: nreloc 0
226 EXE: type S_NON_LAZY_SYMBOL_POINTERS
227 EXE: attributes (none)
228 EXE: reserved1 1 (index into indirect symbol table)
229 EXE: reserved2 0
230 EXE: Section
231 EXE: sectname __la_symbol_ptr
232 EXE: segname __DATA
233 EXE: addr 0x0000000100001010
234 EXE: size 0x0000000000000008
235 EXE: offset 4112
236 EXE: align 2^3 (8)
237 EXE: reloff 0
238 EXE: nreloc 0
239 EXE: type S_LAZY_SYMBOL_POINTERS
240 EXE: attributes (none)
241 EXE: reserved1 3 (index into indirect symbol table)
242 EXE: reserved2 0
243 EXE: Load command 3
244 EXE: cmd LC_SEGMENT_64
245 EXE: cmdsize 72
246 EXE: segname __LINKEDIT
247 EXE: vmaddr 0x0000000100002000
248 EXE: vmsize 0x0000000000001000
249 EXE: fileoff 8192
250 EXE: filesize 304
251 EXE: maxprot rwx
252 EXE: initprot r--
253 EXE: nsects 0
254 EXE: flags (none)
255 EXE: Load command 4
256 EXE: cmd LC_DYLD_INFO_ONLY
257 EXE: cmdsize 48
258 EXE: rebase_off 8192
259 EXE: rebase_size 8
260 EXE: bind_off 8200
261 EXE: bind_size 24
262 EXE: weak_bind_off 0
263 EXE: weak_bind_size 0
264 EXE: lazy_bind_off 8224
265 EXE: lazy_bind_size 16
266 EXE: export_off 8240
267 EXE: export_size 48
268 EXE: Load command 5
269 EXE: cmd LC_SYMTAB
270 EXE: cmdsize 24
271 EXE: symoff 8360
272 EXE: nsyms 4
273 EXE: stroff 8440
274 EXE: strsize 56
275 EXE: Load command 6
276 EXE: cmd LC_DYSYMTAB
277 EXE: cmdsize 80
278 EXE: ilocalsym 0
279 EXE: nlocalsym 0
280 EXE: iextdefsym 0
281 EXE: nextdefsym 2
282 EXE: iundefsym 2
283 EXE: nundefsym 2
284 EXE: tocoff 0
285 EXE: ntoc 0
286 EXE: modtaboff 0
287 EXE: nmodtab 0
288 EXE: extrefsymoff 0
289 EXE: nextrefsyms 0
290 EXE: indirectsymoff 8424
291 EXE: nindirectsyms 4
292 EXE: extreloff 0
293 EXE: nextrel 0
294 EXE: locreloff 0
295 EXE: nlocrel 0
296 EXE: Load command 7
297 EXE: cmd LC_LOAD_DYLINKER
298 EXE: cmdsize 32
299 EXE: name /usr/lib/dyld (offset 12)
300 EXE: Load command 8
301 EXE: cmd LC_UUID
302 EXE: cmdsize 24
303 EXE: uuid 65C2DD41-79B0-3B34-871B-8CB3446AB762
304 EXE: Load command 9
305 EXE: cmd LC_VERSION_MIN_MACOSX
306 EXE: cmdsize 16
307 EXE: version 10.9
308 EXE: sdk 10.9
309 EXE: Load command 10
310 EXE: cmd LC_SOURCE_VERSION
311 EXE: cmdsize 16
312 EXE: version 0.0
313 EXE: Load command 11
314 EXE: cmd LC_MAIN
315 EXE: cmdsize 24
316 EXE: entryoff 3888
317 EXE: stacksize 0
318 EXE: Load command 12
319 EXE: cmd LC_LOAD_DYLIB
320 EXE: cmdsize 56
321 EXE: name /usr/lib/libSystem.B.dylib (offset 24)
322 EXE: time stamp 2 Wed Dec 31 16:00:02 1969
323 EXE: current version 1197.1.1
324 EXE: compatibility version 1.0.0
325 EXE: Load command 13
326 EXE: cmd LC_FUNCTION_STARTS
327 EXE: cmdsize 16
328 EXE: dataoff 8288
329 EXE: datasize 8
330 EXE: Load command 14
331 EXE: cmd LC_DATA_IN_CODE
332 EXE: cmdsize 16
333 EXE: dataoff 8296
334 EXE: datasize 0
335 EXE: Load command 15
336 EXE: cmd LC_DYLIB_CODE_SIGN_DRS
337 EXE: cmdsize 16
338 EXE: dataoff 8296
339 EXE: datasize 64
11111111 break;
11121112 }
11131113 if ((cpusubtype & MachO::CPU_SUBTYPE_MASK) == MachO::CPU_SUBTYPE_LIB64) {
1114 outs() << " LIB64 ";
1114 outs() << " LIB64";
11151115 } else {
11161116 outs() << format(" 0x%02" PRIx32,
11171117 (cpusubtype & MachO::CPU_SUBTYPE_MASK) >> 24);
16951695 outs() << "\n";
16961696 }
16971697
1698 static void PrintDyldInfoLoadCommand(MachO::dyld_info_command dc,
1699 uint32_t object_size) {
1700 if (dc.cmd == MachO::LC_DYLD_INFO)
1701 outs() << " cmd LC_DYLD_INFO\n";
1702 else
1703 outs() << " cmd LC_DYLD_INFO_ONLY\n";
1704 outs() << " cmdsize " << dc.cmdsize;
1705 if (dc.cmdsize != sizeof(struct MachO::dyld_info_command))
1706 outs() << " Incorrect size\n";
1707 else
1708 outs() << "\n";
1709 outs() << " rebase_off " << dc.rebase_off;
1710 if (dc.rebase_off > object_size)
1711 outs() << " (past end of file)\n";
1712 else
1713 outs() << "\n";
1714 outs() << " rebase_size " << dc.rebase_size;
1715 uint64_t big_size;
1716 big_size = dc.rebase_off;
1717 big_size += dc.rebase_size;
1718 if (big_size > object_size)
1719 outs() << " (past end of file)\n";
1720 else
1721 outs() << "\n";
1722 outs() << " bind_off " << dc.bind_off;
1723 if (dc.bind_off > object_size)
1724 outs() << " (past end of file)\n";
1725 else
1726 outs() << "\n";
1727 outs() << " bind_size " << dc.bind_size;
1728 big_size = dc.bind_off;
1729 big_size += dc.bind_size;
1730 if (big_size > object_size)
1731 outs() << " (past end of file)\n";
1732 else
1733 outs() << "\n";
1734 outs() << " weak_bind_off " << dc.weak_bind_off;
1735 if (dc.weak_bind_off > object_size)
1736 outs() << " (past end of file)\n";
1737 else
1738 outs() << "\n";
1739 outs() << " weak_bind_size " << dc.weak_bind_size;
1740 big_size = dc.weak_bind_off;
1741 big_size += dc.weak_bind_size;
1742 if (big_size > object_size)
1743 outs() << " (past end of file)\n";
1744 else
1745 outs() << "\n";
1746 outs() << " lazy_bind_off " << dc.lazy_bind_off;
1747 if (dc.lazy_bind_off > object_size)
1748 outs() << " (past end of file)\n";
1749 else
1750 outs() << "\n";
1751 outs() << " lazy_bind_size " << dc.lazy_bind_size;
1752 big_size = dc.lazy_bind_off;
1753 big_size += dc.lazy_bind_size;
1754 if (big_size > object_size)
1755 outs() << " (past end of file)\n";
1756 else
1757 outs() << "\n";
1758 outs() << " export_off " << dc.export_off;
1759 if (dc.export_off > object_size)
1760 outs() << " (past end of file)\n";
1761 else
1762 outs() << "\n";
1763 outs() << " export_size " << dc.export_size;
1764 big_size = dc.export_off;
1765 big_size += dc.export_size;
1766 if (big_size > object_size)
1767 outs() << " (past end of file)\n";
1768 else
1769 outs() << "\n";
1770 }
1771
1772 static void PrintDyldLoadCommand(MachO::dylinker_command dyld,
1773 const char *Ptr) {
1774 if (dyld.cmd == MachO::LC_ID_DYLINKER)
1775 outs() << " cmd LC_ID_DYLINKER\n";
1776 else if (dyld.cmd == MachO::LC_LOAD_DYLINKER)
1777 outs() << " cmd LC_LOAD_DYLINKER\n";
1778 else if (dyld.cmd == MachO::LC_DYLD_ENVIRONMENT)
1779 outs() << " cmd LC_DYLD_ENVIRONMENT\n";
1780 else
1781 outs() << " cmd ?(" << dyld.cmd << ")\n";
1782 outs() << " cmdsize " << dyld.cmdsize;
1783 if (dyld.cmdsize < sizeof(struct MachO::dylinker_command))
1784 outs() << " Incorrect size\n";
1785 else
1786 outs() << "\n";
1787 if (dyld.name >= dyld.cmdsize)
1788 outs() << " name ?(bad offset " << dyld.name << ")\n";
1789 else {
1790 const char *P = (const char *)(Ptr)+dyld.name;
1791 outs() << " name " << P << " (offset " << dyld.name << ")\n";
1792 }
1793 }
1794
1795 static void PrintUuidLoadCommand(MachO::uuid_command uuid) {
1796 outs() << " cmd LC_UUID\n";
1797 outs() << " cmdsize " << uuid.cmdsize;
1798 if (uuid.cmdsize != sizeof(struct MachO::uuid_command))
1799 outs() << " Incorrect size\n";
1800 else
1801 outs() << "\n";
1802 outs() << " uuid ";
1803 outs() << format("%02" PRIX32, uuid.uuid[0]);
1804 outs() << format("%02" PRIX32, uuid.uuid[1]);
1805 outs() << format("%02" PRIX32, uuid.uuid[2]);
1806 outs() << format("%02" PRIX32, uuid.uuid[3]);
1807 outs() << "-";
1808 outs() << format("%02" PRIX32, uuid.uuid[4]);
1809 outs() << format("%02" PRIX32, uuid.uuid[5]);
1810 outs() << "-";
1811 outs() << format("%02" PRIX32, uuid.uuid[6]);
1812 outs() << format("%02" PRIX32, uuid.uuid[7]);
1813 outs() << "-";
1814 outs() << format("%02" PRIX32, uuid.uuid[8]);
1815 outs() << format("%02" PRIX32, uuid.uuid[9]);
1816 outs() << "-";
1817 outs() << format("%02" PRIX32, uuid.uuid[10]);
1818 outs() << format("%02" PRIX32, uuid.uuid[11]);
1819 outs() << format("%02" PRIX32, uuid.uuid[12]);
1820 outs() << format("%02" PRIX32, uuid.uuid[13]);
1821 outs() << format("%02" PRIX32, uuid.uuid[14]);
1822 outs() << format("%02" PRIX32, uuid.uuid[15]);
1823 outs() << "\n";
1824 }
1825
1826 static void PrintVersionMinLoadCommand(MachO::version_min_command vd) {
1827 if (vd.cmd == MachO::LC_VERSION_MIN_MACOSX)
1828 outs() << " cmd LC_VERSION_MIN_MACOSX\n";
1829 else if (vd.cmd == MachO::LC_VERSION_MIN_IPHONEOS)
1830 outs() << " cmd LC_VERSION_MIN_IPHONEOS\n";
1831 else
1832 outs() << " cmd " << vd.cmd << " (?)\n";
1833 outs() << " cmdsize " << vd.cmdsize;
1834 if (vd.cmdsize != sizeof(struct MachO::version_min_command))
1835 outs() << " Incorrect size\n";
1836 else
1837 outs() << "\n";
1838 outs() << " version " << ((vd.version >> 16) & 0xffff) << "."
1839 << ((vd.version >> 8) & 0xff);
1840 if ((vd.version & 0xff) != 0)
1841 outs() << "." << (vd.version & 0xff);
1842 outs() << "\n";
1843 if (vd.sdk == 0)
1844 outs() << " sdk n/a\n";
1845 else {
1846 outs() << " sdk " << ((vd.sdk >> 16) & 0xffff) << "."
1847 << ((vd.sdk >> 8) & 0xff);
1848 }
1849 if ((vd.sdk & 0xff) != 0)
1850 outs() << "." << (vd.sdk & 0xff);
1851 outs() << "\n";
1852 }
1853
1854 static void PrintSourceVersionCommand(MachO::source_version_command sd) {
1855 outs() << " cmd LC_SOURCE_VERSION\n";
1856 outs() << " cmdsize " << sd.cmdsize;
1857 if (sd.cmdsize != sizeof(struct MachO::source_version_command))
1858 outs() << " Incorrect size\n";
1859 else
1860 outs() << "\n";
1861 uint64_t a = (sd.version >> 40) & 0xffffff;
1862 uint64_t b = (sd.version >> 30) & 0x3ff;
1863 uint64_t c = (sd.version >> 20) & 0x3ff;
1864 uint64_t d = (sd.version >> 10) & 0x3ff;
1865 uint64_t e = sd.version & 0x3ff;
1866 outs() << " version " << a << "." << b;
1867 if (e != 0)
1868 outs() << "." << c << "." << d << "." << e;
1869 else if (d != 0)
1870 outs() << "." << c << "." << d;
1871 else if (c != 0)
1872 outs() << "." << c;
1873 outs() << "\n";
1874 }
1875
1876 static void PrintEntryPointCommand(MachO::entry_point_command ep) {
1877 outs() << " cmd LC_MAIN\n";
1878 outs() << " cmdsize " << ep.cmdsize;
1879 if (ep.cmdsize != sizeof(struct MachO::entry_point_command))
1880 outs() << " Incorrect size\n";
1881 else
1882 outs() << "\n";
1883 outs() << " entryoff " << ep.entryoff << "\n";
1884 outs() << " stacksize " << ep.stacksize << "\n";
1885 }
1886
1887 static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) {
1888 if (dl.cmd == MachO::LC_ID_DYLIB)
1889 outs() << " cmd LC_ID_DYLIB\n";
1890 else if (dl.cmd == MachO::LC_LOAD_DYLIB)
1891 outs() << " cmd LC_LOAD_DYLIB\n";
1892 else if (dl.cmd == MachO::LC_LOAD_WEAK_DYLIB)
1893 outs() << " cmd LC_LOAD_WEAK_DYLIB\n";
1894 else if (dl.cmd == MachO::LC_REEXPORT_DYLIB)
1895 outs() << " cmd LC_REEXPORT_DYLIB\n";
1896 else if (dl.cmd == MachO::LC_LAZY_LOAD_DYLIB)
1897 outs() << " cmd LC_LAZY_LOAD_DYLIB\n";
1898 else if (dl.cmd == MachO::LC_LOAD_UPWARD_DYLIB)
1899 outs() << " cmd LC_LOAD_UPWARD_DYLIB\n";
1900 else
1901 outs() << " cmd " << dl.cmd << " (unknown)\n";
1902 outs() << " cmdsize " << dl.cmdsize;
1903 if (dl.cmdsize < sizeof(struct MachO::dylib_command))
1904 outs() << " Incorrect size\n";
1905 else
1906 outs() << "\n";
1907 if (dl.dylib.name < dl.cmdsize) {
1908 const char *P = (const char *)(Ptr)+dl.dylib.name;
1909 outs() << " name " << P << " (offset " << dl.dylib.name << ")\n";
1910 } else {
1911 outs() << " name ?(bad offset " << dl.dylib.name << ")\n";
1912 }
1913 outs() << " time stamp " << dl.dylib.timestamp << " ";
1914 time_t t = dl.dylib.timestamp;
1915 outs() << ctime(&t);
1916 outs() << " current version ";
1917 if (dl.dylib.current_version == 0xffffffff)
1918 outs() << "n/a\n";
1919 else
1920 outs() << ((dl.dylib.current_version >> 16) & 0xffff) << "."
1921 << ((dl.dylib.current_version >> 8) & 0xff) << "."
1922 << (dl.dylib.current_version & 0xff) << "\n";
1923 outs() << "compatibility version ";
1924 if (dl.dylib.compatibility_version == 0xffffffff)
1925 outs() << "n/a\n";
1926 else
1927 outs() << ((dl.dylib.compatibility_version >> 16) & 0xffff) << "."
1928 << ((dl.dylib.compatibility_version >> 8) & 0xff) << "."
1929 << (dl.dylib.compatibility_version & 0xff) << "\n";
1930 }
1931
1932 static void PrintLinkEditDataCommand(MachO::linkedit_data_command ld,
1933 uint32_t object_size) {
1934 if (ld.cmd == MachO::LC_CODE_SIGNATURE)
1935 outs() << " cmd LC_FUNCTION_STARTS\n";
1936 else if (ld.cmd == MachO::LC_SEGMENT_SPLIT_INFO)
1937 outs() << " cmd LC_SEGMENT_SPLIT_INFO\n";
1938 else if (ld.cmd == MachO::LC_FUNCTION_STARTS)
1939 outs() << " cmd LC_FUNCTION_STARTS\n";
1940 else if (ld.cmd == MachO::LC_DATA_IN_CODE)
1941 outs() << " cmd LC_DATA_IN_CODE\n";
1942 else if (ld.cmd == MachO::LC_DYLIB_CODE_SIGN_DRS)
1943 outs() << " cmd LC_DYLIB_CODE_SIGN_DRS\n";
1944 else if (ld.cmd == MachO::LC_LINKER_OPTIMIZATION_HINT)
1945 outs() << " cmd LC_LINKER_OPTIMIZATION_HINT\n";
1946 else
1947 outs() << " cmd " << ld.cmd << " (?)\n";
1948 outs() << " cmdsize " << ld.cmdsize;
1949 if (ld.cmdsize != sizeof(struct MachO::linkedit_data_command))
1950 outs() << " Incorrect size\n";
1951 else
1952 outs() << "\n";
1953 outs() << " dataoff " << ld.dataoff;
1954 if (ld.dataoff > object_size)
1955 outs() << " (past end of file)\n";
1956 else
1957 outs() << "\n";
1958 outs() << " datasize " << ld.datasize;
1959 uint64_t big_size = ld.dataoff;
1960 big_size += ld.datasize;
1961 if (big_size > object_size)
1962 outs() << " (past end of file)\n";
1963 else
1964 outs() << "\n";
1965 }
1966
16981967 static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds,
16991968 uint32_t filetype, uint32_t cputype,
17001969 bool verbose) {
17362005 MachO::dysymtab_command Dysymtab = Obj->getDysymtabLoadCommand();
17372006 MachO::symtab_command Symtab = Obj->getSymtabLoadCommand();
17382007 PrintDysymtabLoadCommand(Dysymtab, Symtab.nsyms, Buf.size(), cputype);
2008 } else if (Command.C.cmd == MachO::LC_DYLD_INFO ||
2009 Command.C.cmd == MachO::LC_DYLD_INFO_ONLY) {
2010 MachO::dyld_info_command DyldInfo = Obj->getDyldInfoLoadCommand(Command);
2011 PrintDyldInfoLoadCommand(DyldInfo, Buf.size());
2012 } else if (Command.C.cmd == MachO::LC_LOAD_DYLINKER ||
2013 Command.C.cmd == MachO::LC_ID_DYLINKER ||
2014 Command.C.cmd == MachO::LC_DYLD_ENVIRONMENT) {
2015 MachO::dylinker_command Dyld = Obj->getDylinkerCommand(Command);
2016 PrintDyldLoadCommand(Dyld, Command.Ptr);
2017 } else if (Command.C.cmd == MachO::LC_UUID) {
2018 MachO::uuid_command Uuid = Obj->getUuidCommand(Command);
2019 PrintUuidLoadCommand(Uuid);
2020 } else if (Command.C.cmd == MachO::LC_VERSION_MIN_MACOSX) {
2021 MachO::version_min_command Vd = Obj->getVersionMinLoadCommand(Command);
2022 PrintVersionMinLoadCommand(Vd);
2023 } else if (Command.C.cmd == MachO::LC_SOURCE_VERSION) {
2024 MachO::source_version_command Sd = Obj->getSourceVersionCommand(Command);
2025 PrintSourceVersionCommand(Sd);
2026 } else if (Command.C.cmd == MachO::LC_MAIN) {
2027 MachO::entry_point_command Ep = Obj->getEntryPointCommand(Command);
2028 PrintEntryPointCommand(Ep);
2029 } else if (Command.C.cmd == MachO::LC_LOAD_DYLIB) {
2030 MachO::dylib_command Dl = Obj->getDylibIDLoadCommand(Command);
2031 PrintDylibCommand(Dl, Command.Ptr);
2032 } else if (Command.C.cmd == MachO::LC_CODE_SIGNATURE ||
2033 Command.C.cmd == MachO::LC_SEGMENT_SPLIT_INFO ||
2034 Command.C.cmd == MachO::LC_FUNCTION_STARTS ||
2035 Command.C.cmd == MachO::LC_DATA_IN_CODE ||
2036 Command.C.cmd == MachO::LC_DYLIB_CODE_SIGN_DRS ||
2037 Command.C.cmd == MachO::LC_LINKER_OPTIMIZATION_HINT) {
2038 MachO::linkedit_data_command Ld =
2039 Obj->getLinkeditDataLoadCommand(Command);
2040 PrintLinkEditDataCommand(Ld, Buf.size());
17392041 } else {
17402042 outs() << " cmd ?(" << format("0x%08" PRIx32, Command.C.cmd)
17412043 << ")\n";
323323 const MachOObjectFile::LoadCommandInfo &LCI) {
324324 MachO::version_min_command VMLC = Obj.getVersionMinLoadCommand(LCI);
325325 outs() << " ('version, " << VMLC.version << ")\n"
326 << " ('reserved, " << VMLC.reserved << ")\n";
326 << " ('sdk, " << VMLC.sdk << ")\n";
327327 return 0;
328328 }
329329