llvm.org GIT mirror llvm / e479df2
Add printing the LC_ENCRYPTION_INFO_64 load command with llvm-objdump’s -private-headers and add tests for the two AArch64 binaries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224400 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 5 years ago
5 changed file(s) with 364 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
365365 getEntryPointCommand(const LoadCommandInfo &L) const;
366366 MachO::encryption_info_command
367367 getEncryptionInfoCommand(const LoadCommandInfo &L) const;
368 MachO::encryption_info_command_64
369 getEncryptionInfoCommand64(const LoadCommandInfo &L) const;
368370
369371 MachO::any_relocation_info getRelocation(DataRefImpl Rel) const;
370372 MachO::data_in_code_entry getDice(DataRefImpl Rel) const;
129129 LC_DATA_IN_CODE = 0x00000029u,
130130 LC_SOURCE_VERSION = 0x0000002Au,
131131 LC_DYLIB_CODE_SIGN_DRS = 0x0000002Bu,
132 // 0x0000002Cu,
132 LC_ENCRYPTION_INFO_64 = 0x0000002Cu,
133133 LC_LINKER_OPTIONS = 0x0000002Du,
134134 LC_LINKER_OPTIMIZATION_HINT = 0x0000002Eu
135135 };
841841 uint32_t cryptid;
842842 };
843843
844 struct encryption_info_command_64 {
845 uint32_t cmd;
846 uint32_t cmdsize;
847 uint32_t cryptoff;
848 uint32_t cryptsize;
849 uint32_t cryptid;
850 uint32_t pad;
851 };
852
844853 struct version_min_command {
845854 uint32_t cmd; // LC_VERSION_MIN_MACOSX or
846855 // LC_VERSION_MIN_IPHONEOS
11331142 sys::swapByteOrder(e.cryptoff);
11341143 sys::swapByteOrder(e.cryptsize);
11351144 sys::swapByteOrder(e.cryptid);
1145 }
1146
1147 inline void swapStruct(encryption_info_command_64 &e) {
1148 sys::swapByteOrder(e.cmd);
1149 sys::swapByteOrder(e.cmdsize);
1150 sys::swapByteOrder(e.cryptoff);
1151 sys::swapByteOrder(e.cryptsize);
1152 sys::swapByteOrder(e.cryptid);
1153 sys::swapByteOrder(e.pad);
11361154 }
11371155
11381156 inline void swapStruct(dysymtab_command &dst) {
23032303 return getStruct(this, L.Ptr);
23042304 }
23052305
2306 MachO::encryption_info_command_64
2307 MachOObjectFile::getEncryptionInfoCommand64(const LoadCommandInfo &L) const {
2308 return getStruct(this, L.Ptr);
2309 }
2310
23062311
23072312 MachO::any_relocation_info
23082313 MachOObjectFile::getRelocation(DataRefImpl Rel) const {
0 // RUN: llvm-objdump -p %p/Inputs/hello.obj.macho-aarch64 | FileCheck %s
1 // RUN: llvm-objdump -p %p/Inputs/hello.exe.macho-aarch64 \
2 // RUN: | FileCheck %s -check-prefix=EXE
3
4 CHECK: Mach header
5 CHECK: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
6 CHECK: MH_MAGIC_64 ARM64 ALL 0x00 OBJECT 4 352 SUBSECTIONS_VIA_SYMBOLS
7 CHECK: Load command 0
8 CHECK: cmd LC_SEGMENT_64
9 CHECK: cmdsize 232
10 CHECK: segname
11 CHECK: vmaddr 0x0000000000000000
12 CHECK: vmsize 0x000000000000004d
13 CHECK: fileoff 384
14 CHECK: filesize 77
15 CHECK: maxprot rwx
16 CHECK: initprot rwx
17 CHECK: nsects 2
18 CHECK: flags (none)
19 CHECK: Section
20 CHECK: sectname __text
21 CHECK: segname __TEXT
22 CHECK: addr 0x0000000000000000
23 CHECK: size 0x0000000000000040
24 CHECK: offset 384
25 CHECK: align 2^2 (4)
26 CHECK: reloff 464
27 CHECK: nreloc 3
28 CHECK: type S_REGULAR
29 CHECK: attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
30 CHECK: reserved1 0
31 CHECK: reserved2 0
32 CHECK: Section
33 CHECK: sectname __cstring
34 CHECK: segname __TEXT
35 CHECK: addr 0x0000000000000040
36 CHECK: size 0x000000000000000d
37 CHECK: offset 448
38 CHECK: align 2^0 (1)
39 CHECK: reloff 0
40 CHECK: nreloc 0
41 CHECK: type S_CSTRING_LITERALS
42 CHECK: attributes (none)
43 CHECK: reserved1 0
44 CHECK: reserved2 0
45 CHECK: Load command 1
46 CHECK: cmd LC_VERSION_MIN_IPHONEOS
47 CHECK: cmdsize 16
48 CHECK: version 9.0
49 CHECK: sdk n/a
50 CHECK: Load command 2
51 CHECK: cmd LC_SYMTAB
52 CHECK: cmdsize 24
53 CHECK: symoff 488
54 CHECK: nsyms 5
55 CHECK: stroff 568
56 CHECK: strsize 36
57 CHECK: Load command 3
58 CHECK: cmd LC_DYSYMTAB
59 CHECK: cmdsize 80
60 CHECK: ilocalsym 0
61 CHECK: nlocalsym 3
62 CHECK: iextdefsym 3
63 CHECK: nextdefsym 1
64 CHECK: iundefsym 4
65 CHECK: nundefsym 1
66 CHECK: tocoff 0
67 CHECK: ntoc 0
68 CHECK: modtaboff 0
69 CHECK: nmodtab 0
70 CHECK: extrefsymoff 0
71 CHECK: nextrefsyms 0
72 CHECK: indirectsymoff 0
73 CHECK: nindirectsyms 0
74 CHECK: extreloff 0
75 CHECK: nextrel 0
76 CHECK: locreloff 0
77 CHECK: nlocrel 0
78
79 EXE: Mach header
80 EXE: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
81 EXE: MH_MAGIC_64 ARM64 ALL 0x00 EXECUTE 17 1240 NOUNDEFS DYLDLINK TWOLEVEL PIE
82 EXE: Load command 0
83 EXE: cmd LC_SEGMENT_64
84 EXE: cmdsize 72
85 EXE: segname __PAGEZERO
86 EXE: vmaddr 0x0000000000000000
87 EXE: vmsize 0x0000000100000000
88 EXE: fileoff 0
89 EXE: filesize 0
90 EXE: maxprot ---
91 EXE: initprot ---
92 EXE: nsects 0
93 EXE: flags (none)
94 EXE: Load command 1
95 EXE: cmd LC_SEGMENT_64
96 EXE: cmdsize 472
97 EXE: segname __TEXT
98 EXE: vmaddr 0x0000000100000000
99 EXE: vmsize 0x0000000000008000
100 EXE: fileoff 0
101 EXE: filesize 32768
102 EXE: maxprot r-x
103 EXE: initprot r-x
104 EXE: nsects 5
105 EXE: flags (none)
106 EXE: Section
107 EXE: sectname __text
108 EXE: segname __TEXT
109 EXE: addr 0x0000000100007f38
110 EXE: size 0x0000000000000040
111 EXE: offset 32568
112 EXE: align 2^2 (4)
113 EXE: reloff 0
114 EXE: nreloc 0
115 EXE: type S_REGULAR
116 EXE: attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
117 EXE: reserved1 0
118 EXE: reserved2 0
119 EXE: Section
120 EXE: sectname __stubs
121 EXE: segname __TEXT
122 EXE: addr 0x0000000100007f78
123 EXE: size 0x000000000000000c
124 EXE: offset 32632
125 EXE: align 2^1 (2)
126 EXE: reloff 0
127 EXE: nreloc 0
128 EXE: type S_SYMBOL_STUBS
129 EXE: attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
130 EXE: reserved1 0 (index into indirect symbol table)
131 EXE: reserved2 12 (size of stubs)
132 EXE: Section
133 EXE: sectname __stub_helper
134 EXE: segname __TEXT
135 EXE: addr 0x0000000100007f84
136 EXE: size 0x0000000000000024
137 EXE: offset 32644
138 EXE: align 2^2 (4)
139 EXE: reloff 0
140 EXE: nreloc 0
141 EXE: type S_REGULAR
142 EXE: attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
143 EXE: reserved1 0
144 EXE: reserved2 0
145 EXE: Section
146 EXE: sectname __cstring
147 EXE: segname __TEXT
148 EXE: addr 0x0000000100007fa8
149 EXE: size 0x000000000000000d
150 EXE: offset 32680
151 EXE: align 2^0 (1)
152 EXE: reloff 0
153 EXE: nreloc 0
154 EXE: type S_CSTRING_LITERALS
155 EXE: attributes (none)
156 EXE: reserved1 0
157 EXE: reserved2 0
158 EXE: Section
159 EXE: sectname __unwind_info
160 EXE: segname __TEXT
161 EXE: addr 0x0000000100007fb8
162 EXE: size 0x0000000000000048
163 EXE: offset 32696
164 EXE: align 2^2 (4)
165 EXE: reloff 0
166 EXE: nreloc 0
167 EXE: type S_REGULAR
168 EXE: attributes (none)
169 EXE: reserved1 0
170 EXE: reserved2 0
171 EXE: Load command 2
172 EXE: cmd LC_SEGMENT_64
173 EXE: cmdsize 232
174 EXE: segname __DATA
175 EXE: vmaddr 0x0000000100008000
176 EXE: vmsize 0x0000000000004000
177 EXE: fileoff 32768
178 EXE: filesize 16384
179 EXE: maxprot rw-
180 EXE: initprot rw-
181 EXE: nsects 2
182 EXE: flags (none)
183 EXE: Section
184 EXE: sectname __got
185 EXE: segname __DATA
186 EXE: addr 0x0000000100008000
187 EXE: size 0x0000000000000010
188 EXE: offset 32768
189 EXE: align 2^3 (8)
190 EXE: reloff 0
191 EXE: nreloc 0
192 EXE: type S_NON_LAZY_SYMBOL_POINTERS
193 EXE: attributes (none)
194 EXE: reserved1 1 (index into indirect symbol table)
195 EXE: reserved2 0
196 EXE: Section
197 EXE: sectname __la_symbol_ptr
198 EXE: segname __DATA
199 EXE: addr 0x0000000100008010
200 EXE: size 0x0000000000000008
201 EXE: offset 32784
202 EXE: align 2^3 (8)
203 EXE: reloff 0
204 EXE: nreloc 0
205 EXE: type S_LAZY_SYMBOL_POINTERS
206 EXE: attributes (none)
207 EXE: reserved1 3 (index into indirect symbol table)
208 EXE: reserved2 0
209 EXE: Load command 3
210 EXE: cmd LC_SEGMENT_64
211 EXE: cmdsize 72
212 EXE: segname __LINKEDIT
213 EXE: vmaddr 0x000000010000c000
214 EXE: vmsize 0x0000000000004000
215 EXE: fileoff 49152
216 EXE: filesize 264
217 EXE: maxprot r--
218 EXE: initprot r--
219 EXE: nsects 0
220 EXE: flags (none)
221 EXE: Load command 4
222 EXE: cmd LC_DYLD_INFO_ONLY
223 EXE: cmdsize 48
224 EXE: rebase_off 49152
225 EXE: rebase_size 8
226 EXE: bind_off 49160
227 EXE: bind_size 24
228 EXE: weak_bind_off 0
229 EXE: weak_bind_size 0
230 EXE: lazy_bind_off 49184
231 EXE: lazy_bind_size 16
232 EXE: export_off 49200
233 EXE: export_size 48
234 EXE: Load command 5
235 EXE: cmd LC_SYMTAB
236 EXE: cmdsize 24
237 EXE: symoff 49280
238 EXE: nsyms 4
239 EXE: stroff 49360
240 EXE: strsize 56
241 EXE: Load command 6
242 EXE: cmd LC_DYSYMTAB
243 EXE: cmdsize 80
244 EXE: ilocalsym 0
245 EXE: nlocalsym 0
246 EXE: iextdefsym 0
247 EXE: nextdefsym 2
248 EXE: iundefsym 2
249 EXE: nundefsym 2
250 EXE: tocoff 0
251 EXE: ntoc 0
252 EXE: modtaboff 0
253 EXE: nmodtab 0
254 EXE: extrefsymoff 0
255 EXE: nextrefsyms 0
256 EXE: indirectsymoff 49344
257 EXE: nindirectsyms 4
258 EXE: extreloff 0
259 EXE: nextrel 0
260 EXE: locreloff 0
261 EXE: nlocrel 0
262 EXE: Load command 7
263 EXE: cmd LC_LOAD_DYLINKER
264 EXE: cmdsize 32
265 EXE: name /usr/lib/dyld (offset 12)
266 EXE: Load command 8
267 EXE: cmd LC_UUID
268 EXE: cmdsize 24
269 EXE: uuid D687F888-CD3F-3276-8C94-BA3CCA21D820
270 EXE: Load command 9
271 EXE: cmd LC_VERSION_MIN_IPHONEOS
272 EXE: cmdsize 16
273 EXE: version 9.0
274 EXE: sdk 9.0
275 EXE: Load command 10
276 EXE: cmd LC_SOURCE_VERSION
277 EXE: cmdsize 16
278 EXE: version 0.0
279 EXE: Load command 11
280 EXE: cmd LC_MAIN
281 EXE: cmdsize 24
282 EXE: entryoff 32568
283 EXE: stacksize 0
284 EXE: Load command 12
285 EXE: cmd LC_ENCRYPTION_INFO_64
286 EXE: cmdsize 24
287 EXE: cryptoff 16384
288 EXE: cryptsize 16384
289 EXE: cryptid 0
290 EXE: pad 0
291 EXE: Load command 13
292 EXE: cmd LC_LOAD_DYLIB
293 EXE: cmdsize 56
294 EXE: name /usr/lib/libSystem.B.dylib (offset 24)
295 EXE: current version 1215.0.0
296 EXE: compatibility version 1.0.0
297 EXE: Load command 14
298 EXE: cmd LC_FUNCTION_STARTS
299 EXE: cmdsize 16
300 EXE: dataoff 49248
301 EXE: datasize 8
302 EXE: Load command 15
303 EXE: cmd LC_DATA_IN_CODE
304 EXE: cmdsize 16
305 EXE: dataoff 49256
306 EXE: datasize 0
307 EXE: Load command 16
308 EXE: cmd LC_DYLIB_CODE_SIGN_DRS
309 EXE: cmdsize 16
310 EXE: dataoff 49256
311 EXE: datasize 24
35573557 outs() << "." << (vd.version & 0xff);
35583558 outs() << "\n";
35593559 if (vd.sdk == 0)
3560 outs() << " sdk n/a\n";
3560 outs() << " sdk n/a";
35613561 else {
35623562 outs() << " sdk " << ((vd.sdk >> 16) & 0xffff) << "."
35633563 << ((vd.sdk >> 8) & 0xff);
36193619 else
36203620 outs() << "\n";
36213621 outs() << " cryptid " << ec.cryptid << "\n";
3622 }
3623
3624 static void PrintEncryptionInfoCommand64(MachO::encryption_info_command_64 ec,
3625 uint32_t object_size) {
3626 outs() << " cmd LC_ENCRYPTION_INFO_64\n";
3627 outs() << " cmdsize " << ec.cmdsize;
3628 if (ec.cmdsize != sizeof(struct MachO::encryption_info_command_64))
3629 outs() << " Incorrect size\n";
3630 else
3631 outs() << "\n";
3632 outs() << " cryptoff " << ec.cryptoff;
3633 if (ec.cryptoff > object_size)
3634 outs() << " (past end of file)\n";
3635 else
3636 outs() << "\n";
3637 outs() << " cryptsize " << ec.cryptsize;
3638 if (ec.cryptsize > object_size)
3639 outs() << " (past end of file)\n";
3640 else
3641 outs() << "\n";
3642 outs() << " cryptid " << ec.cryptid << "\n";
3643 outs() << " pad " << ec.pad << "\n";
36223644 }
36233645
36243646 static void PrintDylibCommand(MachO::dylib_command dl, const char *Ptr) {
37713793 } else if (Command.C.cmd == MachO::LC_ENCRYPTION_INFO) {
37723794 MachO::encryption_info_command Ei = Obj->getEncryptionInfoCommand(Command);
37733795 PrintEncryptionInfoCommand(Ei, Buf.size());
3796 } else if (Command.C.cmd == MachO::LC_ENCRYPTION_INFO_64) {
3797 MachO::encryption_info_command_64 Ei = Obj->getEncryptionInfoCommand64(Command);
3798 PrintEncryptionInfoCommand64(Ei, Buf.size());
37743799 } else if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
37753800 Command.C.cmd == MachO::LC_ID_DYLIB ||
37763801 Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||