Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
MachOObjectFile.cpp
Go to the documentation of this file.
1//===- MachOObjectFile.cpp - Mach-O object file binding -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the MachOObjectFile class, which binds the MachOObject
10// class to the generic ObjectFile wrapper.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/SmallVector.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/StringSwitch.h"
19#include "llvm/ADT/Twine.h"
20#include "llvm/ADT/bit.h"
21#include "llvm/BinaryFormat/MachO.h"
22#include "llvm/BinaryFormat/Swift.h"
23#include "llvm/Object/Error.h"
24#include "llvm/Object/MachO.h"
25#include "llvm/Object/ObjectFile.h"
26#include "llvm/Object/SymbolicFile.h"
27#include "llvm/Support/DataExtractor.h"
28#include "llvm/Support/Debug.h"
29#include "llvm/Support/Errc.h"
30#include "llvm/Support/Error.h"
31#include "llvm/Support/ErrorHandling.h"
32#include "llvm/Support/FileSystem.h"
33#include "llvm/Support/Format.h"
34#include "llvm/Support/LEB128.h"
35#include "llvm/Support/MemoryBufferRef.h"
36#include "llvm/Support/Path.h"
37#include "llvm/Support/SwapByteOrder.h"
38#include "llvm/Support/raw_ostream.h"
39#include "llvm/TargetParser/Host.h"
40#include "llvm/TargetParser/Triple.h"
41#include <algorithm>
42#include <cassert>
43#include <cstddef>
44#include <cstdint>
45#include <cstring>
46#include <limits>
47#include <list>
48#include <memory>
49#include <system_error>
50
51using namespacellvm;
52using namespaceobject;
53
54namespace{
55
56structsection_base {
57char sectname[16];
58char segname[16];
59 };
60
61}// end anonymous namespace
62
63staticErrormalformedError(constTwine &Msg) {
64return make_error<GenericBinaryError>("truncated or malformed object (" +
65 Msg +")",
66 object_error::parse_failed);
67}
68
69// FIXME: Replace all uses of this function with getStructOrErr.
70template <typename T>
71staticTgetStruct(constMachOObjectFile &O,constchar *P) {
72// Don't read before the beginning or past the end of the file
73if (P < O.getData().begin() ||P +sizeof(T) > O.getData().end())
74report_fatal_error("Malformed MachO file.");
75
76T Cmd;
77 memcpy(&Cmd,P,sizeof(T));
78if (O.isLittleEndian() !=sys::IsLittleEndianHost)
79MachO::swapStruct(Cmd);
80return Cmd;
81}
82
83template <typename T>
84staticExpected<T>getStructOrErr(constMachOObjectFile &O,constchar *P) {
85// Don't read before the beginning or past the end of the file
86if (P < O.getData().begin() ||P +sizeof(T) > O.getData().end())
87returnmalformedError("Structure read out-of-range");
88
89T Cmd;
90 memcpy(&Cmd,P,sizeof(T));
91if (O.isLittleEndian() !=sys::IsLittleEndianHost)
92MachO::swapStruct(Cmd);
93return Cmd;
94}
95
96staticconstchar *
97getSectionPtr(constMachOObjectFile &O,MachOObjectFile::LoadCommandInfo L,
98unsigned Sec) {
99 uintptr_t CommandAddr =reinterpret_cast<uintptr_t>(L.Ptr);
100
101bool Is64 = O.is64Bit();
102unsigned SegmentLoadSize = Is64 ?sizeof(MachO::segment_command_64) :
103sizeof(MachO::segment_command);
104unsigned SectionSize = Is64 ?sizeof(MachO::section_64) :
105sizeof(MachO::section);
106
107 uintptr_t SectionAddr = CommandAddr + SegmentLoadSize + Sec * SectionSize;
108returnreinterpret_cast<constchar*>(SectionAddr);
109}
110
111staticconstchar *getPtr(constMachOObjectFile &O,size_tOffset,
112size_t MachOFilesetEntryOffset = 0) {
113assert(Offset <= O.getData().size() &&
114 MachOFilesetEntryOffset <= O.getData().size());
115return O.getData().data() +Offset + MachOFilesetEntryOffset;
116}
117
118staticMachO::nlist_base
119getSymbolTableEntryBase(constMachOObjectFile &O,DataRefImpl DRI) {
120constchar *P =reinterpret_cast<constchar *>(DRI.p);
121return getStruct<MachO::nlist_base>(O,P);
122}
123
124staticStringRefparseSegmentOrSectionName(constchar *P) {
125if (P[15] == 0)
126// Null terminated.
127returnP;
128// Not null terminated, so this is a 16 char string.
129returnStringRef(P, 16);
130}
131
132staticunsignedgetCPUType(constMachOObjectFile &O) {
133return O.getHeader().cputype;
134}
135
136staticunsignedgetCPUSubType(constMachOObjectFile &O) {
137return O.getHeader().cpusubtype & ~MachO::CPU_SUBTYPE_MASK;
138}
139
140staticuint32_t
141getPlainRelocationAddress(constMachO::any_relocation_info &RE) {
142return RE.r_word0;
143}
144
145staticunsigned
146getScatteredRelocationAddress(constMachO::any_relocation_info &RE) {
147return RE.r_word0 & 0xffffff;
148}
149
150staticboolgetPlainRelocationPCRel(constMachOObjectFile &O,
151constMachO::any_relocation_info &RE) {
152if (O.isLittleEndian())
153return (RE.r_word1 >> 24) & 1;
154return (RE.r_word1 >> 7) & 1;
155}
156
157staticbool
158getScatteredRelocationPCRel(constMachO::any_relocation_info &RE) {
159return (RE.r_word0 >> 30) & 1;
160}
161
162staticunsignedgetPlainRelocationLength(constMachOObjectFile &O,
163constMachO::any_relocation_info &RE) {
164if (O.isLittleEndian())
165return (RE.r_word1 >> 25) & 3;
166return (RE.r_word1 >> 5) & 3;
167}
168
169staticunsigned
170getScatteredRelocationLength(constMachO::any_relocation_info &RE) {
171return (RE.r_word0 >> 28) & 3;
172}
173
174staticunsignedgetPlainRelocationType(constMachOObjectFile &O,
175constMachO::any_relocation_info &RE) {
176if (O.isLittleEndian())
177return RE.r_word1 >> 28;
178return RE.r_word1 & 0xf;
179}
180
181staticuint32_tgetSectionFlags(constMachOObjectFile &O,
182DataRefImpl Sec) {
183if (O.is64Bit()) {
184MachO::section_64 Sect = O.getSection64(Sec);
185return Sect.flags;
186 }
187MachO::section Sect = O.getSection(Sec);
188return Sect.flags;
189}
190
191staticExpected<MachOObjectFile::LoadCommandInfo>
192getLoadCommandInfo(constMachOObjectFile &Obj,constchar *Ptr,
193uint32_t LoadCommandIndex) {
194if (auto CmdOrErr = getStructOrErr<MachO::load_command>(Obj,Ptr)) {
195if (CmdOrErr->cmdsize +Ptr > Obj.getData().end())
196returnmalformedError("load command " +Twine(LoadCommandIndex) +
197" extends past end of file");
198if (CmdOrErr->cmdsize < 8)
199returnmalformedError("load command " +Twine(LoadCommandIndex) +
200" with size less than 8 bytes");
201returnMachOObjectFile::LoadCommandInfo({Ptr, *CmdOrErr});
202 }else
203return CmdOrErr.takeError();
204}
205
206staticExpected<MachOObjectFile::LoadCommandInfo>
207getFirstLoadCommandInfo(constMachOObjectFile &Obj) {
208unsigned HeaderSize = Obj.is64Bit() ?sizeof(MachO::mach_header_64)
209 :sizeof(MachO::mach_header);
210if (sizeof(MachO::load_command) > Obj.getHeader().sizeofcmds)
211returnmalformedError("load command 0 extends past the end all load "
212"commands in the file");
213returngetLoadCommandInfo(
214 Obj,getPtr(Obj, HeaderSize, Obj.getMachOFilesetEntryOffset()), 0);
215}
216
217staticExpected<MachOObjectFile::LoadCommandInfo>
218getNextLoadCommandInfo(constMachOObjectFile &Obj,uint32_t LoadCommandIndex,
219constMachOObjectFile::LoadCommandInfo &L) {
220unsigned HeaderSize = Obj.is64Bit() ?sizeof(MachO::mach_header_64)
221 :sizeof(MachO::mach_header);
222if (L.Ptr + L.C.cmdsize +sizeof(MachO::load_command) >
223 Obj.getData().data() + Obj.getMachOFilesetEntryOffset() + HeaderSize +
224 Obj.getHeader().sizeofcmds)
225returnmalformedError("load command " +Twine(LoadCommandIndex + 1) +
226" extends past the end all load commands in the file");
227returngetLoadCommandInfo(Obj, L.Ptr + L.C.cmdsize, LoadCommandIndex + 1);
228}
229
230template <typename T>
231staticvoidparseHeader(constMachOObjectFile &Obj,T &Header,
232Error &Err) {
233if (sizeof(T) > Obj.getData().size()) {
234 Err =malformedError("the mach header extends past the end of the "
235"file");
236return;
237 }
238if (auto HeaderOrErr = getStructOrErr<T>(
239 Obj,getPtr(Obj, 0, Obj.getMachOFilesetEntryOffset())))
240 Header = *HeaderOrErr;
241else
242 Err = HeaderOrErr.takeError();
243}
244
245// This is used to check for overlapping of Mach-O elements.
246structMachOElement {
247uint64_tOffset;
248uint64_tSize;
249constchar *Name;
250};
251
252staticErrorcheckOverlappingElement(std::list<MachOElement> &Elements,
253uint64_tOffset,uint64_tSize,
254constchar *Name) {
255if (Size == 0)
256returnError::success();
257
258for (auto it = Elements.begin(); it != Elements.end(); ++it) {
259constauto &E = *it;
260if ((Offset >= E.Offset &&Offset < E.Offset + E.Size) ||
261 (Offset +Size > E.Offset &&Offset +Size < E.Offset + E.Size) ||
262 (Offset <= E.Offset && Offset + Size >= E.Offset + E.Size))
263returnmalformedError(Twine(Name) +" at offset " +Twine(Offset) +
264" with a size of " +Twine(Size) +", overlaps " +
265 E.Name +" at offset " +Twine(E.Offset) +" with "
266"a size of " +Twine(E.Size));
267auto nt = it;
268 nt++;
269if (nt != Elements.end()) {
270constauto &N = *nt;
271if (Offset +Size <=N.Offset) {
272 Elements.insert(nt, {Offset,Size,Name});
273returnError::success();
274 }
275 }
276 }
277 Elements.push_back({Offset,Size,Name});
278returnError::success();
279}
280
281// Parses LC_SEGMENT or LC_SEGMENT_64 load command, adds addresses of all
282// sections to \param Sections, and optionally sets
283// \param IsPageZeroSegment to true.
284template <typename Segment,typename Section>
285staticErrorparseSegmentLoadCommand(
286constMachOObjectFile &Obj,constMachOObjectFile::LoadCommandInfo &Load,
287SmallVectorImpl<const char *> &Sections,bool &IsPageZeroSegment,
288uint32_t LoadCommandIndex,constchar *CmdName,uint64_t SizeOfHeaders,
289 std::list<MachOElement> &Elements) {
290constunsigned SegmentLoadSize =sizeof(Segment);
291if (Load.C.cmdsize < SegmentLoadSize)
292returnmalformedError("load command " +Twine(LoadCommandIndex) +
293" " + CmdName +" cmdsize too small");
294if (auto SegOrErr = getStructOrErr<Segment>(Obj, Load.Ptr)) {
295 Segment S = SegOrErr.get();
296constunsigned SectionSize =sizeof(Section);
297uint64_t FileSize = Obj.getData().size();
298if (S.nsects > std::numeric_limits<uint32_t>::max() / SectionSize ||
299 S.nsects * SectionSize > Load.C.cmdsize - SegmentLoadSize)
300returnmalformedError("load command " +Twine(LoadCommandIndex) +
301" inconsistent cmdsize in " + CmdName +
302" for the number of sections");
303for (unsigned J = 0; J < S.nsects; ++J) {
304constchar *Sec =getSectionPtr(Obj, Load, J);
305 Sections.push_back(Sec);
306auto SectionOrErr = getStructOrErr<Section>(Obj, Sec);
307if (!SectionOrErr)
308return SectionOrErr.takeError();
309 Section s = SectionOrErr.get();
310if (Obj.getHeader().filetype !=MachO::MH_DYLIB_STUB &&
311 Obj.getHeader().filetype !=MachO::MH_DSYM &&
312 s.flags !=MachO::S_ZEROFILL &&
313 s.flags !=MachO::S_THREAD_LOCAL_ZEROFILL &&
314 s.offset > FileSize)
315returnmalformedError("offset field of section " +Twine(J) +" in " +
316 CmdName +" command " +Twine(LoadCommandIndex) +
317" extends past the end of the file");
318if (Obj.getHeader().filetype !=MachO::MH_DYLIB_STUB &&
319 Obj.getHeader().filetype !=MachO::MH_DSYM &&
320 s.flags !=MachO::S_ZEROFILL &&
321 s.flags !=MachO::S_THREAD_LOCAL_ZEROFILL && S.fileoff == 0 &&
322 s.offset < SizeOfHeaders && s.size != 0)
323returnmalformedError("offset field of section " +Twine(J) +" in " +
324 CmdName +" command " +Twine(LoadCommandIndex) +
325" not past the headers of the file");
326uint64_t BigSize = s.offset;
327 BigSize += s.size;
328if (Obj.getHeader().filetype !=MachO::MH_DYLIB_STUB &&
329 Obj.getHeader().filetype !=MachO::MH_DSYM &&
330 s.flags !=MachO::S_ZEROFILL &&
331 s.flags !=MachO::S_THREAD_LOCAL_ZEROFILL &&
332 BigSize > FileSize)
333returnmalformedError("offset field plus size field of section " +
334Twine(J) +" in " + CmdName +" command " +
335Twine(LoadCommandIndex) +
336" extends past the end of the file");
337if (Obj.getHeader().filetype !=MachO::MH_DYLIB_STUB &&
338 Obj.getHeader().filetype !=MachO::MH_DSYM &&
339 s.flags !=MachO::S_ZEROFILL &&
340 s.flags !=MachO::S_THREAD_LOCAL_ZEROFILL &&
341 s.size > S.filesize)
342returnmalformedError("size field of section " +
343Twine(J) +" in " + CmdName +" command " +
344Twine(LoadCommandIndex) +
345" greater than the segment");
346if (Obj.getHeader().filetype !=MachO::MH_DYLIB_STUB &&
347 Obj.getHeader().filetype !=MachO::MH_DSYM && s.size != 0 &&
348 s.addr < S.vmaddr)
349returnmalformedError("addr field of section " +Twine(J) +" in " +
350 CmdName +" command " +Twine(LoadCommandIndex) +
351" less than the segment's vmaddr");
352 BigSize = s.addr;
353 BigSize += s.size;
354uint64_t BigEnd = S.vmaddr;
355 BigEnd += S.vmsize;
356if (S.vmsize != 0 && s.size != 0 && BigSize > BigEnd)
357returnmalformedError("addr field plus size of section " +Twine(J) +
358" in " + CmdName +" command " +
359Twine(LoadCommandIndex) +
360" greater than than "
361"the segment's vmaddr plus vmsize");
362if (Obj.getHeader().filetype !=MachO::MH_DYLIB_STUB &&
363 Obj.getHeader().filetype !=MachO::MH_DSYM &&
364 s.flags !=MachO::S_ZEROFILL &&
365 s.flags !=MachO::S_THREAD_LOCAL_ZEROFILL)
366if (Error Err =checkOverlappingElement(Elements, s.offset, s.size,
367"section contents"))
368return Err;
369if (s.reloff > FileSize)
370returnmalformedError("reloff field of section " +Twine(J) +" in " +
371 CmdName +" command " +Twine(LoadCommandIndex) +
372" extends past the end of the file");
373 BigSize = s.nreloc;
374 BigSize *=sizeof(structMachO::relocation_info);
375 BigSize += s.reloff;
376if (BigSize > FileSize)
377returnmalformedError("reloff field plus nreloc field times sizeof("
378"struct relocation_info) of section " +
379Twine(J) +" in " + CmdName +" command " +
380Twine(LoadCommandIndex) +
381" extends past the end of the file");
382if (Error Err =checkOverlappingElement(Elements, s.reloff, s.nreloc *
383sizeof(struct
384MachO::relocation_info),
385"section relocation entries"))
386return Err;
387 }
388if (S.fileoff > FileSize)
389returnmalformedError("load command " +Twine(LoadCommandIndex) +
390" fileoff field in " + CmdName +
391" extends past the end of the file");
392uint64_t BigSize = S.fileoff;
393 BigSize += S.filesize;
394if (BigSize > FileSize)
395returnmalformedError("load command " +Twine(LoadCommandIndex) +
396" fileoff field plus filesize field in " +
397 CmdName +" extends past the end of the file");
398if (S.vmsize != 0 && S.filesize > S.vmsize)
399returnmalformedError("load command " +Twine(LoadCommandIndex) +
400" filesize field in " + CmdName +
401" greater than vmsize field");
402 IsPageZeroSegment |=StringRef("__PAGEZERO") == S.segname;
403 }else
404return SegOrErr.takeError();
405
406returnError::success();
407}
408
409staticErrorcheckSymtabCommand(constMachOObjectFile &Obj,
410constMachOObjectFile::LoadCommandInfo &Load,
411uint32_t LoadCommandIndex,
412constchar **SymtabLoadCmd,
413 std::list<MachOElement> &Elements) {
414if (Load.C.cmdsize <sizeof(MachO::symtab_command))
415returnmalformedError("load command " +Twine(LoadCommandIndex) +
416" LC_SYMTAB cmdsize too small");
417if (*SymtabLoadCmd !=nullptr)
418returnmalformedError("more than one LC_SYMTAB command");
419auto SymtabOrErr = getStructOrErr<MachO::symtab_command>(Obj, Load.Ptr);
420if (!SymtabOrErr)
421return SymtabOrErr.takeError();
422MachO::symtab_command Symtab = SymtabOrErr.get();
423if (Symtab.cmdsize !=sizeof(MachO::symtab_command))
424returnmalformedError("LC_SYMTAB command " +Twine(LoadCommandIndex) +
425" has incorrect cmdsize");
426uint64_t FileSize = Obj.getData().size();
427if (Symtab.symoff > FileSize)
428returnmalformedError("symoff field of LC_SYMTAB command " +
429Twine(LoadCommandIndex) +" extends past the end "
430"of the file");
431uint64_t SymtabSize = Symtab.nsyms;
432constchar *struct_nlist_name;
433if (Obj.is64Bit()) {
434 SymtabSize *=sizeof(MachO::nlist_64);
435 struct_nlist_name ="struct nlist_64";
436 }else {
437 SymtabSize *=sizeof(MachO::nlist);
438 struct_nlist_name ="struct nlist";
439 }
440uint64_t BigSize = SymtabSize;
441 BigSize += Symtab.symoff;
442if (BigSize > FileSize)
443returnmalformedError("symoff field plus nsyms field times sizeof(" +
444Twine(struct_nlist_name) +") of LC_SYMTAB command " +
445Twine(LoadCommandIndex) +" extends past the end "
446"of the file");
447if (Error Err =checkOverlappingElement(Elements, Symtab.symoff, SymtabSize,
448"symbol table"))
449return Err;
450if (Symtab.stroff > FileSize)
451returnmalformedError("stroff field of LC_SYMTAB command " +
452Twine(LoadCommandIndex) +" extends past the end "
453"of the file");
454 BigSize = Symtab.stroff;
455 BigSize += Symtab.strsize;
456if (BigSize > FileSize)
457returnmalformedError("stroff field plus strsize field of LC_SYMTAB "
458"command " +Twine(LoadCommandIndex) +" extends "
459"past the end of the file");
460if (Error Err =checkOverlappingElement(Elements, Symtab.stroff,
461 Symtab.strsize,"string table"))
462return Err;
463 *SymtabLoadCmd = Load.Ptr;
464returnError::success();
465}
466
467staticErrorcheckDysymtabCommand(constMachOObjectFile &Obj,
468constMachOObjectFile::LoadCommandInfo &Load,
469uint32_t LoadCommandIndex,
470constchar **DysymtabLoadCmd,
471 std::list<MachOElement> &Elements) {
472if (Load.C.cmdsize <sizeof(MachO::dysymtab_command))
473returnmalformedError("load command " +Twine(LoadCommandIndex) +
474" LC_DYSYMTAB cmdsize too small");
475if (*DysymtabLoadCmd !=nullptr)
476returnmalformedError("more than one LC_DYSYMTAB command");
477auto DysymtabOrErr =
478 getStructOrErr<MachO::dysymtab_command>(Obj, Load.Ptr);
479if (!DysymtabOrErr)
480return DysymtabOrErr.takeError();
481MachO::dysymtab_command Dysymtab = DysymtabOrErr.get();
482if (Dysymtab.cmdsize !=sizeof(MachO::dysymtab_command))
483returnmalformedError("LC_DYSYMTAB command " +Twine(LoadCommandIndex) +
484" has incorrect cmdsize");
485uint64_t FileSize = Obj.getData().size();
486if (Dysymtab.tocoff > FileSize)
487returnmalformedError("tocoff field of LC_DYSYMTAB command " +
488Twine(LoadCommandIndex) +" extends past the end of "
489"the file");
490uint64_t BigSize = Dysymtab.ntoc;
491 BigSize *=sizeof(MachO::dylib_table_of_contents);
492 BigSize += Dysymtab.tocoff;
493if (BigSize > FileSize)
494returnmalformedError("tocoff field plus ntoc field times sizeof(struct "
495"dylib_table_of_contents) of LC_DYSYMTAB command " +
496Twine(LoadCommandIndex) +" extends past the end of "
497"the file");
498if (Error Err =checkOverlappingElement(Elements, Dysymtab.tocoff,
499 Dysymtab.ntoc *sizeof(struct
500MachO::dylib_table_of_contents),
501"table of contents"))
502return Err;
503if (Dysymtab.modtaboff > FileSize)
504returnmalformedError("modtaboff field of LC_DYSYMTAB command " +
505Twine(LoadCommandIndex) +" extends past the end of "
506"the file");
507 BigSize = Dysymtab.nmodtab;
508constchar *struct_dylib_module_name;
509uint64_t sizeof_modtab;
510if (Obj.is64Bit()) {
511 sizeof_modtab =sizeof(MachO::dylib_module_64);
512 struct_dylib_module_name ="struct dylib_module_64";
513 }else {
514 sizeof_modtab =sizeof(MachO::dylib_module);
515 struct_dylib_module_name ="struct dylib_module";
516 }
517 BigSize *= sizeof_modtab;
518 BigSize += Dysymtab.modtaboff;
519if (BigSize > FileSize)
520returnmalformedError("modtaboff field plus nmodtab field times sizeof(" +
521Twine(struct_dylib_module_name) +") of LC_DYSYMTAB "
522"command " +Twine(LoadCommandIndex) +" extends "
523"past the end of the file");
524if (Error Err =checkOverlappingElement(Elements, Dysymtab.modtaboff,
525 Dysymtab.nmodtab * sizeof_modtab,
526"module table"))
527return Err;
528if (Dysymtab.extrefsymoff > FileSize)
529returnmalformedError("extrefsymoff field of LC_DYSYMTAB command " +
530Twine(LoadCommandIndex) +" extends past the end of "
531"the file");
532 BigSize = Dysymtab.nextrefsyms;
533 BigSize *=sizeof(MachO::dylib_reference);
534 BigSize += Dysymtab.extrefsymoff;
535if (BigSize > FileSize)
536returnmalformedError("extrefsymoff field plus nextrefsyms field times "
537"sizeof(struct dylib_reference) of LC_DYSYMTAB "
538"command " +Twine(LoadCommandIndex) +" extends "
539"past the end of the file");
540if (Error Err =checkOverlappingElement(Elements, Dysymtab.extrefsymoff,
541 Dysymtab.nextrefsyms *
542sizeof(MachO::dylib_reference),
543"reference table"))
544return Err;
545if (Dysymtab.indirectsymoff > FileSize)
546returnmalformedError("indirectsymoff field of LC_DYSYMTAB command " +
547Twine(LoadCommandIndex) +" extends past the end of "
548"the file");
549 BigSize = Dysymtab.nindirectsyms;
550 BigSize *=sizeof(uint32_t);
551 BigSize += Dysymtab.indirectsymoff;
552if (BigSize > FileSize)
553returnmalformedError("indirectsymoff field plus nindirectsyms field times "
554"sizeof(uint32_t) of LC_DYSYMTAB command " +
555Twine(LoadCommandIndex) +" extends past the end of "
556"the file");
557if (Error Err =checkOverlappingElement(Elements, Dysymtab.indirectsymoff,
558 Dysymtab.nindirectsyms *
559sizeof(uint32_t),
560"indirect table"))
561return Err;
562if (Dysymtab.extreloff > FileSize)
563returnmalformedError("extreloff field of LC_DYSYMTAB command " +
564Twine(LoadCommandIndex) +" extends past the end of "
565"the file");
566 BigSize = Dysymtab.nextrel;
567 BigSize *=sizeof(MachO::relocation_info);
568 BigSize += Dysymtab.extreloff;
569if (BigSize > FileSize)
570returnmalformedError("extreloff field plus nextrel field times sizeof"
571"(struct relocation_info) of LC_DYSYMTAB command " +
572Twine(LoadCommandIndex) +" extends past the end of "
573"the file");
574if (Error Err =checkOverlappingElement(Elements, Dysymtab.extreloff,
575 Dysymtab.nextrel *
576sizeof(MachO::relocation_info),
577"external relocation table"))
578return Err;
579if (Dysymtab.locreloff > FileSize)
580returnmalformedError("locreloff field of LC_DYSYMTAB command " +
581Twine(LoadCommandIndex) +" extends past the end of "
582"the file");
583 BigSize = Dysymtab.nlocrel;
584 BigSize *=sizeof(MachO::relocation_info);
585 BigSize += Dysymtab.locreloff;
586if (BigSize > FileSize)
587returnmalformedError("locreloff field plus nlocrel field times sizeof"
588"(struct relocation_info) of LC_DYSYMTAB command " +
589Twine(LoadCommandIndex) +" extends past the end of "
590"the file");
591if (Error Err =checkOverlappingElement(Elements, Dysymtab.locreloff,
592 Dysymtab.nlocrel *
593sizeof(MachO::relocation_info),
594"local relocation table"))
595return Err;
596 *DysymtabLoadCmd = Load.Ptr;
597returnError::success();
598}
599
600staticErrorcheckLinkeditDataCommand(constMachOObjectFile &Obj,
601constMachOObjectFile::LoadCommandInfo &Load,
602uint32_t LoadCommandIndex,
603constchar **LoadCmd,constchar *CmdName,
604 std::list<MachOElement> &Elements,
605constchar *ElementName) {
606if (Load.C.cmdsize <sizeof(MachO::linkedit_data_command))
607returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
608 CmdName +" cmdsize too small");
609if (*LoadCmd !=nullptr)
610returnmalformedError("more than one " +Twine(CmdName) +" command");
611auto LinkDataOrError =
612 getStructOrErr<MachO::linkedit_data_command>(Obj, Load.Ptr);
613if (!LinkDataOrError)
614return LinkDataOrError.takeError();
615MachO::linkedit_data_command LinkData = LinkDataOrError.get();
616if (LinkData.cmdsize !=sizeof(MachO::linkedit_data_command))
617returnmalformedError(Twine(CmdName) +" command " +
618Twine(LoadCommandIndex) +" has incorrect cmdsize");
619uint64_t FileSize = Obj.getData().size();
620if (LinkData.dataoff > FileSize)
621returnmalformedError("dataoff field of " +Twine(CmdName) +" command " +
622Twine(LoadCommandIndex) +" extends past the end of "
623"the file");
624uint64_t BigSize = LinkData.dataoff;
625 BigSize += LinkData.datasize;
626if (BigSize > FileSize)
627returnmalformedError("dataoff field plus datasize field of " +
628Twine(CmdName) +" command " +
629Twine(LoadCommandIndex) +" extends past the end of "
630"the file");
631if (Error Err =checkOverlappingElement(Elements, LinkData.dataoff,
632 LinkData.datasize, ElementName))
633return Err;
634 *LoadCmd = Load.Ptr;
635returnError::success();
636}
637
638staticErrorcheckDyldInfoCommand(constMachOObjectFile &Obj,
639constMachOObjectFile::LoadCommandInfo &Load,
640uint32_t LoadCommandIndex,
641constchar **LoadCmd,constchar *CmdName,
642 std::list<MachOElement> &Elements) {
643if (Load.C.cmdsize <sizeof(MachO::dyld_info_command))
644returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
645 CmdName +" cmdsize too small");
646if (*LoadCmd !=nullptr)
647returnmalformedError("more than one LC_DYLD_INFO and or LC_DYLD_INFO_ONLY "
648"command");
649auto DyldInfoOrErr =
650 getStructOrErr<MachO::dyld_info_command>(Obj, Load.Ptr);
651if (!DyldInfoOrErr)
652return DyldInfoOrErr.takeError();
653MachO::dyld_info_command DyldInfo = DyldInfoOrErr.get();
654if (DyldInfo.cmdsize !=sizeof(MachO::dyld_info_command))
655returnmalformedError(Twine(CmdName) +" command " +
656Twine(LoadCommandIndex) +" has incorrect cmdsize");
657uint64_t FileSize = Obj.getData().size();
658if (DyldInfo.rebase_off > FileSize)
659returnmalformedError("rebase_off field of " +Twine(CmdName) +
660" command " +Twine(LoadCommandIndex) +" extends "
661"past the end of the file");
662uint64_t BigSize = DyldInfo.rebase_off;
663 BigSize += DyldInfo.rebase_size;
664if (BigSize > FileSize)
665returnmalformedError("rebase_off field plus rebase_size field of " +
666Twine(CmdName) +" command " +
667Twine(LoadCommandIndex) +" extends past the end of "
668"the file");
669if (Error Err =checkOverlappingElement(Elements, DyldInfo.rebase_off,
670 DyldInfo.rebase_size,
671"dyld rebase info"))
672return Err;
673if (DyldInfo.bind_off > FileSize)
674returnmalformedError("bind_off field of " +Twine(CmdName) +
675" command " +Twine(LoadCommandIndex) +" extends "
676"past the end of the file");
677 BigSize = DyldInfo.bind_off;
678 BigSize += DyldInfo.bind_size;
679if (BigSize > FileSize)
680returnmalformedError("bind_off field plus bind_size field of " +
681Twine(CmdName) +" command " +
682Twine(LoadCommandIndex) +" extends past the end of "
683"the file");
684if (Error Err =checkOverlappingElement(Elements, DyldInfo.bind_off,
685 DyldInfo.bind_size,
686"dyld bind info"))
687return Err;
688if (DyldInfo.weak_bind_off > FileSize)
689returnmalformedError("weak_bind_off field of " +Twine(CmdName) +
690" command " +Twine(LoadCommandIndex) +" extends "
691"past the end of the file");
692 BigSize = DyldInfo.weak_bind_off;
693 BigSize += DyldInfo.weak_bind_size;
694if (BigSize > FileSize)
695returnmalformedError("weak_bind_off field plus weak_bind_size field of " +
696Twine(CmdName) +" command " +
697Twine(LoadCommandIndex) +" extends past the end of "
698"the file");
699if (Error Err =checkOverlappingElement(Elements, DyldInfo.weak_bind_off,
700 DyldInfo.weak_bind_size,
701"dyld weak bind info"))
702return Err;
703if (DyldInfo.lazy_bind_off > FileSize)
704returnmalformedError("lazy_bind_off field of " +Twine(CmdName) +
705" command " +Twine(LoadCommandIndex) +" extends "
706"past the end of the file");
707 BigSize = DyldInfo.lazy_bind_off;
708 BigSize += DyldInfo.lazy_bind_size;
709if (BigSize > FileSize)
710returnmalformedError("lazy_bind_off field plus lazy_bind_size field of " +
711Twine(CmdName) +" command " +
712Twine(LoadCommandIndex) +" extends past the end of "
713"the file");
714if (Error Err =checkOverlappingElement(Elements, DyldInfo.lazy_bind_off,
715 DyldInfo.lazy_bind_size,
716"dyld lazy bind info"))
717return Err;
718if (DyldInfo.export_off > FileSize)
719returnmalformedError("export_off field of " +Twine(CmdName) +
720" command " +Twine(LoadCommandIndex) +" extends "
721"past the end of the file");
722 BigSize = DyldInfo.export_off;
723 BigSize += DyldInfo.export_size;
724if (BigSize > FileSize)
725returnmalformedError("export_off field plus export_size field of " +
726Twine(CmdName) +" command " +
727Twine(LoadCommandIndex) +" extends past the end of "
728"the file");
729if (Error Err =checkOverlappingElement(Elements, DyldInfo.export_off,
730 DyldInfo.export_size,
731"dyld export info"))
732return Err;
733 *LoadCmd = Load.Ptr;
734returnError::success();
735}
736
737staticErrorcheckDylibCommand(constMachOObjectFile &Obj,
738constMachOObjectFile::LoadCommandInfo &Load,
739uint32_t LoadCommandIndex,constchar *CmdName) {
740if (Load.C.cmdsize <sizeof(MachO::dylib_command))
741returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
742 CmdName +" cmdsize too small");
743auto CommandOrErr = getStructOrErr<MachO::dylib_command>(Obj, Load.Ptr);
744if (!CommandOrErr)
745return CommandOrErr.takeError();
746MachO::dylib_commandD = CommandOrErr.get();
747if (D.dylib.name <sizeof(MachO::dylib_command))
748returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
749 CmdName +" name.offset field too small, not past "
750"the end of the dylib_command struct");
751if (D.dylib.name >=D.cmdsize)
752returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
753 CmdName +" name.offset field extends past the end "
754"of the load command");
755// Make sure there is a null between the starting offset of the name and
756// the end of the load command.
757uint32_t i;
758constchar *P = (constchar *)Load.Ptr;
759for (i =D.dylib.name; i <D.cmdsize; i++)
760if (P[i] =='\0')
761break;
762if (i >=D.cmdsize)
763returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
764 CmdName +" library name extends past the end of the "
765"load command");
766returnError::success();
767}
768
769staticErrorcheckDylibIdCommand(constMachOObjectFile &Obj,
770constMachOObjectFile::LoadCommandInfo &Load,
771uint32_t LoadCommandIndex,
772constchar **LoadCmd) {
773if (Error Err =checkDylibCommand(Obj, Load, LoadCommandIndex,
774"LC_ID_DYLIB"))
775return Err;
776if (*LoadCmd !=nullptr)
777returnmalformedError("more than one LC_ID_DYLIB command");
778if (Obj.getHeader().filetype !=MachO::MH_DYLIB &&
779 Obj.getHeader().filetype !=MachO::MH_DYLIB_STUB)
780returnmalformedError("LC_ID_DYLIB load command in non-dynamic library "
781"file type");
782 *LoadCmd = Load.Ptr;
783returnError::success();
784}
785
786staticErrorcheckDyldCommand(constMachOObjectFile &Obj,
787constMachOObjectFile::LoadCommandInfo &Load,
788uint32_t LoadCommandIndex,constchar *CmdName) {
789if (Load.C.cmdsize <sizeof(MachO::dylinker_command))
790returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
791 CmdName +" cmdsize too small");
792auto CommandOrErr = getStructOrErr<MachO::dylinker_command>(Obj, Load.Ptr);
793if (!CommandOrErr)
794return CommandOrErr.takeError();
795MachO::dylinker_commandD = CommandOrErr.get();
796if (D.name <sizeof(MachO::dylinker_command))
797returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
798 CmdName +" name.offset field too small, not past "
799"the end of the dylinker_command struct");
800if (D.name >=D.cmdsize)
801returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
802 CmdName +" name.offset field extends past the end "
803"of the load command");
804// Make sure there is a null between the starting offset of the name and
805// the end of the load command.
806uint32_t i;
807constchar *P = (constchar *)Load.Ptr;
808for (i =D.name; i <D.cmdsize; i++)
809if (P[i] =='\0')
810break;
811if (i >=D.cmdsize)
812returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
813 CmdName +" dyld name extends past the end of the "
814"load command");
815returnError::success();
816}
817
818staticErrorcheckVersCommand(constMachOObjectFile &Obj,
819constMachOObjectFile::LoadCommandInfo &Load,
820uint32_t LoadCommandIndex,
821constchar **LoadCmd,constchar *CmdName) {
822if (Load.C.cmdsize !=sizeof(MachO::version_min_command))
823returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
824 CmdName +" has incorrect cmdsize");
825if (*LoadCmd !=nullptr)
826returnmalformedError("more than one LC_VERSION_MIN_MACOSX, "
827"LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_TVOS or "
828"LC_VERSION_MIN_WATCHOS command");
829 *LoadCmd = Load.Ptr;
830returnError::success();
831}
832
833staticErrorcheckNoteCommand(constMachOObjectFile &Obj,
834constMachOObjectFile::LoadCommandInfo &Load,
835uint32_t LoadCommandIndex,
836 std::list<MachOElement> &Elements) {
837if (Load.C.cmdsize !=sizeof(MachO::note_command))
838returnmalformedError("load command " +Twine(LoadCommandIndex) +
839" LC_NOTE has incorrect cmdsize");
840auto NoteCmdOrErr = getStructOrErr<MachO::note_command>(Obj, Load.Ptr);
841if (!NoteCmdOrErr)
842return NoteCmdOrErr.takeError();
843MachO::note_command Nt = NoteCmdOrErr.get();
844uint64_t FileSize = Obj.getData().size();
845if (Nt.offset > FileSize)
846returnmalformedError("offset field of LC_NOTE command " +
847Twine(LoadCommandIndex) +" extends "
848"past the end of the file");
849uint64_t BigSize = Nt.offset;
850 BigSize += Nt.size;
851if (BigSize > FileSize)
852returnmalformedError("size field plus offset field of LC_NOTE command " +
853Twine(LoadCommandIndex) +" extends past the end of "
854"the file");
855if (Error Err =checkOverlappingElement(Elements, Nt.offset, Nt.size,
856"LC_NOTE data"))
857return Err;
858returnError::success();
859}
860
861staticError
862parseBuildVersionCommand(constMachOObjectFile &Obj,
863constMachOObjectFile::LoadCommandInfo &Load,
864SmallVectorImpl<const char*> &BuildTools,
865uint32_t LoadCommandIndex) {
866auto BVCOrErr =
867 getStructOrErr<MachO::build_version_command>(Obj, Load.Ptr);
868if (!BVCOrErr)
869return BVCOrErr.takeError();
870MachO::build_version_command BVC = BVCOrErr.get();
871if (Load.C.cmdsize !=
872sizeof(MachO::build_version_command) +
873 BVC.ntools *sizeof(MachO::build_tool_version))
874returnmalformedError("load command " +Twine(LoadCommandIndex) +
875" LC_BUILD_VERSION_COMMAND has incorrect cmdsize");
876
877auto Start = Load.Ptr +sizeof(MachO::build_version_command);
878 BuildTools.resize(BVC.ntools);
879for (unsigned i = 0; i < BVC.ntools; ++i)
880 BuildTools[i] = Start + i *sizeof(MachO::build_tool_version);
881
882returnError::success();
883}
884
885staticErrorcheckRpathCommand(constMachOObjectFile &Obj,
886constMachOObjectFile::LoadCommandInfo &Load,
887uint32_t LoadCommandIndex) {
888if (Load.C.cmdsize <sizeof(MachO::rpath_command))
889returnmalformedError("load command " +Twine(LoadCommandIndex) +
890" LC_RPATH cmdsize too small");
891auto ROrErr = getStructOrErr<MachO::rpath_command>(Obj, Load.Ptr);
892if (!ROrErr)
893return ROrErr.takeError();
894MachO::rpath_command R = ROrErr.get();
895if (R.path <sizeof(MachO::rpath_command))
896returnmalformedError("load command " +Twine(LoadCommandIndex) +
897" LC_RPATH path.offset field too small, not past "
898"the end of the rpath_command struct");
899if (R.path >= R.cmdsize)
900returnmalformedError("load command " +Twine(LoadCommandIndex) +
901" LC_RPATH path.offset field extends past the end "
902"of the load command");
903// Make sure there is a null between the starting offset of the path and
904// the end of the load command.
905uint32_t i;
906constchar *P = (constchar *)Load.Ptr;
907for (i = R.path; i < R.cmdsize; i++)
908if (P[i] =='\0')
909break;
910if (i >= R.cmdsize)
911returnmalformedError("load command " +Twine(LoadCommandIndex) +
912" LC_RPATH library name extends past the end of the "
913"load command");
914returnError::success();
915}
916
917staticErrorcheckEncryptCommand(constMachOObjectFile &Obj,
918constMachOObjectFile::LoadCommandInfo &Load,
919uint32_t LoadCommandIndex,
920uint64_t cryptoff,uint64_t cryptsize,
921constchar **LoadCmd,constchar *CmdName) {
922if (*LoadCmd !=nullptr)
923returnmalformedError("more than one LC_ENCRYPTION_INFO and or "
924"LC_ENCRYPTION_INFO_64 command");
925uint64_t FileSize = Obj.getData().size();
926if (cryptoff > FileSize)
927returnmalformedError("cryptoff field of " +Twine(CmdName) +
928" command " +Twine(LoadCommandIndex) +" extends "
929"past the end of the file");
930uint64_t BigSize = cryptoff;
931 BigSize += cryptsize;
932if (BigSize > FileSize)
933returnmalformedError("cryptoff field plus cryptsize field of " +
934Twine(CmdName) +" command " +
935Twine(LoadCommandIndex) +" extends past the end of "
936"the file");
937 *LoadCmd = Load.Ptr;
938returnError::success();
939}
940
941staticErrorcheckLinkerOptCommand(constMachOObjectFile &Obj,
942constMachOObjectFile::LoadCommandInfo &Load,
943uint32_t LoadCommandIndex) {
944if (Load.C.cmdsize <sizeof(MachO::linker_option_command))
945returnmalformedError("load command " +Twine(LoadCommandIndex) +
946" LC_LINKER_OPTION cmdsize too small");
947auto LinkOptionOrErr =
948 getStructOrErr<MachO::linker_option_command>(Obj, Load.Ptr);
949if (!LinkOptionOrErr)
950return LinkOptionOrErr.takeError();
951MachO::linker_option_command L = LinkOptionOrErr.get();
952// Make sure the count of strings is correct.
953constchar *string = (constchar *)Load.Ptr +
954sizeof(structMachO::linker_option_command);
955uint32_t left = L.cmdsize -sizeof(structMachO::linker_option_command);
956uint32_t i = 0;
957while (left > 0) {
958while (*string =='\0' && left > 0) {
959string++;
960 left--;
961 }
962if (left > 0) {
963 i++;
964uint32_t NullPos =StringRef(string, left).find('\0');
965if (0xffffffff == NullPos)
966returnmalformedError("load command " +Twine(LoadCommandIndex) +
967" LC_LINKER_OPTION string #" +Twine(i) +
968" is not NULL terminated");
969uint32_t len = std::min(NullPos, left) + 1;
970string += len;
971 left -= len;
972 }
973 }
974if (L.count != i)
975returnmalformedError("load command " +Twine(LoadCommandIndex) +
976" LC_LINKER_OPTION string count " +Twine(L.count) +
977" does not match number of strings");
978returnError::success();
979}
980
981staticErrorcheckSubCommand(constMachOObjectFile &Obj,
982constMachOObjectFile::LoadCommandInfo &Load,
983uint32_t LoadCommandIndex,constchar *CmdName,
984size_t SizeOfCmd,constchar *CmdStructName,
985uint32_t PathOffset,constchar *PathFieldName) {
986if (PathOffset < SizeOfCmd)
987returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
988 CmdName +" " + PathFieldName +".offset field too "
989"small, not past the end of the " + CmdStructName);
990if (PathOffset >= Load.C.cmdsize)
991returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
992 CmdName +" " + PathFieldName +".offset field "
993"extends past the end of the load command");
994// Make sure there is a null between the starting offset of the path and
995// the end of the load command.
996uint32_t i;
997constchar *P = (constchar *)Load.Ptr;
998for (i = PathOffset; i < Load.C.cmdsize; i++)
999if (P[i] =='\0')
1000break;
1001if (i >= Load.C.cmdsize)
1002returnmalformedError("load command " +Twine(LoadCommandIndex) +" " +
1003 CmdName +" " + PathFieldName +" name extends past "
1004"the end of the load command");
1005returnError::success();
1006}
1007
1008staticErrorcheckThreadCommand(constMachOObjectFile &Obj,
1009constMachOObjectFile::LoadCommandInfo &Load,
1010uint32_t LoadCommandIndex,
1011constchar *CmdName) {
1012if (Load.C.cmdsize <sizeof(MachO::thread_command))
1013returnmalformedError("load command " +Twine(LoadCommandIndex) +
1014 CmdName +" cmdsize too small");
1015auto ThreadCommandOrErr =
1016 getStructOrErr<MachO::thread_command>(Obj, Load.Ptr);
1017if (!ThreadCommandOrErr)
1018return ThreadCommandOrErr.takeError();
1019MachO::thread_commandT = ThreadCommandOrErr.get();
1020constchar *state = Load.Ptr +sizeof(MachO::thread_command);
1021constchar *end = Load.Ptr +T.cmdsize;
1022uint32_t nflavor = 0;
1023uint32_t cputype =getCPUType(Obj);
1024while (state < end) {
1025if(state +sizeof(uint32_t) > end)
1026returnmalformedError("load command " +Twine(LoadCommandIndex) +
1027"flavor in " + CmdName +" extends past end of "
1028"command");
1029uint32_t flavor;
1030 memcpy(&flavor, state,sizeof(uint32_t));
1031if (Obj.isLittleEndian() !=sys::IsLittleEndianHost)
1032sys::swapByteOrder(flavor);
1033 state +=sizeof(uint32_t);
1034
1035if(state +sizeof(uint32_t) > end)
1036returnmalformedError("load command " +Twine(LoadCommandIndex) +
1037" count in " + CmdName +" extends past end of "
1038"command");
1039uint32_tcount;
1040 memcpy(&count, state,sizeof(uint32_t));
1041if (Obj.isLittleEndian() !=sys::IsLittleEndianHost)
1042sys::swapByteOrder(count);
1043 state +=sizeof(uint32_t);
1044
1045if (cputype ==MachO::CPU_TYPE_I386) {
1046if (flavor ==MachO::x86_THREAD_STATE32) {
1047if (count !=MachO::x86_THREAD_STATE32_COUNT)
1048returnmalformedError("load command " +Twine(LoadCommandIndex) +
1049" count not x86_THREAD_STATE32_COUNT for "
1050"flavor number " +Twine(nflavor) +" which is "
1051"a x86_THREAD_STATE32 flavor in " + CmdName +
1052" command");
1053if (state +sizeof(MachO::x86_thread_state32_t) > end)
1054returnmalformedError("load command " +Twine(LoadCommandIndex) +
1055" x86_THREAD_STATE32 extends past end of "
1056"command in " + CmdName +" command");
1057 state +=sizeof(MachO::x86_thread_state32_t);
1058 }else {
1059returnmalformedError("load command " +Twine(LoadCommandIndex) +
1060" unknown flavor (" +Twine(flavor) +") for "
1061"flavor number " +Twine(nflavor) +" in " +
1062 CmdName +" command");
1063 }
1064 }elseif (cputype ==MachO::CPU_TYPE_X86_64) {
1065if (flavor ==MachO::x86_THREAD_STATE) {
1066if (count !=MachO::x86_THREAD_STATE_COUNT)
1067returnmalformedError("load command " +Twine(LoadCommandIndex) +
1068" count not x86_THREAD_STATE_COUNT for "
1069"flavor number " +Twine(nflavor) +" which is "
1070"a x86_THREAD_STATE flavor in " + CmdName +
1071" command");
1072if (state +sizeof(MachO::x86_thread_state_t) > end)
1073returnmalformedError("load command " +Twine(LoadCommandIndex) +
1074" x86_THREAD_STATE extends past end of "
1075"command in " + CmdName +" command");
1076 state +=sizeof(MachO::x86_thread_state_t);
1077 }elseif (flavor ==MachO::x86_FLOAT_STATE) {
1078if (count !=MachO::x86_FLOAT_STATE_COUNT)
1079returnmalformedError("load command " +Twine(LoadCommandIndex) +
1080" count not x86_FLOAT_STATE_COUNT for "
1081"flavor number " +Twine(nflavor) +" which is "
1082"a x86_FLOAT_STATE flavor in " + CmdName +
1083" command");
1084if (state +sizeof(MachO::x86_float_state_t) > end)
1085returnmalformedError("load command " +Twine(LoadCommandIndex) +
1086" x86_FLOAT_STATE extends past end of "
1087"command in " + CmdName +" command");
1088 state +=sizeof(MachO::x86_float_state_t);
1089 }elseif (flavor ==MachO::x86_EXCEPTION_STATE) {
1090if (count !=MachO::x86_EXCEPTION_STATE_COUNT)
1091returnmalformedError("load command " +Twine(LoadCommandIndex) +
1092" count not x86_EXCEPTION_STATE_COUNT for "
1093"flavor number " +Twine(nflavor) +" which is "
1094"a x86_EXCEPTION_STATE flavor in " + CmdName +
1095" command");
1096if (state +sizeof(MachO::x86_exception_state_t) > end)
1097returnmalformedError("load command " +Twine(LoadCommandIndex) +
1098" x86_EXCEPTION_STATE extends past end of "
1099"command in " + CmdName +" command");
1100 state +=sizeof(MachO::x86_exception_state_t);
1101 }elseif (flavor ==MachO::x86_THREAD_STATE64) {
1102if (count !=MachO::x86_THREAD_STATE64_COUNT)
1103returnmalformedError("load command " +Twine(LoadCommandIndex) +
1104" count not x86_THREAD_STATE64_COUNT for "
1105"flavor number " +Twine(nflavor) +" which is "
1106"a x86_THREAD_STATE64 flavor in " + CmdName +
1107" command");
1108if (state +sizeof(MachO::x86_thread_state64_t) > end)
1109returnmalformedError("load command " +Twine(LoadCommandIndex) +
1110" x86_THREAD_STATE64 extends past end of "
1111"command in " + CmdName +" command");
1112 state +=sizeof(MachO::x86_thread_state64_t);
1113 }elseif (flavor ==MachO::x86_EXCEPTION_STATE64) {
1114if (count !=MachO::x86_EXCEPTION_STATE64_COUNT)
1115returnmalformedError("load command " +Twine(LoadCommandIndex) +
1116" count not x86_EXCEPTION_STATE64_COUNT for "
1117"flavor number " +Twine(nflavor) +" which is "
1118"a x86_EXCEPTION_STATE64 flavor in " + CmdName +
1119" command");
1120if (state +sizeof(MachO::x86_exception_state64_t) > end)
1121returnmalformedError("load command " +Twine(LoadCommandIndex) +
1122" x86_EXCEPTION_STATE64 extends past end of "
1123"command in " + CmdName +" command");
1124 state +=sizeof(MachO::x86_exception_state64_t);
1125 }else {
1126returnmalformedError("load command " +Twine(LoadCommandIndex) +
1127" unknown flavor (" +Twine(flavor) +") for "
1128"flavor number " +Twine(nflavor) +" in " +
1129 CmdName +" command");
1130 }
1131 }elseif (cputype ==MachO::CPU_TYPE_ARM) {
1132if (flavor ==MachO::ARM_THREAD_STATE) {
1133if (count !=MachO::ARM_THREAD_STATE_COUNT)
1134returnmalformedError("load command " +Twine(LoadCommandIndex) +
1135" count not ARM_THREAD_STATE_COUNT for "
1136"flavor number " +Twine(nflavor) +" which is "
1137"a ARM_THREAD_STATE flavor in " + CmdName +
1138" command");
1139if (state +sizeof(MachO::arm_thread_state32_t) > end)
1140returnmalformedError("load command " +Twine(LoadCommandIndex) +
1141" ARM_THREAD_STATE extends past end of "
1142"command in " + CmdName +" command");
1143 state +=sizeof(MachO::arm_thread_state32_t);
1144 }else {
1145returnmalformedError("load command " +Twine(LoadCommandIndex) +
1146" unknown flavor (" +Twine(flavor) +") for "
1147"flavor number " +Twine(nflavor) +" in " +
1148 CmdName +" command");
1149 }
1150 }elseif (cputype ==MachO::CPU_TYPE_ARM64 ||
1151 cputype ==MachO::CPU_TYPE_ARM64_32) {
1152if (flavor ==MachO::ARM_THREAD_STATE64) {
1153if (count !=MachO::ARM_THREAD_STATE64_COUNT)
1154returnmalformedError("load command " +Twine(LoadCommandIndex) +
1155" count not ARM_THREAD_STATE64_COUNT for "
1156"flavor number " +Twine(nflavor) +" which is "
1157"a ARM_THREAD_STATE64 flavor in " + CmdName +
1158" command");
1159if (state +sizeof(MachO::arm_thread_state64_t) > end)
1160returnmalformedError("load command " +Twine(LoadCommandIndex) +
1161" ARM_THREAD_STATE64 extends past end of "
1162"command in " + CmdName +" command");
1163 state +=sizeof(MachO::arm_thread_state64_t);
1164 }else {
1165returnmalformedError("load command " +Twine(LoadCommandIndex) +
1166" unknown flavor (" +Twine(flavor) +") for "
1167"flavor number " +Twine(nflavor) +" in " +
1168 CmdName +" command");
1169 }
1170 }elseif (cputype ==MachO::CPU_TYPE_POWERPC) {
1171if (flavor ==MachO::PPC_THREAD_STATE) {
1172if (count !=MachO::PPC_THREAD_STATE_COUNT)
1173returnmalformedError("load command " +Twine(LoadCommandIndex) +
1174" count not PPC_THREAD_STATE_COUNT for "
1175"flavor number " +Twine(nflavor) +" which is "
1176"a PPC_THREAD_STATE flavor in " + CmdName +
1177" command");
1178if (state +sizeof(MachO::ppc_thread_state32_t) > end)
1179returnmalformedError("load command " +Twine(LoadCommandIndex) +
1180" PPC_THREAD_STATE extends past end of "
1181"command in " + CmdName +" command");
1182 state +=sizeof(MachO::ppc_thread_state32_t);
1183 }else {
1184returnmalformedError("load command " +Twine(LoadCommandIndex) +
1185" unknown flavor (" +Twine(flavor) +") for "
1186"flavor number " +Twine(nflavor) +" in " +
1187 CmdName +" command");
1188 }
1189 }else {
1190returnmalformedError("unknown cputype (" +Twine(cputype) +") load "
1191"command " +Twine(LoadCommandIndex) +" for " +
1192 CmdName +" command can't be checked");
1193 }
1194 nflavor++;
1195 }
1196returnError::success();
1197}
1198
1199staticErrorcheckTwoLevelHintsCommand(constMachOObjectFile &Obj,
1200constMachOObjectFile::LoadCommandInfo
1201 &Load,
1202uint32_t LoadCommandIndex,
1203constchar **LoadCmd,
1204 std::list<MachOElement> &Elements) {
1205if (Load.C.cmdsize !=sizeof(MachO::twolevel_hints_command))
1206returnmalformedError("load command " +Twine(LoadCommandIndex) +
1207" LC_TWOLEVEL_HINTS has incorrect cmdsize");
1208if (*LoadCmd !=nullptr)
1209returnmalformedError("more than one LC_TWOLEVEL_HINTS command");
1210auto HintsOrErr = getStructOrErr<MachO::twolevel_hints_command>(Obj, Load.Ptr);
1211if(!HintsOrErr)
1212return HintsOrErr.takeError();
1213MachO::twolevel_hints_command Hints = HintsOrErr.get();
1214uint64_t FileSize = Obj.getData().size();
1215if (Hints.offset > FileSize)
1216returnmalformedError("offset field of LC_TWOLEVEL_HINTS command " +
1217Twine(LoadCommandIndex) +" extends past the end of "
1218"the file");
1219uint64_t BigSize = Hints.nhints;
1220 BigSize *=sizeof(MachO::twolevel_hint);
1221 BigSize += Hints.offset;
1222if (BigSize > FileSize)
1223returnmalformedError("offset field plus nhints times sizeof(struct "
1224"twolevel_hint) field of LC_TWOLEVEL_HINTS command " +
1225Twine(LoadCommandIndex) +" extends past the end of "
1226"the file");
1227if (Error Err =checkOverlappingElement(Elements, Hints.offset, Hints.nhints *
1228sizeof(MachO::twolevel_hint),
1229"two level hints"))
1230return Err;
1231 *LoadCmd = Load.Ptr;
1232returnError::success();
1233}
1234
1235// Returns true if the libObject code does not support the load command and its
1236// contents. The cmd value it is treated as an unknown load command but with
1237// an error message that says the cmd value is obsolete.
1238staticboolisLoadCommandObsolete(uint32_tcmd) {
1239if (cmd == MachO::LC_SYMSEG ||
1240cmd == MachO::LC_LOADFVMLIB ||
1241cmd == MachO::LC_IDFVMLIB ||
1242cmd == MachO::LC_IDENT ||
1243cmd == MachO::LC_FVMFILE ||
1244cmd == MachO::LC_PREPAGE ||
1245cmd == MachO::LC_PREBOUND_DYLIB ||
1246cmd == MachO::LC_TWOLEVEL_HINTS ||
1247cmd == MachO::LC_PREBIND_CKSUM)
1248returntrue;
1249returnfalse;
1250}
1251
1252Expected<std::unique_ptr<MachOObjectFile>>
1253MachOObjectFile::create(MemoryBufferRef Object,bool IsLittleEndian,
1254bool Is64Bits,uint32_t UniversalCputype,
1255uint32_t UniversalIndex,
1256size_t MachOFilesetEntryOffset) {
1257Error Err =Error::success();
1258 std::unique_ptr<MachOObjectFile> Obj(newMachOObjectFile(
1259 std::move(Object), IsLittleEndian, Is64Bits, Err, UniversalCputype,
1260 UniversalIndex, MachOFilesetEntryOffset));
1261if (Err)
1262return std::move(Err);
1263return std::move(Obj);
1264}
1265
1266MachOObjectFile::MachOObjectFile(MemoryBufferRef Object,bool IsLittleEndian,
1267bool Is64bits,Error &Err,
1268uint32_t UniversalCputype,
1269uint32_t UniversalIndex,
1270size_t MachOFilesetEntryOffset)
1271 :ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object),
1272 MachOFilesetEntryOffset(MachOFilesetEntryOffset) {
1273ErrorAsOutParameter ErrAsOutParam(Err);
1274uint64_t SizeOfHeaders;
1275uint32_t cputype;
1276if (is64Bit()) {
1277parseHeader(*this,Header64, Err);
1278 SizeOfHeaders =sizeof(MachO::mach_header_64);
1279 cputype =Header64.cputype;
1280 }else {
1281parseHeader(*this,Header, Err);
1282 SizeOfHeaders =sizeof(MachO::mach_header);
1283 cputype =Header.cputype;
1284 }
1285if (Err)
1286return;
1287 SizeOfHeaders +=getHeader().sizeofcmds;
1288if (getData().data() + SizeOfHeaders >getData().end()) {
1289 Err =malformedError("load commands extend past the end of the file");
1290return;
1291 }
1292if (UniversalCputype != 0 && cputype != UniversalCputype) {
1293 Err =malformedError("universal header architecture: " +
1294Twine(UniversalIndex) +"'s cputype does not match "
1295"object file's mach header");
1296return;
1297 }
1298 std::list<MachOElement>Elements;
1299Elements.push_back({0, SizeOfHeaders,"Mach-O headers"});
1300
1301uint32_t LoadCommandCount =getHeader().ncmds;
1302 LoadCommandInfoLoad;
1303if (LoadCommandCount != 0) {
1304if (auto LoadOrErr =getFirstLoadCommandInfo(*this))
1305Load = *LoadOrErr;
1306else {
1307 Err = LoadOrErr.takeError();
1308return;
1309 }
1310 }
1311
1312constchar *DyldIdLoadCmd =nullptr;
1313constchar *SplitInfoLoadCmd =nullptr;
1314constchar *CodeSignDrsLoadCmd =nullptr;
1315constchar *CodeSignLoadCmd =nullptr;
1316constchar *VersLoadCmd =nullptr;
1317constchar *SourceLoadCmd =nullptr;
1318constchar *EntryPointLoadCmd =nullptr;
1319constchar *EncryptLoadCmd =nullptr;
1320constchar *RoutinesLoadCmd =nullptr;
1321constchar *UnixThreadLoadCmd =nullptr;
1322constchar *TwoLevelHintsLoadCmd =nullptr;
1323for (unsignedI = 0;I < LoadCommandCount; ++I) {
1324if (is64Bit()) {
1325if (Load.C.cmdsize % 8 != 0) {
1326// We have a hack here to allow 64-bit Mach-O core files to have
1327// LC_THREAD commands that are only a multiple of 4 and not 8 to be
1328// allowed since the macOS kernel produces them.
1329if (getHeader().filetype !=MachO::MH_CORE ||
1330Load.C.cmd != MachO::LC_THREAD ||Load.C.cmdsize % 4) {
1331 Err =malformedError("load command " +Twine(I) +" cmdsize not a "
1332"multiple of 8");
1333return;
1334 }
1335 }
1336 }else {
1337if (Load.C.cmdsize % 4 != 0) {
1338 Err =malformedError("load command " +Twine(I) +" cmdsize not a "
1339"multiple of 4");
1340return;
1341 }
1342 }
1343 LoadCommands.push_back(Load);
1344if (Load.C.cmd == MachO::LC_SYMTAB) {
1345if ((Err =checkSymtabCommand(*this, Load,I, &SymtabLoadCmd, Elements)))
1346return;
1347 }elseif (Load.C.cmd == MachO::LC_DYSYMTAB) {
1348if ((Err =checkDysymtabCommand(*this, Load,I, &DysymtabLoadCmd,
1349 Elements)))
1350return;
1351 }elseif (Load.C.cmd == MachO::LC_DATA_IN_CODE) {
1352if ((Err =checkLinkeditDataCommand(*this, Load,I, &DataInCodeLoadCmd,
1353"LC_DATA_IN_CODE", Elements,
1354"data in code info")))
1355return;
1356 }elseif (Load.C.cmd == MachO::LC_LINKER_OPTIMIZATION_HINT) {
1357if ((Err =checkLinkeditDataCommand(*this, Load,I, &LinkOptHintsLoadCmd,
1358"LC_LINKER_OPTIMIZATION_HINT",
1359 Elements,"linker optimization "
1360"hints")))
1361return;
1362 }elseif (Load.C.cmd == MachO::LC_FUNCTION_STARTS) {
1363if ((Err =checkLinkeditDataCommand(*this, Load,I, &FuncStartsLoadCmd,
1364"LC_FUNCTION_STARTS", Elements,
1365"function starts data")))
1366return;
1367 }elseif (Load.C.cmd == MachO::LC_SEGMENT_SPLIT_INFO) {
1368if ((Err =checkLinkeditDataCommand(*this, Load,I, &SplitInfoLoadCmd,
1369"LC_SEGMENT_SPLIT_INFO", Elements,
1370"split info data")))
1371return;
1372 }elseif (Load.C.cmd == MachO::LC_DYLIB_CODE_SIGN_DRS) {
1373if ((Err =checkLinkeditDataCommand(*this, Load,I, &CodeSignDrsLoadCmd,
1374"LC_DYLIB_CODE_SIGN_DRS", Elements,
1375"code signing RDs data")))
1376return;
1377 }elseif (Load.C.cmd == MachO::LC_CODE_SIGNATURE) {
1378if ((Err =checkLinkeditDataCommand(*this, Load,I, &CodeSignLoadCmd,
1379"LC_CODE_SIGNATURE", Elements,
1380"code signature data")))
1381return;
1382 }elseif (Load.C.cmd == MachO::LC_DYLD_INFO) {
1383if ((Err =checkDyldInfoCommand(*this, Load,I, &DyldInfoLoadCmd,
1384"LC_DYLD_INFO", Elements)))
1385return;
1386 }elseif (Load.C.cmd == MachO::LC_DYLD_INFO_ONLY) {
1387if ((Err =checkDyldInfoCommand(*this, Load,I, &DyldInfoLoadCmd,
1388"LC_DYLD_INFO_ONLY", Elements)))
1389return;
1390 }elseif (Load.C.cmd == MachO::LC_DYLD_CHAINED_FIXUPS) {
1391if ((Err =checkLinkeditDataCommand(
1392 *this, Load,I, &DyldChainedFixupsLoadCmd,
1393"LC_DYLD_CHAINED_FIXUPS", Elements,"chained fixups")))
1394return;
1395 }elseif (Load.C.cmd == MachO::LC_DYLD_EXPORTS_TRIE) {
1396if ((Err =checkLinkeditDataCommand(
1397 *this, Load,I, &DyldExportsTrieLoadCmd,"LC_DYLD_EXPORTS_TRIE",
1398 Elements,"exports trie")))
1399return;
1400 }elseif (Load.C.cmd == MachO::LC_UUID) {
1401if (Load.C.cmdsize !=sizeof(MachO::uuid_command)) {
1402 Err =malformedError("LC_UUID command " +Twine(I) +" has incorrect "
1403"cmdsize");
1404return;
1405 }
1406if (UuidLoadCmd) {
1407 Err =malformedError("more than one LC_UUID command");
1408return;
1409 }
1410 UuidLoadCmd =Load.Ptr;
1411 }elseif (Load.C.cmd == MachO::LC_SEGMENT_64) {
1412if ((Err =parseSegmentLoadCommand<MachO::segment_command_64,
1413MachO::section_64>(
1414 *this, Load, Sections, HasPageZeroSegment,I,
1415"LC_SEGMENT_64", SizeOfHeaders, Elements)))
1416return;
1417 }elseif (Load.C.cmd == MachO::LC_SEGMENT) {
1418if ((Err =parseSegmentLoadCommand<MachO::segment_command,
1419MachO::section>(
1420 *this, Load, Sections, HasPageZeroSegment,I,
1421"LC_SEGMENT", SizeOfHeaders, Elements)))
1422return;
1423 }elseif (Load.C.cmd == MachO::LC_ID_DYLIB) {
1424if ((Err =checkDylibIdCommand(*this, Load,I, &DyldIdLoadCmd)))
1425return;
1426 }elseif (Load.C.cmd == MachO::LC_LOAD_DYLIB) {
1427if ((Err =checkDylibCommand(*this, Load,I,"LC_LOAD_DYLIB")))
1428return;
1429 Libraries.push_back(Load.Ptr);
1430 }elseif (Load.C.cmd == MachO::LC_LOAD_WEAK_DYLIB) {
1431if ((Err =checkDylibCommand(*this, Load,I,"LC_LOAD_WEAK_DYLIB")))
1432return;
1433 Libraries.push_back(Load.Ptr);
1434 }elseif (Load.C.cmd == MachO::LC_LAZY_LOAD_DYLIB) {
1435if ((Err =checkDylibCommand(*this, Load,I,"LC_LAZY_LOAD_DYLIB")))
1436return;
1437 Libraries.push_back(Load.Ptr);
1438 }elseif (Load.C.cmd == MachO::LC_REEXPORT_DYLIB) {
1439if ((Err =checkDylibCommand(*this, Load,I,"LC_REEXPORT_DYLIB")))
1440return;
1441 Libraries.push_back(Load.Ptr);
1442 }elseif (Load.C.cmd == MachO::LC_LOAD_UPWARD_DYLIB) {
1443if ((Err =checkDylibCommand(*this, Load,I,"LC_LOAD_UPWARD_DYLIB")))
1444return;
1445 Libraries.push_back(Load.Ptr);
1446 }elseif (Load.C.cmd == MachO::LC_ID_DYLINKER) {
1447if ((Err =checkDyldCommand(*this, Load,I,"LC_ID_DYLINKER")))
1448return;
1449 }elseif (Load.C.cmd == MachO::LC_LOAD_DYLINKER) {
1450if ((Err =checkDyldCommand(*this, Load,I,"LC_LOAD_DYLINKER")))
1451return;
1452 }elseif (Load.C.cmd == MachO::LC_DYLD_ENVIRONMENT) {
1453if ((Err =checkDyldCommand(*this, Load,I,"LC_DYLD_ENVIRONMENT")))
1454return;
1455 }elseif (Load.C.cmd == MachO::LC_VERSION_MIN_MACOSX) {
1456if ((Err =checkVersCommand(*this, Load,I, &VersLoadCmd,
1457"LC_VERSION_MIN_MACOSX")))
1458return;
1459 }elseif (Load.C.cmd == MachO::LC_VERSION_MIN_IPHONEOS) {
1460if ((Err =checkVersCommand(*this, Load,I, &VersLoadCmd,
1461"LC_VERSION_MIN_IPHONEOS")))
1462return;
1463 }elseif (Load.C.cmd == MachO::LC_VERSION_MIN_TVOS) {
1464if ((Err =checkVersCommand(*this, Load,I, &VersLoadCmd,
1465"LC_VERSION_MIN_TVOS")))
1466return;
1467 }elseif (Load.C.cmd == MachO::LC_VERSION_MIN_WATCHOS) {
1468if ((Err =checkVersCommand(*this, Load,I, &VersLoadCmd,
1469"LC_VERSION_MIN_WATCHOS")))
1470return;
1471 }elseif (Load.C.cmd == MachO::LC_NOTE) {
1472if ((Err =checkNoteCommand(*this, Load,I, Elements)))
1473return;
1474 }elseif (Load.C.cmd == MachO::LC_BUILD_VERSION) {
1475if ((Err =parseBuildVersionCommand(*this, Load, BuildTools,I)))
1476return;
1477 }elseif (Load.C.cmd == MachO::LC_RPATH) {
1478if ((Err =checkRpathCommand(*this, Load,I)))
1479return;
1480 }elseif (Load.C.cmd == MachO::LC_SOURCE_VERSION) {
1481if (Load.C.cmdsize !=sizeof(MachO::source_version_command)) {
1482 Err =malformedError("LC_SOURCE_VERSION command " +Twine(I) +
1483" has incorrect cmdsize");
1484return;
1485 }
1486if (SourceLoadCmd) {
1487 Err =malformedError("more than one LC_SOURCE_VERSION command");
1488return;
1489 }
1490 SourceLoadCmd =Load.Ptr;
1491 }elseif (Load.C.cmd == MachO::LC_MAIN) {
1492if (Load.C.cmdsize !=sizeof(MachO::entry_point_command)) {
1493 Err =malformedError("LC_MAIN command " +Twine(I) +
1494" has incorrect cmdsize");
1495return;
1496 }
1497if (EntryPointLoadCmd) {
1498 Err =malformedError("more than one LC_MAIN command");
1499return;
1500 }
1501 EntryPointLoadCmd =Load.Ptr;
1502 }elseif (Load.C.cmd == MachO::LC_ENCRYPTION_INFO) {
1503if (Load.C.cmdsize !=sizeof(MachO::encryption_info_command)) {
1504 Err =malformedError("LC_ENCRYPTION_INFO command " +Twine(I) +
1505" has incorrect cmdsize");
1506return;
1507 }
1508MachO::encryption_info_commandE =
1509 getStruct<MachO::encryption_info_command>(*this,Load.Ptr);
1510if ((Err =checkEncryptCommand(*this, Load,I,E.cryptoff,E.cryptsize,
1511 &EncryptLoadCmd,"LC_ENCRYPTION_INFO")))
1512return;
1513 }elseif (Load.C.cmd == MachO::LC_ENCRYPTION_INFO_64) {
1514if (Load.C.cmdsize !=sizeof(MachO::encryption_info_command_64)) {
1515 Err =malformedError("LC_ENCRYPTION_INFO_64 command " +Twine(I) +
1516" has incorrect cmdsize");
1517return;
1518 }
1519MachO::encryption_info_command_64E =
1520 getStruct<MachO::encryption_info_command_64>(*this,Load.Ptr);
1521if ((Err =checkEncryptCommand(*this, Load,I,E.cryptoff,E.cryptsize,
1522 &EncryptLoadCmd,"LC_ENCRYPTION_INFO_64")))
1523return;
1524 }elseif (Load.C.cmd == MachO::LC_LINKER_OPTION) {
1525if ((Err =checkLinkerOptCommand(*this, Load,I)))
1526return;
1527 }elseif (Load.C.cmd == MachO::LC_SUB_FRAMEWORK) {
1528if (Load.C.cmdsize <sizeof(MachO::sub_framework_command)) {
1529 Err =malformedError("load command " +Twine(I) +
1530" LC_SUB_FRAMEWORK cmdsize too small");
1531return;
1532 }
1533MachO::sub_framework_command S =
1534 getStruct<MachO::sub_framework_command>(*this,Load.Ptr);
1535if ((Err =checkSubCommand(*this, Load,I,"LC_SUB_FRAMEWORK",
1536sizeof(MachO::sub_framework_command),
1537"sub_framework_command", S.umbrella,
1538"umbrella")))
1539return;
1540 }elseif (Load.C.cmd == MachO::LC_SUB_UMBRELLA) {
1541if (Load.C.cmdsize <sizeof(MachO::sub_umbrella_command)) {
1542 Err =malformedError("load command " +Twine(I) +
1543" LC_SUB_UMBRELLA cmdsize too small");
1544return;
1545 }
1546MachO::sub_umbrella_command S =
1547 getStruct<MachO::sub_umbrella_command>(*this,Load.Ptr);
1548if ((Err =checkSubCommand(*this, Load,I,"LC_SUB_UMBRELLA",
1549sizeof(MachO::sub_umbrella_command),
1550"sub_umbrella_command", S.sub_umbrella,
1551"sub_umbrella")))
1552return;
1553 }elseif (Load.C.cmd == MachO::LC_SUB_LIBRARY) {
1554if (Load.C.cmdsize <sizeof(MachO::sub_library_command)) {
1555 Err =malformedError("load command " +Twine(I) +
1556" LC_SUB_LIBRARY cmdsize too small");
1557return;
1558 }
1559MachO::sub_library_command S =
1560 getStruct<MachO::sub_library_command>(*this,Load.Ptr);
1561if ((Err =checkSubCommand(*this, Load,I,"LC_SUB_LIBRARY",
1562sizeof(MachO::sub_library_command),
1563"sub_library_command", S.sub_library,
1564"sub_library")))
1565return;
1566 }elseif (Load.C.cmd == MachO::LC_SUB_CLIENT) {
1567if (Load.C.cmdsize <sizeof(MachO::sub_client_command)) {
1568 Err =malformedError("load command " +Twine(I) +
1569" LC_SUB_CLIENT cmdsize too small");
1570return;
1571 }
1572MachO::sub_client_command S =
1573 getStruct<MachO::sub_client_command>(*this,Load.Ptr);
1574if ((Err =checkSubCommand(*this, Load,I,"LC_SUB_CLIENT",
1575sizeof(MachO::sub_client_command),
1576"sub_client_command", S.client,"client")))
1577return;
1578 }elseif (Load.C.cmd == MachO::LC_ROUTINES) {
1579if (Load.C.cmdsize !=sizeof(MachO::routines_command)) {
1580 Err =malformedError("LC_ROUTINES command " +Twine(I) +
1581" has incorrect cmdsize");
1582return;
1583 }
1584if (RoutinesLoadCmd) {
1585 Err =malformedError("more than one LC_ROUTINES and or LC_ROUTINES_64 "
1586"command");
1587return;
1588 }
1589 RoutinesLoadCmd =Load.Ptr;
1590 }elseif (Load.C.cmd == MachO::LC_ROUTINES_64) {
1591if (Load.C.cmdsize !=sizeof(MachO::routines_command_64)) {
1592 Err =malformedError("LC_ROUTINES_64 command " +Twine(I) +
1593" has incorrect cmdsize");
1594return;
1595 }
1596if (RoutinesLoadCmd) {
1597 Err =malformedError("more than one LC_ROUTINES_64 and or LC_ROUTINES "
1598"command");
1599return;
1600 }
1601 RoutinesLoadCmd =Load.Ptr;
1602 }elseif (Load.C.cmd == MachO::LC_UNIXTHREAD) {
1603if ((Err =checkThreadCommand(*this, Load,I,"LC_UNIXTHREAD")))
1604return;
1605if (UnixThreadLoadCmd) {
1606 Err =malformedError("more than one LC_UNIXTHREAD command");
1607return;
1608 }
1609 UnixThreadLoadCmd =Load.Ptr;
1610 }elseif (Load.C.cmd == MachO::LC_THREAD) {
1611if ((Err =checkThreadCommand(*this, Load,I,"LC_THREAD")))
1612return;
1613// Note: LC_TWOLEVEL_HINTS is really obsolete and is not supported.
1614 }elseif (Load.C.cmd == MachO::LC_TWOLEVEL_HINTS) {
1615if ((Err =checkTwoLevelHintsCommand(*this, Load,I,
1616 &TwoLevelHintsLoadCmd, Elements)))
1617return;
1618 }elseif (Load.C.cmd == MachO::LC_IDENT) {
1619// Note: LC_IDENT is ignored.
1620continue;
1621 }elseif (isLoadCommandObsolete(Load.C.cmd)) {
1622 Err =malformedError("load command " +Twine(I) +" for cmd value of: " +
1623Twine(Load.C.cmd) +" is obsolete and not "
1624"supported");
1625return;
1626 }
1627// TODO: generate a error for unknown load commands by default. But still
1628// need work out an approach to allow or not allow unknown values like this
1629// as an option for some uses like lldb.
1630if (I < LoadCommandCount - 1) {
1631if (auto LoadOrErr =getNextLoadCommandInfo(*this,I, Load))
1632Load = *LoadOrErr;
1633else {
1634 Err = LoadOrErr.takeError();
1635return;
1636 }
1637 }
1638 }
1639if (!SymtabLoadCmd) {
1640if (DysymtabLoadCmd) {
1641 Err =malformedError("contains LC_DYSYMTAB load command without a "
1642"LC_SYMTAB load command");
1643return;
1644 }
1645 }elseif (DysymtabLoadCmd) {
1646MachO::symtab_command Symtab =
1647 getStruct<MachO::symtab_command>(*this, SymtabLoadCmd);
1648MachO::dysymtab_command Dysymtab =
1649 getStruct<MachO::dysymtab_command>(*this, DysymtabLoadCmd);
1650if (Dysymtab.nlocalsym != 0 && Dysymtab.ilocalsym > Symtab.nsyms) {
1651 Err =malformedError("ilocalsym in LC_DYSYMTAB load command "
1652"extends past the end of the symbol table");
1653return;
1654 }
1655uint64_t BigSize = Dysymtab.ilocalsym;
1656 BigSize += Dysymtab.nlocalsym;
1657if (Dysymtab.nlocalsym != 0 && BigSize > Symtab.nsyms) {
1658 Err =malformedError("ilocalsym plus nlocalsym in LC_DYSYMTAB load "
1659"command extends past the end of the symbol table");
1660return;
1661 }
1662if (Dysymtab.nextdefsym != 0 && Dysymtab.iextdefsym > Symtab.nsyms) {
1663 Err =malformedError("iextdefsym in LC_DYSYMTAB load command "
1664"extends past the end of the symbol table");
1665return;
1666 }
1667 BigSize = Dysymtab.iextdefsym;
1668 BigSize += Dysymtab.nextdefsym;
1669if (Dysymtab.nextdefsym != 0 && BigSize > Symtab.nsyms) {
1670 Err =malformedError("iextdefsym plus nextdefsym in LC_DYSYMTAB "
1671"load command extends past the end of the symbol "
1672"table");
1673return;
1674 }
1675if (Dysymtab.nundefsym != 0 && Dysymtab.iundefsym > Symtab.nsyms) {
1676 Err =malformedError("iundefsym in LC_DYSYMTAB load command "
1677"extends past the end of the symbol table");
1678return;
1679 }
1680 BigSize = Dysymtab.iundefsym;
1681 BigSize += Dysymtab.nundefsym;
1682if (Dysymtab.nundefsym != 0 && BigSize > Symtab.nsyms) {
1683 Err =malformedError("iundefsym plus nundefsym in LC_DYSYMTAB load "
1684" command extends past the end of the symbol table");
1685return;
1686 }
1687 }
1688if ((getHeader().filetype ==MachO::MH_DYLIB ||
1689getHeader().filetype ==MachO::MH_DYLIB_STUB) &&
1690 DyldIdLoadCmd ==nullptr) {
1691 Err =malformedError("no LC_ID_DYLIB load command in dynamic library "
1692"filetype");
1693return;
1694 }
1695assert(LoadCommands.size() == LoadCommandCount);
1696
1697 Err =Error::success();
1698}
1699
1700ErrorMachOObjectFile::checkSymbolTable() const{
1701uint32_t Flags = 0;
1702if (is64Bit()) {
1703MachO::mach_header_64 H_64 =MachOObjectFile::getHeader64();
1704 Flags = H_64.flags;
1705 }else {
1706MachO::mach_headerH =MachOObjectFile::getHeader();
1707 Flags =H.flags;
1708 }
1709uint8_t NType = 0;
1710uint8_t NSect = 0;
1711uint16_t NDesc = 0;
1712uint32_t NStrx = 0;
1713uint64_t NValue = 0;
1714uint32_t SymbolIndex = 0;
1715MachO::symtab_command S =getSymtabLoadCommand();
1716for (constSymbolRef &Symbol :symbols()) {
1717DataRefImpl SymDRI = Symbol.getRawDataRefImpl();
1718if (is64Bit()) {
1719MachO::nlist_64 STE_64 =getSymbol64TableEntry(SymDRI);
1720 NType = STE_64.n_type;
1721 NSect = STE_64.n_sect;
1722 NDesc = STE_64.n_desc;
1723 NStrx = STE_64.n_strx;
1724 NValue = STE_64.n_value;
1725 }else {
1726MachO::nlist STE =getSymbolTableEntry(SymDRI);
1727 NType = STE.n_type;
1728 NSect = STE.n_sect;
1729 NDesc = STE.n_desc;
1730 NStrx = STE.n_strx;
1731 NValue = STE.n_value;
1732 }
1733if ((NType &MachO::N_STAB) == 0) {
1734if ((NType &MachO::N_TYPE) ==MachO::N_SECT) {
1735if (NSect == 0 || NSect > Sections.size())
1736returnmalformedError("bad section index: " +Twine((int)NSect) +
1737" for symbol at index " +Twine(SymbolIndex));
1738 }
1739if ((NType &MachO::N_TYPE) ==MachO::N_INDR) {
1740if (NValue >= S.strsize)
1741returnmalformedError("bad n_value: " +Twine((int)NValue) +" past "
1742"the end of string table, for N_INDR symbol at "
1743"index " +Twine(SymbolIndex));
1744 }
1745if ((Flags &MachO::MH_TWOLEVEL) ==MachO::MH_TWOLEVEL &&
1746 (((NType &MachO::N_TYPE) ==MachO::N_UNDF && NValue == 0) ||
1747 (NType &MachO::N_TYPE) ==MachO::N_PBUD)) {
1748uint32_t LibraryOrdinal =MachO::GET_LIBRARY_ORDINAL(NDesc);
1749if (LibraryOrdinal != 0 &&
1750 LibraryOrdinal !=MachO::EXECUTABLE_ORDINAL &&
1751 LibraryOrdinal !=MachO::DYNAMIC_LOOKUP_ORDINAL &&
1752 LibraryOrdinal - 1 >= Libraries.size() ) {
1753returnmalformedError("bad library ordinal: " +Twine(LibraryOrdinal) +
1754" for symbol at index " +Twine(SymbolIndex));
1755 }
1756 }
1757 }
1758if (NStrx >= S.strsize)
1759returnmalformedError("bad string table index: " +Twine((int)NStrx) +
1760" past the end of string table, for symbol at "
1761"index " +Twine(SymbolIndex));
1762 SymbolIndex++;
1763 }
1764returnError::success();
1765}
1766
1767voidMachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const{
1768unsignedSymbolTableEntrySize =is64Bit() ?
1769sizeof(MachO::nlist_64) :
1770sizeof(MachO::nlist);
1771 Symb.p +=SymbolTableEntrySize;
1772}
1773
1774Expected<StringRef>MachOObjectFile::getSymbolName(DataRefImpl Symb) const{
1775StringRefStringTable =getStringTableData();
1776MachO::nlist_base Entry =getSymbolTableEntryBase(*this, Symb);
1777if (Entry.n_strx == 0)
1778// A n_strx value of 0 indicates that no name is associated with a
1779// particular symbol table entry.
1780returnStringRef();
1781constchar *Start = &StringTable.data()[Entry.n_strx];
1782if (Start <getData().begin() || Start >=getData().end()) {
1783returnmalformedError("bad string index: " +Twine(Entry.n_strx) +
1784" for symbol at index " +Twine(getSymbolIndex(Symb)));
1785 }
1786returnStringRef(Start);
1787}
1788
1789unsignedMachOObjectFile::getSectionType(SectionRef Sec) const{
1790DataRefImpl DRI = Sec.getRawDataRefImpl();
1791uint32_t Flags =getSectionFlags(*this, DRI);
1792return Flags &MachO::SECTION_TYPE;
1793}
1794
1795uint64_tMachOObjectFile::getNValue(DataRefImplSym) const{
1796if (is64Bit()) {
1797MachO::nlist_64 Entry =getSymbol64TableEntry(Sym);
1798return Entry.n_value;
1799 }
1800MachO::nlist Entry =getSymbolTableEntry(Sym);
1801return Entry.n_value;
1802}
1803
1804// getIndirectName() returns the name of the alias'ed symbol who's string table
1805// index is in the n_value field.
1806std::error_codeMachOObjectFile::getIndirectName(DataRefImpl Symb,
1807StringRef &Res) const{
1808StringRefStringTable =getStringTableData();
1809MachO::nlist_base Entry =getSymbolTableEntryBase(*this, Symb);
1810if ((Entry.n_type &MachO::N_TYPE) !=MachO::N_INDR)
1811returnobject_error::parse_failed;
1812uint64_t NValue =getNValue(Symb);
1813if (NValue >=StringTable.size())
1814returnobject_error::parse_failed;
1815constchar *Start = &StringTable.data()[NValue];
1816 Res =StringRef(Start);
1817return std::error_code();
1818}
1819
1820uint64_t MachOObjectFile::getSymbolValueImpl(DataRefImplSym) const{
1821returngetNValue(Sym);
1822}
1823
1824Expected<uint64_t>MachOObjectFile::getSymbolAddress(DataRefImplSym) const{
1825returngetSymbolValue(Sym);
1826}
1827
1828uint32_tMachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const{
1829uint32_t Flags =cantFail(getSymbolFlags(DRI));
1830if (Flags &SymbolRef::SF_Common) {
1831MachO::nlist_base Entry =getSymbolTableEntryBase(*this, DRI);
1832return 1 <<MachO::GET_COMM_ALIGN(Entry.n_desc);
1833 }
1834return 0;
1835}
1836
1837uint64_tMachOObjectFile::getCommonSymbolSizeImpl(DataRefImpl DRI) const{
1838returngetNValue(DRI);
1839}
1840
1841Expected<SymbolRef::Type>
1842MachOObjectFile::getSymbolType(DataRefImpl Symb) const{
1843MachO::nlist_base Entry =getSymbolTableEntryBase(*this, Symb);
1844uint8_t n_type = Entry.n_type;
1845
1846// If this is a STAB debugging symbol, we can do nothing more.
1847if (n_type &MachO::N_STAB)
1848returnSymbolRef::ST_Debug;
1849
1850switch (n_type &MachO::N_TYPE) {
1851caseMachO::N_UNDF :
1852returnSymbolRef::ST_Unknown;
1853caseMachO::N_SECT :
1854Expected<section_iterator> SecOrError =getSymbolSection(Symb);
1855if (!SecOrError)
1856return SecOrError.takeError();
1857section_iterator Sec = *SecOrError;
1858if (Sec ==section_end())
1859returnSymbolRef::ST_Other;
1860if (Sec->isData() || Sec->isBSS())
1861returnSymbolRef::ST_Data;
1862returnSymbolRef::ST_Function;
1863 }
1864returnSymbolRef::ST_Other;
1865}
1866
1867Expected<uint32_t>MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const{
1868MachO::nlist_base Entry =getSymbolTableEntryBase(*this, DRI);
1869
1870uint8_t MachOType = Entry.n_type;
1871uint16_t MachOFlags = Entry.n_desc;
1872
1873uint32_t Result =SymbolRef::SF_None;
1874
1875if ((MachOType &MachO::N_TYPE) ==MachO::N_INDR)
1876 Result |=SymbolRef::SF_Indirect;
1877
1878if (MachOType &MachO::N_STAB)
1879 Result |=SymbolRef::SF_FormatSpecific;
1880
1881if (MachOType &MachO::N_EXT) {
1882 Result |=SymbolRef::SF_Global;
1883if ((MachOType &MachO::N_TYPE) ==MachO::N_UNDF) {
1884if (getNValue(DRI))
1885 Result |=SymbolRef::SF_Common;
1886else
1887 Result |=SymbolRef::SF_Undefined;
1888 }
1889
1890if (MachOType &MachO::N_PEXT)
1891 Result |=SymbolRef::SF_Hidden;
1892else
1893 Result |=SymbolRef::SF_Exported;
1894
1895 }elseif (MachOType &MachO::N_PEXT)
1896 Result |=SymbolRef::SF_Hidden;
1897
1898if (MachOFlags & (MachO::N_WEAK_REF |MachO::N_WEAK_DEF))
1899 Result |=SymbolRef::SF_Weak;
1900
1901if (MachOFlags & (MachO::N_ARM_THUMB_DEF))
1902 Result |=SymbolRef::SF_Thumb;
1903
1904if ((MachOType &MachO::N_TYPE) ==MachO::N_ABS)
1905 Result |=SymbolRef::SF_Absolute;
1906
1907return Result;
1908}
1909
1910Expected<section_iterator>
1911MachOObjectFile::getSymbolSection(DataRefImpl Symb) const{
1912MachO::nlist_base Entry =getSymbolTableEntryBase(*this, Symb);
1913uint8_t index = Entry.n_sect;
1914
1915if (index == 0)
1916returnsection_end();
1917DataRefImpl DRI;
1918 DRI.d.a = index - 1;
1919if (DRI.d.a >= Sections.size()){
1920returnmalformedError("bad section index: " +Twine((int)index) +
1921" for symbol at index " +Twine(getSymbolIndex(Symb)));
1922 }
1923returnsection_iterator(SectionRef(DRI,this));
1924}
1925
1926unsignedMachOObjectFile::getSymbolSectionID(SymbolRefSym) const{
1927MachO::nlist_base Entry =
1928getSymbolTableEntryBase(*this,Sym.getRawDataRefImpl());
1929return Entry.n_sect - 1;
1930}
1931
1932voidMachOObjectFile::moveSectionNext(DataRefImpl &Sec) const{
1933 Sec.d.a++;
1934}
1935
1936Expected<StringRef>MachOObjectFile::getSectionName(DataRefImpl Sec) const{
1937ArrayRef<char> Raw =getSectionRawName(Sec);
1938returnparseSegmentOrSectionName(Raw.data());
1939}
1940
1941uint64_tMachOObjectFile::getSectionAddress(DataRefImpl Sec) const{
1942if (is64Bit())
1943returngetSection64(Sec).addr;
1944returngetSection(Sec).addr;
1945}
1946
1947uint64_tMachOObjectFile::getSectionIndex(DataRefImpl Sec) const{
1948return Sec.d.a;
1949}
1950
1951uint64_tMachOObjectFile::getSectionSize(DataRefImpl Sec) const{
1952// In the case if a malformed Mach-O file where the section offset is past
1953// the end of the file or some part of the section size is past the end of
1954// the file return a size of zero or a size that covers the rest of the file
1955// but does not extend past the end of the file.
1956uint32_t SectOffset, SectType;
1957uint64_t SectSize;
1958
1959if (is64Bit()) {
1960MachO::section_64 Sect =getSection64(Sec);
1961 SectOffset = Sect.offset;
1962 SectSize = Sect.size;
1963 SectType = Sect.flags &MachO::SECTION_TYPE;
1964 }else {
1965MachO::section Sect =getSection(Sec);
1966 SectOffset = Sect.offset;
1967 SectSize = Sect.size;
1968 SectType = Sect.flags &MachO::SECTION_TYPE;
1969 }
1970if (SectType ==MachO::S_ZEROFILL || SectType ==MachO::S_GB_ZEROFILL)
1971return SectSize;
1972uint64_t FileSize =getData().size();
1973if (SectOffset > FileSize)
1974return 0;
1975if (FileSize - SectOffset < SectSize)
1976return FileSize - SectOffset;
1977return SectSize;
1978}
1979
1980ArrayRef<uint8_t>MachOObjectFile::getSectionContents(uint32_tOffset,
1981uint64_tSize) const{
1982return arrayRefFromStringRef(getData().substr(Offset,Size));
1983}
1984
1985Expected<ArrayRef<uint8_t>>
1986MachOObjectFile::getSectionContents(DataRefImpl Sec) const{
1987uint32_tOffset;
1988uint64_tSize;
1989
1990if (is64Bit()) {
1991MachO::section_64 Sect =getSection64(Sec);
1992Offset = Sect.offset;
1993Size = Sect.size;
1994 }else {
1995MachO::section Sect =getSection(Sec);
1996Offset = Sect.offset;
1997Size = Sect.size;
1998 }
1999
2000returngetSectionContents(Offset,Size);
2001}
2002
2003uint64_tMachOObjectFile::getSectionAlignment(DataRefImpl Sec) const{
2004uint32_tAlign;
2005if (is64Bit()) {
2006MachO::section_64 Sect =getSection64(Sec);
2007Align = Sect.align;
2008 }else {
2009MachO::section Sect =getSection(Sec);
2010Align = Sect.align;
2011 }
2012
2013returnuint64_t(1) <<Align;
2014}
2015
2016Expected<SectionRef>MachOObjectFile::getSection(unsigned SectionIndex) const{
2017if (SectionIndex < 1 || SectionIndex > Sections.size())
2018returnmalformedError("bad section index: " +Twine((int)SectionIndex));
2019
2020DataRefImpl DRI;
2021 DRI.d.a = SectionIndex - 1;
2022returnSectionRef(DRI,this);
2023}
2024
2025Expected<SectionRef>MachOObjectFile::getSection(StringRefSectionName) const{
2026for (constSectionRef &Section :sections()) {
2027auto NameOrErr = Section.getName();
2028if (!NameOrErr)
2029return NameOrErr.takeError();
2030if (*NameOrErr ==SectionName)
2031return Section;
2032 }
2033returnerrorCodeToError(object_error::parse_failed);
2034}
2035
2036boolMachOObjectFile::isSectionCompressed(DataRefImpl Sec) const{
2037returnfalse;
2038}
2039
2040boolMachOObjectFile::isSectionText(DataRefImpl Sec) const{
2041uint32_t Flags =getSectionFlags(*this, Sec);
2042return Flags &MachO::S_ATTR_PURE_INSTRUCTIONS;
2043}
2044
2045boolMachOObjectFile::isSectionData(DataRefImpl Sec) const{
2046uint32_t Flags =getSectionFlags(*this, Sec);
2047unsigned SectionType = Flags &MachO::SECTION_TYPE;
2048return !(Flags &MachO::S_ATTR_PURE_INSTRUCTIONS) &&
2049 !(SectionType ==MachO::S_ZEROFILL ||
2050 SectionType ==MachO::S_GB_ZEROFILL);
2051}
2052
2053boolMachOObjectFile::isSectionBSS(DataRefImpl Sec) const{
2054uint32_t Flags =getSectionFlags(*this, Sec);
2055unsigned SectionType = Flags &MachO::SECTION_TYPE;
2056return !(Flags &MachO::S_ATTR_PURE_INSTRUCTIONS) &&
2057 (SectionType ==MachO::S_ZEROFILL ||
2058 SectionType ==MachO::S_GB_ZEROFILL);
2059}
2060
2061boolMachOObjectFile::isDebugSection(DataRefImpl Sec) const{
2062Expected<StringRef> SectionNameOrErr =getSectionName(Sec);
2063if (!SectionNameOrErr) {
2064// TODO: Report the error message properly.
2065consumeError(SectionNameOrErr.takeError());
2066returnfalse;
2067 }
2068StringRefSectionName = SectionNameOrErr.get();
2069returnSectionName.starts_with("__debug") ||
2070SectionName.starts_with("__zdebug") ||
2071SectionName.starts_with("__apple") ||SectionName =="__gdb_index" ||
2072SectionName =="__swift_ast";
2073}
2074
2075namespace{
2076template <typename LoadCommandType>
2077ArrayRef<uint8_t> getSegmentContents(constMachOObjectFile &Obj,
2078MachOObjectFile::LoadCommandInfo LoadCmd,
2079StringRef SegmentName) {
2080auto SegmentOrErr = getStructOrErr<LoadCommandType>(Obj, LoadCmd.Ptr);
2081if (!SegmentOrErr) {
2082consumeError(SegmentOrErr.takeError());
2083return {};
2084 }
2085auto &Segment = SegmentOrErr.get();
2086if (StringRef(Segment.segname, 16).starts_with(SegmentName))
2087return arrayRefFromStringRef(Obj.getData().slice(
2088 Segment.fileoff, Segment.fileoff + Segment.filesize));
2089return {};
2090}
2091
2092template <typename LoadCommandType>
2093ArrayRef<uint8_t> getSegmentContents(constMachOObjectFile &Obj,
2094MachOObjectFile::LoadCommandInfo LoadCmd) {
2095auto SegmentOrErr = getStructOrErr<LoadCommandType>(Obj, LoadCmd.Ptr);
2096if (!SegmentOrErr) {
2097consumeError(SegmentOrErr.takeError());
2098return {};
2099 }
2100auto &Segment = SegmentOrErr.get();
2101return arrayRefFromStringRef(
2102 Obj.getData().substr(Segment.fileoff, Segment.filesize));
2103}
2104}// namespace
2105
2106ArrayRef<uint8_t>
2107MachOObjectFile::getSegmentContents(StringRef SegmentName) const{
2108for (auto LoadCmd :load_commands()) {
2109ArrayRef<uint8_t> Contents;
2110switch (LoadCmd.C.cmd) {
2111case MachO::LC_SEGMENT:
2112 Contents = ::getSegmentContents<MachO::segment_command>(*this, LoadCmd,
2113 SegmentName);
2114break;
2115case MachO::LC_SEGMENT_64:
2116 Contents = ::getSegmentContents<MachO::segment_command_64>(*this, LoadCmd,
2117 SegmentName);
2118break;
2119default:
2120continue;
2121 }
2122if (!Contents.empty())
2123return Contents;
2124 }
2125return {};
2126}
2127
2128ArrayRef<uint8_t>
2129MachOObjectFile::getSegmentContents(size_t SegmentIndex) const{
2130size_tIdx = 0;
2131for (auto LoadCmd :load_commands()) {
2132switch (LoadCmd.C.cmd) {
2133case MachO::LC_SEGMENT:
2134if (Idx == SegmentIndex)
2135 return ::getSegmentContents<MachO::segment_command>(*this, LoadCmd);
2136 ++Idx;
2137break;
2138case MachO::LC_SEGMENT_64:
2139if (Idx == SegmentIndex)
2140 return ::getSegmentContents<MachO::segment_command_64>(*this, LoadCmd);
2141 ++Idx;
2142break;
2143default:
2144continue;
2145 }
2146 }
2147return {};
2148}
2149
2150unsignedMachOObjectFile::getSectionID(SectionRef Sec) const{
2151return Sec.getRawDataRefImpl().d.a;
2152}
2153
2154boolMachOObjectFile::isSectionVirtual(DataRefImpl Sec) const{
2155uint32_t Flags =getSectionFlags(*this, Sec);
2156unsigned SectionType = Flags &MachO::SECTION_TYPE;
2157return SectionType ==MachO::S_ZEROFILL ||
2158 SectionType ==MachO::S_GB_ZEROFILL;
2159}
2160
2161boolMachOObjectFile::isSectionBitcode(DataRefImpl Sec) const{
2162StringRef SegmentName =getSectionFinalSegmentName(Sec);
2163if (Expected<StringRef> NameOrErr =getSectionName(Sec))
2164return (SegmentName =="__LLVM" && *NameOrErr =="__bitcode");
2165returnfalse;
2166}
2167
2168boolMachOObjectFile::isSectionStripped(DataRefImpl Sec) const{
2169if (is64Bit())
2170returngetSection64(Sec).offset == 0;
2171returngetSection(Sec).offset == 0;
2172}
2173
2174relocation_iteratorMachOObjectFile::section_rel_begin(DataRefImpl Sec) const{
2175DataRefImpl Ret;
2176 Ret.d.a = Sec.d.a;
2177 Ret.d.b = 0;
2178returnrelocation_iterator(RelocationRef(Ret,this));
2179}
2180
2181relocation_iterator
2182MachOObjectFile::section_rel_end(DataRefImpl Sec) const{
2183uint32_t Num;
2184if (is64Bit()) {
2185MachO::section_64 Sect =getSection64(Sec);
2186 Num = Sect.nreloc;
2187 }else {
2188MachO::section Sect =getSection(Sec);
2189 Num = Sect.nreloc;
2190 }
2191
2192DataRefImpl Ret;
2193 Ret.d.a = Sec.d.a;
2194 Ret.d.b = Num;
2195returnrelocation_iterator(RelocationRef(Ret,this));
2196}
2197
2198relocation_iteratorMachOObjectFile::extrel_begin() const{
2199DataRefImpl Ret;
2200// for DYSYMTAB symbols, Ret.d.a == 0 for external relocations
2201 Ret.d.a = 0;// Would normally be a section index.
2202 Ret.d.b = 0;// Index into the external relocations
2203returnrelocation_iterator(RelocationRef(Ret,this));
2204}
2205
2206relocation_iteratorMachOObjectFile::extrel_end() const{
2207MachO::dysymtab_command DysymtabLoadCmd =getDysymtabLoadCommand();
2208DataRefImpl Ret;
2209// for DYSYMTAB symbols, Ret.d.a == 0 for external relocations
2210 Ret.d.a = 0;// Would normally be a section index.
2211 Ret.d.b = DysymtabLoadCmd.nextrel;// Index into the external relocations
2212returnrelocation_iterator(RelocationRef(Ret,this));
2213}
2214
2215relocation_iteratorMachOObjectFile::locrel_begin() const{
2216DataRefImpl Ret;
2217// for DYSYMTAB symbols, Ret.d.a == 1 for local relocations
2218 Ret.d.a = 1;// Would normally be a section index.
2219 Ret.d.b = 0;// Index into the local relocations
2220returnrelocation_iterator(RelocationRef(Ret,this));
2221}
2222
2223relocation_iteratorMachOObjectFile::locrel_end() const{
2224MachO::dysymtab_command DysymtabLoadCmd =getDysymtabLoadCommand();
2225DataRefImpl Ret;
2226// for DYSYMTAB symbols, Ret.d.a == 1 for local relocations
2227 Ret.d.a = 1;// Would normally be a section index.
2228 Ret.d.b = DysymtabLoadCmd.nlocrel;// Index into the local relocations
2229returnrelocation_iterator(RelocationRef(Ret,this));
2230}
2231
2232voidMachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const{
2233 ++Rel.d.b;
2234}
2235
2236uint64_tMachOObjectFile::getRelocationOffset(DataRefImpl Rel) const{
2237assert((getHeader().filetype ==MachO::MH_OBJECT ||
2238getHeader().filetype ==MachO::MH_KEXT_BUNDLE) &&
2239"Only implemented for MH_OBJECT && MH_KEXT_BUNDLE");
2240MachO::any_relocation_info RE =getRelocation(Rel);
2241returngetAnyRelocationAddress(RE);
2242}
2243
2244symbol_iterator
2245MachOObjectFile::getRelocationSymbol(DataRefImpl Rel) const{
2246MachO::any_relocation_info RE =getRelocation(Rel);
2247if (isRelocationScattered(RE))
2248returnsymbol_end();
2249
2250uint32_t SymbolIdx =getPlainRelocationSymbolNum(RE);
2251bool isExtern =getPlainRelocationExternal(RE);
2252if (!isExtern)
2253returnsymbol_end();
2254
2255MachO::symtab_command S =getSymtabLoadCommand();
2256unsignedSymbolTableEntrySize =is64Bit() ?
2257sizeof(MachO::nlist_64) :
2258sizeof(MachO::nlist);
2259uint64_tOffset = S.symoff + SymbolIdx *SymbolTableEntrySize;
2260DataRefImplSym;
2261Sym.p =reinterpret_cast<uintptr_t>(getPtr(*this,Offset));
2262returnsymbol_iterator(SymbolRef(Sym,this));
2263}
2264
2265section_iterator
2266MachOObjectFile::getRelocationSection(DataRefImpl Rel) const{
2267returnsection_iterator(getAnyRelocationSection(getRelocation(Rel)));
2268}
2269
2270uint64_tMachOObjectFile::getRelocationType(DataRefImpl Rel) const{
2271MachO::any_relocation_info RE =getRelocation(Rel);
2272returngetAnyRelocationType(RE);
2273}
2274
2275voidMachOObjectFile::getRelocationTypeName(
2276DataRefImpl Rel,SmallVectorImpl<char> &Result) const{
2277StringRef res;
2278uint64_t RType =getRelocationType(Rel);
2279
2280unsigned Arch = this->getArch();
2281
2282switch (Arch) {
2283caseTriple::x86: {
2284staticconstchar *const Table[] = {
2285"GENERIC_RELOC_VANILLA",
2286"GENERIC_RELOC_PAIR",
2287"GENERIC_RELOC_SECTDIFF",
2288"GENERIC_RELOC_PB_LA_PTR",
2289"GENERIC_RELOC_LOCAL_SECTDIFF",
2290"GENERIC_RELOC_TLV" };
2291
2292if (RType > 5)
2293 res ="Unknown";
2294else
2295 res = Table[RType];
2296break;
2297 }
2298caseTriple::x86_64: {
2299staticconstchar *const Table[] = {
2300"X86_64_RELOC_UNSIGNED",
2301"X86_64_RELOC_SIGNED",
2302"X86_64_RELOC_BRANCH",
2303"X86_64_RELOC_GOT_LOAD",
2304"X86_64_RELOC_GOT",
2305"X86_64_RELOC_SUBTRACTOR",
2306"X86_64_RELOC_SIGNED_1",
2307"X86_64_RELOC_SIGNED_2",
2308"X86_64_RELOC_SIGNED_4",
2309"X86_64_RELOC_TLV" };
2310
2311if (RType > 9)
2312 res ="Unknown";
2313else
2314 res = Table[RType];
2315break;
2316 }
2317caseTriple::arm: {
2318staticconstchar *const Table[] = {
2319"ARM_RELOC_VANILLA",
2320"ARM_RELOC_PAIR",
2321"ARM_RELOC_SECTDIFF",
2322"ARM_RELOC_LOCAL_SECTDIFF",
2323"ARM_RELOC_PB_LA_PTR",
2324"ARM_RELOC_BR24",
2325"ARM_THUMB_RELOC_BR22",
2326"ARM_THUMB_32BIT_BRANCH",
2327"ARM_RELOC_HALF",
2328"ARM_RELOC_HALF_SECTDIFF" };
2329
2330if (RType > 9)
2331 res ="Unknown";
2332else
2333 res = Table[RType];
2334break;
2335 }
2336caseTriple::aarch64:
2337caseTriple::aarch64_32: {
2338staticconstchar *const Table[] = {
2339"ARM64_RELOC_UNSIGNED","ARM64_RELOC_SUBTRACTOR",
2340"ARM64_RELOC_BRANCH26","ARM64_RELOC_PAGE21",
2341"ARM64_RELOC_PAGEOFF12","ARM64_RELOC_GOT_LOAD_PAGE21",
2342"ARM64_RELOC_GOT_LOAD_PAGEOFF12","ARM64_RELOC_POINTER_TO_GOT",
2343"ARM64_RELOC_TLVP_LOAD_PAGE21","ARM64_RELOC_TLVP_LOAD_PAGEOFF12",
2344"ARM64_RELOC_ADDEND","ARM64_RELOC_AUTHENTICATED_POINTER"
2345 };
2346
2347if (RType >= std::size(Table))
2348 res ="Unknown";
2349else
2350 res = Table[RType];
2351break;
2352 }
2353caseTriple::ppc: {
2354staticconstchar *const Table[] = {
2355"PPC_RELOC_VANILLA",
2356"PPC_RELOC_PAIR",
2357"PPC_RELOC_BR14",
2358"PPC_RELOC_BR24",
2359"PPC_RELOC_HI16",
2360"PPC_RELOC_LO16",
2361"PPC_RELOC_HA16",
2362"PPC_RELOC_LO14",
2363"PPC_RELOC_SECTDIFF",
2364"PPC_RELOC_PB_LA_PTR",
2365"PPC_RELOC_HI16_SECTDIFF",
2366"PPC_RELOC_LO16_SECTDIFF",
2367"PPC_RELOC_HA16_SECTDIFF",
2368"PPC_RELOC_JBSR",
2369"PPC_RELOC_LO14_SECTDIFF",
2370"PPC_RELOC_LOCAL_SECTDIFF" };
2371
2372if (RType > 15)
2373 res ="Unknown";
2374else
2375 res = Table[RType];
2376break;
2377 }
2378caseTriple::UnknownArch:
2379 res ="Unknown";
2380break;
2381 }
2382 Result.append(res.begin(), res.end());
2383}
2384
2385uint8_tMachOObjectFile::getRelocationLength(DataRefImpl Rel) const{
2386MachO::any_relocation_info RE =getRelocation(Rel);
2387returngetAnyRelocationLength(RE);
2388}
2389
2390//
2391// guessLibraryShortName() is passed a name of a dynamic library and returns a
2392// guess on what the short name is. Then name is returned as a substring of the
2393// StringRef Name passed in. The name of the dynamic library is recognized as
2394// a framework if it has one of the two following forms:
2395// Foo.framework/Versions/A/Foo
2396// Foo.framework/Foo
2397// Where A and Foo can be any string. And may contain a trailing suffix
2398// starting with an underbar. If the Name is recognized as a framework then
2399// isFramework is set to true else it is set to false. If the Name has a
2400// suffix then Suffix is set to the substring in Name that contains the suffix
2401// else it is set to a NULL StringRef.
2402//
2403// The Name of the dynamic library is recognized as a library name if it has
2404// one of the two following forms:
2405// libFoo.A.dylib
2406// libFoo.dylib
2407//
2408// The library may have a suffix trailing the name Foo of the form:
2409// libFoo_profile.A.dylib
2410// libFoo_profile.dylib
2411// These dyld image suffixes are separated from the short name by a '_'
2412// character. Because the '_' character is commonly used to separate words in
2413// filenames guessLibraryShortName() cannot reliably separate a dylib's short
2414// name from an arbitrary image suffix; imagine if both the short name and the
2415// suffix contains an '_' character! To better deal with this ambiguity,
2416// guessLibraryShortName() will recognize only "_debug" and "_profile" as valid
2417// Suffix values. Calling code needs to be tolerant of guessLibraryShortName()
2418// guessing incorrectly.
2419//
2420// The Name of the dynamic library is also recognized as a library name if it
2421// has the following form:
2422// Foo.qtx
2423//
2424// If the Name of the dynamic library is none of the forms above then a NULL
2425// StringRef is returned.
2426StringRefMachOObjectFile::guessLibraryShortName(StringRefName,
2427bool &isFramework,
2428StringRef &Suffix) {
2429StringRef Foo,F, DotFramework, V, Dylib,Lib, Dot, Qtx;
2430size_t a, b, c, d,Idx;
2431
2432 isFramework =false;
2433 Suffix =StringRef();
2434
2435// Pull off the last component and make Foo point to it
2436 a =Name.rfind('/');
2437if (a ==Name.npos || a == 0)
2438goto guess_library;
2439 Foo =Name.substr(a + 1);
2440
2441// Look for a suffix starting with a '_'
2442Idx = Foo.rfind('_');
2443if (Idx != Foo.npos && Foo.size() >= 2) {
2444 Suffix = Foo.substr(Idx);
2445if (Suffix !="_debug" && Suffix !="_profile")
2446 Suffix =StringRef();
2447else
2448 Foo = Foo.slice(0,Idx);
2449 }
2450
2451// First look for the form Foo.framework/Foo
2452 b =Name.rfind('/', a);
2453if (b ==Name.npos)
2454Idx = 0;
2455else
2456Idx = b+1;
2457F =Name.substr(Idx, Foo.size());
2458 DotFramework =Name.substr(Idx + Foo.size(),sizeof(".framework/") - 1);
2459if (F == Foo && DotFramework ==".framework/") {
2460 isFramework =true;
2461return Foo;
2462 }
2463
2464// Next look for the form Foo.framework/Versions/A/Foo
2465if (b ==Name.npos)
2466goto guess_library;
2467 c =Name.rfind('/', b);
2468if (c ==Name.npos || c == 0)
2469goto guess_library;
2470 V =Name.substr(c + 1);
2471if (!V.starts_with("Versions/"))
2472goto guess_library;
2473 d =Name.rfind('/', c);
2474if (d ==Name.npos)
2475Idx = 0;
2476else
2477Idx = d+1;
2478F =Name.substr(Idx, Foo.size());
2479 DotFramework =Name.substr(Idx + Foo.size(),sizeof(".framework/") - 1);
2480if (F == Foo && DotFramework ==".framework/") {
2481 isFramework =true;
2482return Foo;
2483 }
2484
2485guess_library:
2486// pull off the suffix after the "." and make a point to it
2487 a =Name.rfind('.');
2488if (a ==Name.npos || a == 0)
2489returnStringRef();
2490 Dylib =Name.substr(a);
2491if (Dylib !=".dylib")
2492goto guess_qtx;
2493
2494// First pull off the version letter for the form Foo.A.dylib if any.
2495if (a >= 3) {
2496 Dot =Name.substr(a - 2, 1);
2497if (Dot ==".")
2498 a = a - 2;
2499 }
2500
2501 b =Name.rfind('/', a);
2502if (b ==Name.npos)
2503 b = 0;
2504else
2505 b = b+1;
2506// ignore any suffix after an underbar like Foo_profile.A.dylib
2507Idx =Name.rfind('_');
2508if (Idx !=Name.npos &&Idx != b) {
2509Lib =Name.slice(b,Idx);
2510 Suffix =Name.slice(Idx, a);
2511if (Suffix !="_debug" && Suffix !="_profile") {
2512 Suffix =StringRef();
2513Lib =Name.slice(b, a);
2514 }
2515 }
2516else
2517Lib =Name.slice(b, a);
2518// There are incorrect library names of the form:
2519// libATS.A_profile.dylib so check for these.
2520if (Lib.size() >= 3) {
2521 Dot =Lib.substr(Lib.size() - 2, 1);
2522if (Dot ==".")
2523Lib =Lib.slice(0,Lib.size()-2);
2524 }
2525returnLib;
2526
2527guess_qtx:
2528 Qtx =Name.substr(a);
2529if (Qtx !=".qtx")
2530returnStringRef();
2531 b =Name.rfind('/', a);
2532if (b ==Name.npos)
2533Lib =Name.slice(0, a);
2534else
2535Lib =Name.slice(b+1, a);
2536// There are library names of the form: QT.A.qtx so check for these.
2537if (Lib.size() >= 3) {
2538 Dot =Lib.substr(Lib.size() - 2, 1);
2539if (Dot ==".")
2540Lib =Lib.slice(0,Lib.size()-2);
2541 }
2542returnLib;
2543}
2544
2545// getLibraryShortNameByIndex() is used to get the short name of the library
2546// for an undefined symbol in a linked Mach-O binary that was linked with the
2547// normal two-level namespace default (that is MH_TWOLEVEL in the header).
2548// It is passed the index (0 - based) of the library as translated from
2549// GET_LIBRARY_ORDINAL (1 - based).
2550std::error_codeMachOObjectFile::getLibraryShortNameByIndex(unsigned Index,
2551StringRef &Res) const{
2552if (Index >= Libraries.size())
2553returnobject_error::parse_failed;
2554
2555// If the cache of LibrariesShortNames is not built up do that first for
2556// all the Libraries.
2557if (LibrariesShortNames.size() == 0) {
2558for (unsigned i = 0; i < Libraries.size(); i++) {
2559auto CommandOrErr =
2560 getStructOrErr<MachO::dylib_command>(*this, Libraries[i]);
2561if (!CommandOrErr)
2562returnobject_error::parse_failed;
2563MachO::dylib_commandD = CommandOrErr.get();
2564if (D.dylib.name >=D.cmdsize)
2565returnobject_error::parse_failed;
2566constchar *P = (constchar *)(Libraries[i]) +D.dylib.name;
2567StringRefName =StringRef(P);
2568if (D.dylib.name+Name.size() >=D.cmdsize)
2569returnobject_error::parse_failed;
2570StringRef Suffix;
2571bool isFramework;
2572StringRef shortName =guessLibraryShortName(Name, isFramework, Suffix);
2573if (shortName.empty())
2574 LibrariesShortNames.push_back(Name);
2575else
2576 LibrariesShortNames.push_back(shortName);
2577 }
2578 }
2579
2580 Res = LibrariesShortNames[Index];
2581return std::error_code();
2582}
2583
2584uint32_tMachOObjectFile::getLibraryCount() const{
2585return Libraries.size();
2586}
2587
2588section_iterator
2589MachOObjectFile::getRelocationRelocatedSection(relocation_iterator Rel) const{
2590DataRefImpl Sec;
2591 Sec.d.a = Rel->getRawDataRefImpl().d.a;
2592returnsection_iterator(SectionRef(Sec,this));
2593}
2594
2595basic_symbol_iteratorMachOObjectFile::symbol_begin() const{
2596DataRefImpl DRI;
2597MachO::symtab_command Symtab =getSymtabLoadCommand();
2598if (!SymtabLoadCmd || Symtab.nsyms == 0)
2599returnbasic_symbol_iterator(SymbolRef(DRI,this));
2600
2601returngetSymbolByIndex(0);
2602}
2603
2604basic_symbol_iteratorMachOObjectFile::symbol_end() const{
2605DataRefImpl DRI;
2606MachO::symtab_command Symtab =getSymtabLoadCommand();
2607if (!SymtabLoadCmd || Symtab.nsyms == 0)
2608returnbasic_symbol_iterator(SymbolRef(DRI,this));
2609
2610unsignedSymbolTableEntrySize =is64Bit() ?
2611sizeof(MachO::nlist_64) :
2612sizeof(MachO::nlist);
2613unsignedOffset = Symtab.symoff +
2614 Symtab.nsyms *SymbolTableEntrySize;
2615 DRI.p =reinterpret_cast<uintptr_t>(getPtr(*this,Offset));
2616returnbasic_symbol_iterator(SymbolRef(DRI,this));
2617}
2618
2619symbol_iteratorMachOObjectFile::getSymbolByIndex(unsigned Index) const{
2620MachO::symtab_command Symtab =getSymtabLoadCommand();
2621if (!SymtabLoadCmd || Index >= Symtab.nsyms)
2622report_fatal_error("Requested symbol index is out of range.");
2623unsignedSymbolTableEntrySize =
2624is64Bit() ?sizeof(MachO::nlist_64) :sizeof(MachO::nlist);
2625DataRefImpl DRI;
2626 DRI.p =reinterpret_cast<uintptr_t>(getPtr(*this, Symtab.symoff));
2627 DRI.p += Index *SymbolTableEntrySize;
2628returnbasic_symbol_iterator(SymbolRef(DRI,this));
2629}
2630
2631uint64_tMachOObjectFile::getSymbolIndex(DataRefImpl Symb) const{
2632MachO::symtab_command Symtab =getSymtabLoadCommand();
2633if (!SymtabLoadCmd)
2634report_fatal_error("getSymbolIndex() called with no symbol table symbol");
2635unsignedSymbolTableEntrySize =
2636is64Bit() ?sizeof(MachO::nlist_64) :sizeof(MachO::nlist);
2637DataRefImpl DRIstart;
2638 DRIstart.p =reinterpret_cast<uintptr_t>(getPtr(*this, Symtab.symoff));
2639uint64_t Index = (Symb.p - DRIstart.p) /SymbolTableEntrySize;
2640return Index;
2641}
2642
2643section_iteratorMachOObjectFile::section_begin() const{
2644DataRefImpl DRI;
2645returnsection_iterator(SectionRef(DRI,this));
2646}
2647
2648section_iteratorMachOObjectFile::section_end() const{
2649DataRefImpl DRI;
2650 DRI.d.a = Sections.size();
2651returnsection_iterator(SectionRef(DRI,this));
2652}
2653
2654uint8_tMachOObjectFile::getBytesInAddress() const{
2655returnis64Bit() ? 8 : 4;
2656}
2657
2658StringRefMachOObjectFile::getFileFormatName() const{
2659unsigned CPUType =getCPUType(*this);
2660if (!is64Bit()) {
2661switch (CPUType) {
2662caseMachO::CPU_TYPE_I386:
2663return"Mach-O 32-bit i386";
2664caseMachO::CPU_TYPE_ARM:
2665return"Mach-O arm";
2666caseMachO::CPU_TYPE_ARM64_32:
2667return"Mach-O arm64 (ILP32)";
2668caseMachO::CPU_TYPE_POWERPC:
2669return"Mach-O 32-bit ppc";
2670default:
2671return"Mach-O 32-bit unknown";
2672 }
2673 }
2674
2675switch (CPUType) {
2676caseMachO::CPU_TYPE_X86_64:
2677return"Mach-O 64-bit x86-64";
2678caseMachO::CPU_TYPE_ARM64:
2679return"Mach-O arm64";
2680caseMachO::CPU_TYPE_POWERPC64:
2681return"Mach-O 64-bit ppc64";
2682default:
2683return"Mach-O 64-bit unknown";
2684 }
2685}
2686
2687Triple::ArchTypeMachOObjectFile::getArch(uint32_t CPUType,uint32_t CPUSubType) {
2688switch (CPUType) {
2689caseMachO::CPU_TYPE_I386:
2690returnTriple::x86;
2691caseMachO::CPU_TYPE_X86_64:
2692returnTriple::x86_64;
2693caseMachO::CPU_TYPE_ARM:
2694returnTriple::arm;
2695caseMachO::CPU_TYPE_ARM64:
2696returnTriple::aarch64;
2697caseMachO::CPU_TYPE_ARM64_32:
2698returnTriple::aarch64_32;
2699caseMachO::CPU_TYPE_POWERPC:
2700returnTriple::ppc;
2701caseMachO::CPU_TYPE_POWERPC64:
2702returnTriple::ppc64;
2703default:
2704returnTriple::UnknownArch;
2705 }
2706}
2707
2708TripleMachOObjectFile::getArchTriple(uint32_t CPUType,uint32_t CPUSubType,
2709constchar **McpuDefault,
2710constchar **ArchFlag) {
2711if (McpuDefault)
2712 *McpuDefault =nullptr;
2713if (ArchFlag)
2714 *ArchFlag =nullptr;
2715
2716switch (CPUType) {
2717caseMachO::CPU_TYPE_I386:
2718switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
2719caseMachO::CPU_SUBTYPE_I386_ALL:
2720if (ArchFlag)
2721 *ArchFlag ="i386";
2722returnTriple("i386-apple-darwin");
2723default:
2724returnTriple();
2725 }
2726caseMachO::CPU_TYPE_X86_64:
2727switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
2728caseMachO::CPU_SUBTYPE_X86_64_ALL:
2729if (ArchFlag)
2730 *ArchFlag ="x86_64";
2731returnTriple("x86_64-apple-darwin");
2732caseMachO::CPU_SUBTYPE_X86_64_H:
2733if (ArchFlag)
2734 *ArchFlag ="x86_64h";
2735returnTriple("x86_64h-apple-darwin");
2736default:
2737returnTriple();
2738 }
2739caseMachO::CPU_TYPE_ARM:
2740switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
2741caseMachO::CPU_SUBTYPE_ARM_V4T:
2742if (ArchFlag)
2743 *ArchFlag ="armv4t";
2744returnTriple("armv4t-apple-darwin");
2745caseMachO::CPU_SUBTYPE_ARM_V5TEJ:
2746if (ArchFlag)
2747 *ArchFlag ="armv5e";
2748returnTriple("armv5e-apple-darwin");
2749caseMachO::CPU_SUBTYPE_ARM_XSCALE:
2750if (ArchFlag)
2751 *ArchFlag ="xscale";
2752returnTriple("xscale-apple-darwin");
2753caseMachO::CPU_SUBTYPE_ARM_V6:
2754if (ArchFlag)
2755 *ArchFlag ="armv6";
2756returnTriple("armv6-apple-darwin");
2757caseMachO::CPU_SUBTYPE_ARM_V6M:
2758if (McpuDefault)
2759 *McpuDefault ="cortex-m0";
2760if (ArchFlag)
2761 *ArchFlag ="armv6m";
2762returnTriple("armv6m-apple-darwin");
2763caseMachO::CPU_SUBTYPE_ARM_V7:
2764if (ArchFlag)
2765 *ArchFlag ="armv7";
2766returnTriple("armv7-apple-darwin");
2767caseMachO::CPU_SUBTYPE_ARM_V7EM:
2768if (McpuDefault)
2769 *McpuDefault ="cortex-m4";
2770if (ArchFlag)
2771 *ArchFlag ="armv7em";
2772returnTriple("thumbv7em-apple-darwin");
2773caseMachO::CPU_SUBTYPE_ARM_V7K:
2774if (McpuDefault)
2775 *McpuDefault ="cortex-a7";
2776if (ArchFlag)
2777 *ArchFlag ="armv7k";
2778returnTriple("armv7k-apple-darwin");
2779caseMachO::CPU_SUBTYPE_ARM_V7M:
2780if (McpuDefault)
2781 *McpuDefault ="cortex-m3";
2782if (ArchFlag)
2783 *ArchFlag ="armv7m";
2784returnTriple("thumbv7m-apple-darwin");
2785caseMachO::CPU_SUBTYPE_ARM_V7S:
2786if (McpuDefault)
2787 *McpuDefault ="cortex-a7";
2788if (ArchFlag)
2789 *ArchFlag ="armv7s";
2790returnTriple("armv7s-apple-darwin");
2791default:
2792returnTriple();
2793 }
2794caseMachO::CPU_TYPE_ARM64:
2795switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
2796caseMachO::CPU_SUBTYPE_ARM64_ALL:
2797if (McpuDefault)
2798 *McpuDefault ="cyclone";
2799if (ArchFlag)
2800 *ArchFlag ="arm64";
2801returnTriple("arm64-apple-darwin");
2802caseMachO::CPU_SUBTYPE_ARM64E:
2803if (McpuDefault)
2804 *McpuDefault ="apple-a12";
2805if (ArchFlag)
2806 *ArchFlag ="arm64e";
2807returnTriple("arm64e-apple-darwin");
2808default:
2809returnTriple();
2810 }
2811caseMachO::CPU_TYPE_ARM64_32:
2812switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
2813caseMachO::CPU_SUBTYPE_ARM64_32_V8:
2814if (McpuDefault)
2815 *McpuDefault ="cyclone";
2816if (ArchFlag)
2817 *ArchFlag ="arm64_32";
2818returnTriple("arm64_32-apple-darwin");
2819default:
2820returnTriple();
2821 }
2822caseMachO::CPU_TYPE_POWERPC:
2823switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
2824caseMachO::CPU_SUBTYPE_POWERPC_ALL:
2825if (ArchFlag)
2826 *ArchFlag ="ppc";
2827returnTriple("ppc-apple-darwin");
2828default:
2829returnTriple();
2830 }
2831caseMachO::CPU_TYPE_POWERPC64:
2832switch (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) {
2833caseMachO::CPU_SUBTYPE_POWERPC_ALL:
2834if (ArchFlag)
2835 *ArchFlag ="ppc64";
2836returnTriple("ppc64-apple-darwin");
2837default:
2838returnTriple();
2839 }
2840default:
2841returnTriple();
2842 }
2843}
2844
2845TripleMachOObjectFile::getHostArch() {
2846returnTriple(sys::getDefaultTargetTriple());
2847}
2848
2849boolMachOObjectFile::isValidArch(StringRef ArchFlag) {
2850auto validArchs =getValidArchs();
2851returnllvm::is_contained(validArchs, ArchFlag);
2852}
2853
2854ArrayRef<StringRef>MachOObjectFile::getValidArchs() {
2855staticconst std::array<StringRef, 18> ValidArchs = {{
2856"i386",
2857"x86_64",
2858"x86_64h",
2859"armv4t",
2860"arm",
2861"armv5e",
2862"armv6",
2863"armv6m",
2864"armv7",
2865"armv7em",
2866"armv7k",
2867"armv7m",
2868"armv7s",
2869"arm64",
2870"arm64e",
2871"arm64_32",
2872"ppc",
2873"ppc64",
2874 }};
2875
2876return ValidArchs;
2877}
2878
2879Triple::ArchTypeMachOObjectFile::getArch() const{
2880returngetArch(getCPUType(*this),getCPUSubType(*this));
2881}
2882
2883TripleMachOObjectFile::getArchTriple(constchar **McpuDefault) const{
2884returngetArchTriple(Header.cputype,Header.cpusubtype, McpuDefault);
2885}
2886
2887relocation_iteratorMachOObjectFile::section_rel_begin(unsigned Index) const{
2888DataRefImpl DRI;
2889 DRI.d.a = Index;
2890returnsection_rel_begin(DRI);
2891}
2892
2893relocation_iteratorMachOObjectFile::section_rel_end(unsigned Index) const{
2894DataRefImpl DRI;
2895 DRI.d.a = Index;
2896returnsection_rel_end(DRI);
2897}
2898
2899dice_iteratorMachOObjectFile::begin_dices() const{
2900DataRefImpl DRI;
2901if (!DataInCodeLoadCmd)
2902returndice_iterator(DiceRef(DRI,this));
2903
2904MachO::linkedit_data_command DicLC =getDataInCodeLoadCommand();
2905 DRI.p =reinterpret_cast<uintptr_t>(getPtr(*this, DicLC.dataoff));
2906returndice_iterator(DiceRef(DRI,this));
2907}
2908
2909dice_iteratorMachOObjectFile::end_dices() const{
2910DataRefImpl DRI;
2911if (!DataInCodeLoadCmd)
2912returndice_iterator(DiceRef(DRI,this));
2913
2914MachO::linkedit_data_command DicLC =getDataInCodeLoadCommand();
2915unsignedOffset = DicLC.dataoff + DicLC.datasize;
2916 DRI.p =reinterpret_cast<uintptr_t>(getPtr(*this,Offset));
2917returndice_iterator(DiceRef(DRI,this));
2918}
2919
2920ExportEntry::ExportEntry(Error *E,constMachOObjectFile *O,
2921ArrayRef<uint8_t>T) : E(E), O(O), Trie(T) {}
2922
2923void ExportEntry::moveToFirst() {
2924ErrorAsOutParameter ErrAsOutParam(E);
2925 pushNode(0);
2926if (*E)
2927return;
2928 pushDownUntilBottom();
2929}
2930
2931void ExportEntry::moveToEnd() {
2932 Stack.clear();
2933 Done =true;
2934}
2935
2936boolExportEntry::operator==(constExportEntry &Other) const{
2937// Common case, one at end, other iterating from begin.
2938if (Done ||Other.Done)
2939return (Done ==Other.Done);
2940// Not equal if different stack sizes.
2941if (Stack.size() !=Other.Stack.size())
2942returnfalse;
2943// Not equal if different cumulative strings.
2944if (!CumulativeString.equals(Other.CumulativeString))
2945returnfalse;
2946// Equal if all nodes in both stacks match.
2947for (unsigned i=0; i < Stack.size(); ++i) {
2948if (Stack[i].Start !=Other.Stack[i].Start)
2949returnfalse;
2950 }
2951returntrue;
2952}
2953
2954uint64_t ExportEntry::readULEB128(constuint8_t *&Ptr,constchar **error) {
2955unsigned Count;
2956uint64_t Result =decodeULEB128(Ptr, &Count, Trie.end(),error);
2957Ptr += Count;
2958if (Ptr > Trie.end())
2959Ptr = Trie.end();
2960return Result;
2961}
2962
2963StringRefExportEntry::name() const{
2964return CumulativeString;
2965}
2966
2967uint64_tExportEntry::flags() const{
2968return Stack.back().Flags;
2969}
2970
2971uint64_tExportEntry::address() const{
2972return Stack.back().Address;
2973}
2974
2975uint64_tExportEntry::other() const{
2976return Stack.back().Other;
2977}
2978
2979StringRefExportEntry::otherName() const{
2980constchar* ImportName = Stack.back().ImportName;
2981if (ImportName)
2982returnStringRef(ImportName);
2983returnStringRef();
2984}
2985
2986uint32_tExportEntry::nodeOffset() const{
2987return Stack.back().Start - Trie.begin();
2988}
2989
2990ExportEntry::NodeState::NodeState(constuint8_t *Ptr)
2991 : Start(Ptr), Current(Ptr) {}
2992
2993void ExportEntry::pushNode(uint64_t offset) {
2994ErrorAsOutParameter ErrAsOutParam(E);
2995constuint8_t *Ptr = Trie.begin() + offset;
2996 NodeState State(Ptr);
2997constchar *error =nullptr;
2998uint64_t ExportInfoSize = readULEB128(State.Current, &error);
2999if (error) {
3000 *E =malformedError("export info size " +Twine(error) +
3001" in export trie data at node: 0x" +
3002Twine::utohexstr(offset));
3003 moveToEnd();
3004return;
3005 }
3006 State.IsExportNode = (ExportInfoSize != 0);
3007constuint8_t* Children = State.Current + ExportInfoSize;
3008if (Children > Trie.end()) {
3009 *E =malformedError(
3010"export info size: 0x" +Twine::utohexstr(ExportInfoSize) +
3011" in export trie data at node: 0x" +Twine::utohexstr(offset) +
3012" too big and extends past end of trie data");
3013 moveToEnd();
3014return;
3015 }
3016if (State.IsExportNode) {
3017constuint8_t *ExportStart = State.Current;
3018 State.Flags = readULEB128(State.Current, &error);
3019if (error) {
3020 *E =malformedError("flags " +Twine(error) +
3021" in export trie data at node: 0x" +
3022Twine::utohexstr(offset));
3023 moveToEnd();
3024return;
3025 }
3026uint64_tKind = State.Flags &MachO::EXPORT_SYMBOL_FLAGS_KIND_MASK;
3027if (State.Flags != 0 &&
3028 (Kind !=MachO::EXPORT_SYMBOL_FLAGS_KIND_REGULAR &&
3029Kind !=MachO::EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE &&
3030Kind !=MachO::EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL)) {
3031 *E =malformedError(
3032"unsupported exported symbol kind: " +Twine((int)Kind) +
3033" in flags: 0x" +Twine::utohexstr(State.Flags) +
3034" in export trie data at node: 0x" +Twine::utohexstr(offset));
3035 moveToEnd();
3036return;
3037 }
3038if (State.Flags &MachO::EXPORT_SYMBOL_FLAGS_REEXPORT) {
3039 State.Address = 0;
3040 State.Other = readULEB128(State.Current, &error);// dylib ordinal
3041if (error) {
3042 *E =malformedError("dylib ordinal of re-export " +Twine(error) +
3043" in export trie data at node: 0x" +
3044Twine::utohexstr(offset));
3045 moveToEnd();
3046return;
3047 }
3048if (O !=nullptr) {
3049// Only positive numbers represent library ordinals. Zero and negative
3050// numbers have special meaning (see BindSpecialDylib).
3051if ((int64_t)State.Other > 0 && State.Other > O->getLibraryCount()) {
3052 *E =malformedError(
3053"bad library ordinal: " +Twine((int)State.Other) +" (max " +
3054Twine((int)O->getLibraryCount()) +
3055") in export trie data at node: 0x" +Twine::utohexstr(offset));
3056 moveToEnd();
3057return;
3058 }
3059 }
3060 State.ImportName =reinterpret_cast<constchar*>(State.Current);
3061if (*State.ImportName =='\0') {
3062 State.Current++;
3063 }else {
3064constuint8_t *End = State.Current + 1;
3065if (End >= Trie.end()) {
3066 *E =malformedError("import name of re-export in export trie data at "
3067"node: 0x" +
3068Twine::utohexstr(offset) +
3069" starts past end of trie data");
3070 moveToEnd();
3071return;
3072 }
3073while(*End !='\0' &&End < Trie.end())
3074End++;
3075if (*End !='\0') {
3076 *E =malformedError("import name of re-export in export trie data at "
3077"node: 0x" +
3078Twine::utohexstr(offset) +
3079" extends past end of trie data");
3080 moveToEnd();
3081return;
3082 }
3083 State.Current =End + 1;
3084 }
3085 }else {
3086 State.Address = readULEB128(State.Current, &error);
3087if (error) {
3088 *E =malformedError("address " +Twine(error) +
3089" in export trie data at node: 0x" +
3090Twine::utohexstr(offset));
3091 moveToEnd();
3092return;
3093 }
3094if (State.Flags &MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) {
3095 State.Other = readULEB128(State.Current, &error);
3096if (error) {
3097 *E =malformedError("resolver of stub and resolver " +Twine(error) +
3098" in export trie data at node: 0x" +
3099Twine::utohexstr(offset));
3100 moveToEnd();
3101return;
3102 }
3103 }
3104 }
3105if (ExportStart + ExportInfoSize < State.Current) {
3106 *E =malformedError(
3107"inconsistent export info size: 0x" +
3108Twine::utohexstr(ExportInfoSize) +" where actual size was: 0x" +
3109Twine::utohexstr(State.Current - ExportStart) +
3110" in export trie data at node: 0x" +Twine::utohexstr(offset));
3111 moveToEnd();
3112return;
3113 }
3114 }
3115 State.ChildCount = *Children;
3116if (State.ChildCount != 0 && Children + 1 >= Trie.end()) {
3117 *E =malformedError("byte for count of childern in export trie data at "
3118"node: 0x" +
3119Twine::utohexstr(offset) +
3120" extends past end of trie data");
3121 moveToEnd();
3122return;
3123 }
3124 State.Current =Children + 1;
3125 State.NextChildIndex = 0;
3126 State.ParentStringLength = CumulativeString.size();
3127 Stack.push_back(State);
3128}
3129
3130void ExportEntry::pushDownUntilBottom() {
3131ErrorAsOutParameter ErrAsOutParam(E);
3132constchar *error =nullptr;
3133while (Stack.back().NextChildIndex < Stack.back().ChildCount) {
3134 NodeState &Top = Stack.back();
3135 CumulativeString.resize(Top.ParentStringLength);
3136for (;*Top.Current != 0 && Top.Current < Trie.end(); Top.Current++) {
3137charC = *Top.Current;
3138 CumulativeString.push_back(C);
3139 }
3140if (Top.Current >= Trie.end()) {
3141 *E =malformedError("edge sub-string in export trie data at node: 0x" +
3142Twine::utohexstr(Top.Start - Trie.begin()) +
3143" for child #" +Twine((int)Top.NextChildIndex) +
3144" extends past end of trie data");
3145 moveToEnd();
3146return;
3147 }
3148 Top.Current += 1;
3149uint64_t childNodeIndex = readULEB128(Top.Current, &error);
3150if (error) {
3151 *E =malformedError("child node offset " +Twine(error) +
3152" in export trie data at node: 0x" +
3153Twine::utohexstr(Top.Start - Trie.begin()));
3154 moveToEnd();
3155return;
3156 }
3157for (const NodeState &node : nodes()) {
3158if (node.Start == Trie.begin() + childNodeIndex){
3159 *E =malformedError("loop in childern in export trie data at node: 0x" +
3160Twine::utohexstr(Top.Start - Trie.begin()) +
3161" back to node: 0x" +
3162Twine::utohexstr(childNodeIndex));
3163 moveToEnd();
3164return;
3165 }
3166 }
3167 Top.NextChildIndex += 1;
3168 pushNode(childNodeIndex);
3169if (*E)
3170return;
3171 }
3172if (!Stack.back().IsExportNode) {
3173 *E =malformedError("node is not an export node in export trie data at "
3174"node: 0x" +
3175Twine::utohexstr(Stack.back().Start - Trie.begin()));
3176 moveToEnd();
3177return;
3178 }
3179}
3180
3181// We have a trie data structure and need a way to walk it that is compatible
3182// with the C++ iterator model. The solution is a non-recursive depth first
3183// traversal where the iterator contains a stack of parent nodes along with a
3184// string that is the accumulation of all edge strings along the parent chain
3185// to this point.
3186//
3187// There is one "export" node for each exported symbol. But because some
3188// symbols may be a prefix of another symbol (e.g. _dup and _dup2), an export
3189// node may have child nodes too.
3190//
3191// The algorithm for moveNext() is to keep moving down the leftmost unvisited
3192// child until hitting a node with no children (which is an export node or
3193// else the trie is malformed). On the way down, each node is pushed on the
3194// stack ivar. If there is no more ways down, it pops up one and tries to go
3195// down a sibling path until a childless node is reached.
3196voidExportEntry::moveNext() {
3197assert(!Stack.empty() &&"ExportEntry::moveNext() with empty node stack");
3198if (!Stack.back().IsExportNode) {
3199 *E =malformedError("node is not an export node in export trie data at "
3200"node: 0x" +
3201Twine::utohexstr(Stack.back().Start - Trie.begin()));
3202 moveToEnd();
3203return;
3204 }
3205
3206 Stack.pop_back();
3207while (!Stack.empty()) {
3208 NodeState &Top = Stack.back();
3209if (Top.NextChildIndex < Top.ChildCount) {
3210 pushDownUntilBottom();
3211// Now at the next export node.
3212return;
3213 }else {
3214if (Top.IsExportNode) {
3215// This node has no children but is itself an export node.
3216 CumulativeString.resize(Top.ParentStringLength);
3217return;
3218 }
3219 Stack.pop_back();
3220 }
3221 }
3222 Done =true;
3223}
3224
3225iterator_range<export_iterator>
3226MachOObjectFile::exports(Error &E,ArrayRef<uint8_t> Trie,
3227constMachOObjectFile *O) {
3228ExportEntry Start(&E, O, Trie);
3229if (Trie.empty())
3230 Start.moveToEnd();
3231else
3232 Start.moveToFirst();
3233
3234ExportEntry Finish(&E, O, Trie);
3235 Finish.moveToEnd();
3236
3237returnmake_range(export_iterator(Start),export_iterator(Finish));
3238}
3239
3240iterator_range<export_iterator>MachOObjectFile::exports(Error &Err) const{
3241ArrayRef<uint8_t> Trie;
3242if (DyldInfoLoadCmd)
3243 Trie =getDyldInfoExportsTrie();
3244elseif (DyldExportsTrieLoadCmd)
3245 Trie =getDyldExportsTrie();
3246
3247returnexports(Err, Trie,this);
3248}
3249
3250MachOAbstractFixupEntry::MachOAbstractFixupEntry(Error *E,
3251constMachOObjectFile *O)
3252 : E(E), O(O) {
3253// Cache the vmaddress of __TEXT
3254for (constauto &Command :O->load_commands()) {
3255if (Command.C.cmd == MachO::LC_SEGMENT) {
3256MachO::segment_command SLC =O->getSegmentLoadCommand(Command);
3257if (StringRef(SLC.segname) =="__TEXT") {
3258 TextAddress = SLC.vmaddr;
3259break;
3260 }
3261 }elseif (Command.C.cmd == MachO::LC_SEGMENT_64) {
3262MachO::segment_command_64 SLC_64 =O->getSegment64LoadCommand(Command);
3263if (StringRef(SLC_64.segname) =="__TEXT") {
3264 TextAddress = SLC_64.vmaddr;
3265break;
3266 }
3267 }
3268 }
3269}
3270
3271int32_tMachOAbstractFixupEntry::segmentIndex() const{returnSegmentIndex; }
3272
3273uint64_tMachOAbstractFixupEntry::segmentOffset() const{
3274returnSegmentOffset;
3275}
3276
3277uint64_tMachOAbstractFixupEntry::segmentAddress() const{
3278returnO->BindRebaseAddress(SegmentIndex, 0);
3279}
3280
3281StringRefMachOAbstractFixupEntry::segmentName() const{
3282returnO->BindRebaseSegmentName(SegmentIndex);
3283}
3284
3285StringRefMachOAbstractFixupEntry::sectionName() const{
3286returnO->BindRebaseSectionName(SegmentIndex,SegmentOffset);
3287}
3288
3289uint64_tMachOAbstractFixupEntry::address() const{
3290returnO->BindRebaseAddress(SegmentIndex,SegmentOffset);
3291}
3292
3293StringRefMachOAbstractFixupEntry::symbolName() const{returnSymbolName; }
3294
3295int64_tMachOAbstractFixupEntry::addend() const{returnAddend; }
3296
3297uint32_tMachOAbstractFixupEntry::flags() const{returnFlags; }
3298
3299intMachOAbstractFixupEntry::ordinal() const{returnOrdinal; }
3300
3301StringRefMachOAbstractFixupEntry::typeName() const{return"unknown"; }
3302
3303voidMachOAbstractFixupEntry::moveToFirst() {
3304SegmentOffset = 0;
3305SegmentIndex = -1;
3306Ordinal = 0;
3307Flags = 0;
3308Addend = 0;
3309Done =false;
3310}
3311
3312voidMachOAbstractFixupEntry::moveToEnd() {Done =true; }
3313
3314voidMachOAbstractFixupEntry::moveNext() {}
3315
3316MachOChainedFixupEntry::MachOChainedFixupEntry(Error *E,
3317constMachOObjectFile *O,
3318bool Parse)
3319 :MachOAbstractFixupEntry(E, O) {
3320ErrorAsOutParameter e(E);
3321if (!Parse)
3322return;
3323
3324if (auto FixupTargetsOrErr =O->getDyldChainedFixupTargets()) {
3325 FixupTargets = *FixupTargetsOrErr;
3326 }else {
3327 *E = FixupTargetsOrErr.takeError();
3328return;
3329 }
3330
3331if (auto SegmentsOrErr =O->getChainedFixupsSegments()) {
3332 Segments = std::move(SegmentsOrErr->second);
3333 }else {
3334 *E = SegmentsOrErr.takeError();
3335return;
3336 }
3337}
3338
3339void MachOChainedFixupEntry::findNextPageWithFixups() {
3340auto FindInSegment = [this]() {
3341constChainedFixupsSegment &SegInfo = Segments[InfoSegIndex];
3342while (PageIndex < SegInfo.PageStarts.size() &&
3343 SegInfo.PageStarts[PageIndex] ==MachO::DYLD_CHAINED_PTR_START_NONE)
3344 ++PageIndex;
3345return PageIndex < SegInfo.PageStarts.size();
3346 };
3347
3348while (InfoSegIndex < Segments.size()) {
3349if (FindInSegment()) {
3350 PageOffset = Segments[InfoSegIndex].PageStarts[PageIndex];
3351 SegmentData =O->getSegmentContents(Segments[InfoSegIndex].SegIdx);
3352return;
3353 }
3354
3355 InfoSegIndex++;
3356 PageIndex = 0;
3357 }
3358}
3359
3360voidMachOChainedFixupEntry::moveToFirst() {
3361MachOAbstractFixupEntry::moveToFirst();
3362if (Segments.empty()) {
3363Done =true;
3364return;
3365 }
3366
3367 InfoSegIndex = 0;
3368 PageIndex = 0;
3369
3370 findNextPageWithFixups();
3371moveNext();
3372}
3373
3374voidMachOChainedFixupEntry::moveToEnd() {
3375MachOAbstractFixupEntry::moveToEnd();
3376}
3377
3378voidMachOChainedFixupEntry::moveNext() {
3379ErrorAsOutParameter ErrAsOutParam(E);
3380
3381if (InfoSegIndex == Segments.size()) {
3382Done =true;
3383return;
3384 }
3385
3386constChainedFixupsSegment &SegInfo = Segments[InfoSegIndex];
3387SegmentIndex = SegInfo.SegIdx;
3388SegmentOffset = SegInfo.Header.page_size * PageIndex + PageOffset;
3389
3390// FIXME: Handle other pointer formats.
3391uint16_t PointerFormat = SegInfo.Header.pointer_format;
3392if (PointerFormat !=MachO::DYLD_CHAINED_PTR_64 &&
3393 PointerFormat !=MachO::DYLD_CHAINED_PTR_64_OFFSET) {
3394 *E =createError("segment " +Twine(SegmentIndex) +
3395" has unsupported chained fixup pointer_format " +
3396Twine(PointerFormat));
3397moveToEnd();
3398return;
3399 }
3400
3401Ordinal = 0;
3402Flags = 0;
3403Addend = 0;
3404PointerValue = 0;
3405SymbolName = {};
3406
3407if (SegmentOffset +sizeof(RawValue) > SegmentData.size()) {
3408 *E =malformedError("fixup in segment " +Twine(SegmentIndex) +
3409" at offset " +Twine(SegmentOffset) +
3410" extends past segment's end");
3411moveToEnd();
3412return;
3413 }
3414
3415static_assert(sizeof(RawValue) ==sizeof(MachO::dyld_chained_import_addend));
3416 memcpy(&RawValue, SegmentData.data() +SegmentOffset,sizeof(RawValue));
3417if (O->isLittleEndian() !=sys::IsLittleEndianHost)
3418sys::swapByteOrder(RawValue);
3419
3420// The bit extraction below assumes little-endian fixup entries.
3421assert(O->isLittleEndian() &&"big-endian object should have been rejected "
3422"by getDyldChainedFixupTargets()");
3423autoField = [this](uint8_tRight,uint8_t Count) {
3424return (RawValue >>Right) & ((1ULL << Count) - 1);
3425 };
3426
3427// The `bind` field (most significant bit) of the encoded fixup determines
3428// whether it is dyld_chained_ptr_64_bind or dyld_chained_ptr_64_rebase.
3429bool IsBind =Field(63, 1);
3430Kind = IsBind ?FixupKind::Bind :FixupKind::Rebase;
3431uint32_t Next =Field(51, 12);
3432if (IsBind) {
3433uint32_t ImportOrdinal =Field(0, 24);
3434uint8_t InlineAddend =Field(24, 8);
3435
3436if (ImportOrdinal >= FixupTargets.size()) {
3437 *E =malformedError("fixup in segment " +Twine(SegmentIndex) +
3438" at offset " +Twine(SegmentOffset) +
3439" has out-of range import ordinal " +
3440Twine(ImportOrdinal));
3441moveToEnd();
3442return;
3443 }
3444
3445ChainedFixupTarget &Target = FixupTargets[ImportOrdinal];
3446Ordinal =Target.libOrdinal();
3447Addend = InlineAddend ? InlineAddend :Target.addend();
3448Flags =Target.weakImport() ?MachO::BIND_SYMBOL_FLAGS_WEAK_IMPORT : 0;
3449SymbolName =Target.symbolName();
3450 }else {
3451uint64_tTarget =Field(0, 36);
3452uint64_t High8 =Field(36, 8);
3453
3454PointerValue =Target | (High8 << 56);
3455if (PointerFormat ==MachO::DYLD_CHAINED_PTR_64_OFFSET)
3456PointerValue +=textAddress();
3457 }
3458
3459// The stride is 4 bytes for DYLD_CHAINED_PTR_64(_OFFSET).
3460if (Next != 0) {
3461 PageOffset += 4 * Next;
3462 }else {
3463 ++PageIndex;
3464 findNextPageWithFixups();
3465 }
3466}
3467
3468boolMachOChainedFixupEntry::operator==(
3469constMachOChainedFixupEntry &Other) const{
3470if (Done &&Other.Done)
3471returntrue;
3472if (Done !=Other.Done)
3473returnfalse;
3474return InfoSegIndex ==Other.InfoSegIndex && PageIndex ==Other.PageIndex &&
3475 PageOffset ==Other.PageOffset;
3476}
3477
3478MachORebaseEntry::MachORebaseEntry(Error *E,constMachOObjectFile *O,
3479ArrayRef<uint8_t> Bytes,boolis64Bit)
3480 : E(E), O(O), Opcodes(Bytes),Ptr(Bytes.begin()),
3481 PointerSize(is64Bit ? 8 : 4) {}
3482
3483void MachORebaseEntry::moveToFirst() {
3484Ptr = Opcodes.begin();
3485moveNext();
3486}
3487
3488void MachORebaseEntry::moveToEnd() {
3489Ptr = Opcodes.end();
3490 RemainingLoopCount = 0;
3491 Done =true;
3492}
3493
3494voidMachORebaseEntry::moveNext() {
3495ErrorAsOutParameter ErrAsOutParam(E);
3496// If in the middle of some loop, move to next rebasing in loop.
3497 SegmentOffset += AdvanceAmount;
3498if (RemainingLoopCount) {
3499 --RemainingLoopCount;
3500return;
3501 }
3502
3503bool More =true;
3504while (More) {
3505// REBASE_OPCODE_DONE is only used for padding if we are not aligned to
3506// pointer size. Therefore it is possible to reach the end without ever
3507// having seen REBASE_OPCODE_DONE.
3508if (Ptr == Opcodes.end()) {
3509 Done =true;
3510return;
3511 }
3512
3513// Parse next opcode and set up next loop.
3514constuint8_t *OpcodeStart =Ptr;
3515uint8_t Byte = *Ptr++;
3516uint8_t ImmValue = Byte &MachO::REBASE_IMMEDIATE_MASK;
3517uint8_t Opcode = Byte &MachO::REBASE_OPCODE_MASK;
3518uint64_t Count, Skip;
3519constchar *error =nullptr;
3520switch (Opcode) {
3521caseMachO::REBASE_OPCODE_DONE:
3522 More =false;
3523 Done =true;
3524 moveToEnd();
3525DEBUG_WITH_TYPE("mach-o-rebase",dbgs() <<"REBASE_OPCODE_DONE\n");
3526break;
3527caseMachO::REBASE_OPCODE_SET_TYPE_IMM:
3528 RebaseType = ImmValue;
3529if (RebaseType >MachO::REBASE_TYPE_TEXT_PCREL32) {
3530 *E =malformedError("for REBASE_OPCODE_SET_TYPE_IMM bad bind type: " +
3531Twine((int)RebaseType) +" for opcode at: 0x" +
3532Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3533 moveToEnd();
3534return;
3535 }
3536DEBUG_WITH_TYPE(
3537"mach-o-rebase",
3538dbgs() <<"REBASE_OPCODE_SET_TYPE_IMM: "
3539 <<"RebaseType=" << (int) RebaseType <<"\n");
3540break;
3541caseMachO::REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
3542 SegmentIndex = ImmValue;
3543 SegmentOffset = readULEB128(&error);
3544if (error) {
3545 *E =malformedError("for REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
3546Twine(error) +" for opcode at: 0x" +
3547Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3548 moveToEnd();
3549return;
3550 }
3551error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
3552 PointerSize);
3553if (error) {
3554 *E =malformedError("for REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
3555Twine(error) +" for opcode at: 0x" +
3556Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3557 moveToEnd();
3558return;
3559 }
3560DEBUG_WITH_TYPE(
3561"mach-o-rebase",
3562dbgs() <<"REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: "
3563 <<"SegmentIndex=" << SegmentIndex <<", "
3564 <<format("SegmentOffset=0x%06X", SegmentOffset)
3565 <<"\n");
3566break;
3567caseMachO::REBASE_OPCODE_ADD_ADDR_ULEB:
3568 SegmentOffset += readULEB128(&error);
3569if (error) {
3570 *E =malformedError("for REBASE_OPCODE_ADD_ADDR_ULEB " +Twine(error) +
3571" for opcode at: 0x" +
3572Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3573 moveToEnd();
3574return;
3575 }
3576error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
3577 PointerSize);
3578if (error) {
3579 *E =malformedError("for REBASE_OPCODE_ADD_ADDR_ULEB " +Twine(error) +
3580" for opcode at: 0x" +
3581Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3582 moveToEnd();
3583return;
3584 }
3585DEBUG_WITH_TYPE("mach-o-rebase",
3586dbgs() <<"REBASE_OPCODE_ADD_ADDR_ULEB: "
3587 <<format("SegmentOffset=0x%06X",
3588 SegmentOffset) <<"\n");
3589break;
3590caseMachO::REBASE_OPCODE_ADD_ADDR_IMM_SCALED:
3591 SegmentOffset += ImmValue * PointerSize;
3592error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
3593 PointerSize);
3594if (error) {
3595 *E =malformedError("for REBASE_OPCODE_ADD_ADDR_IMM_SCALED " +
3596Twine(error) +" for opcode at: 0x" +
3597Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3598 moveToEnd();
3599return;
3600 }
3601DEBUG_WITH_TYPE("mach-o-rebase",
3602dbgs() <<"REBASE_OPCODE_ADD_ADDR_IMM_SCALED: "
3603 <<format("SegmentOffset=0x%06X",
3604 SegmentOffset) <<"\n");
3605break;
3606caseMachO::REBASE_OPCODE_DO_REBASE_IMM_TIMES:
3607 AdvanceAmount = PointerSize;
3608 Skip = 0;
3609 Count = ImmValue;
3610if (ImmValue != 0)
3611 RemainingLoopCount = ImmValue - 1;
3612else
3613 RemainingLoopCount = 0;
3614error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
3615 PointerSize, Count, Skip);
3616if (error) {
3617 *E =malformedError("for REBASE_OPCODE_DO_REBASE_IMM_TIMES " +
3618Twine(error) +" for opcode at: 0x" +
3619Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3620 moveToEnd();
3621return;
3622 }
3623DEBUG_WITH_TYPE(
3624"mach-o-rebase",
3625dbgs() <<"REBASE_OPCODE_DO_REBASE_IMM_TIMES: "
3626 <<format("SegmentOffset=0x%06X", SegmentOffset)
3627 <<", AdvanceAmount=" << AdvanceAmount
3628 <<", RemainingLoopCount=" << RemainingLoopCount
3629 <<"\n");
3630return;
3631caseMachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES:
3632 AdvanceAmount = PointerSize;
3633 Skip = 0;
3634 Count = readULEB128(&error);
3635if (error) {
3636 *E =malformedError("for REBASE_OPCODE_DO_REBASE_ULEB_TIMES " +
3637Twine(error) +" for opcode at: 0x" +
3638Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3639 moveToEnd();
3640return;
3641 }
3642if (Count != 0)
3643 RemainingLoopCount = Count - 1;
3644else
3645 RemainingLoopCount = 0;
3646error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
3647 PointerSize, Count, Skip);
3648if (error) {
3649 *E =malformedError("for REBASE_OPCODE_DO_REBASE_ULEB_TIMES " +
3650Twine(error) +" for opcode at: 0x" +
3651Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3652 moveToEnd();
3653return;
3654 }
3655DEBUG_WITH_TYPE(
3656"mach-o-rebase",
3657dbgs() <<"REBASE_OPCODE_DO_REBASE_ULEB_TIMES: "
3658 <<format("SegmentOffset=0x%06X", SegmentOffset)
3659 <<", AdvanceAmount=" << AdvanceAmount
3660 <<", RemainingLoopCount=" << RemainingLoopCount
3661 <<"\n");
3662return;
3663caseMachO::REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB:
3664 Skip = readULEB128(&error);
3665if (error) {
3666 *E =malformedError("for REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB " +
3667Twine(error) +" for opcode at: 0x" +
3668Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3669 moveToEnd();
3670return;
3671 }
3672 AdvanceAmount = Skip + PointerSize;
3673 Count = 1;
3674 RemainingLoopCount = 0;
3675error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
3676 PointerSize, Count, Skip);
3677if (error) {
3678 *E =malformedError("for REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB " +
3679Twine(error) +" for opcode at: 0x" +
3680Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3681 moveToEnd();
3682return;
3683 }
3684DEBUG_WITH_TYPE(
3685"mach-o-rebase",
3686dbgs() <<"REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB: "
3687 <<format("SegmentOffset=0x%06X", SegmentOffset)
3688 <<", AdvanceAmount=" << AdvanceAmount
3689 <<", RemainingLoopCount=" << RemainingLoopCount
3690 <<"\n");
3691return;
3692caseMachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB:
3693 Count = readULEB128(&error);
3694if (error) {
3695 *E =malformedError("for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_"
3696"ULEB " +
3697Twine(error) +" for opcode at: 0x" +
3698Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3699 moveToEnd();
3700return;
3701 }
3702if (Count != 0)
3703 RemainingLoopCount = Count - 1;
3704else
3705 RemainingLoopCount = 0;
3706 Skip = readULEB128(&error);
3707if (error) {
3708 *E =malformedError("for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_"
3709"ULEB " +
3710Twine(error) +" for opcode at: 0x" +
3711Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3712 moveToEnd();
3713return;
3714 }
3715 AdvanceAmount = Skip + PointerSize;
3716
3717error = O->RebaseEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
3718 PointerSize, Count, Skip);
3719if (error) {
3720 *E =malformedError("for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_"
3721"ULEB " +
3722Twine(error) +" for opcode at: 0x" +
3723Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3724 moveToEnd();
3725return;
3726 }
3727DEBUG_WITH_TYPE(
3728"mach-o-rebase",
3729dbgs() <<"REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB: "
3730 <<format("SegmentOffset=0x%06X", SegmentOffset)
3731 <<", AdvanceAmount=" << AdvanceAmount
3732 <<", RemainingLoopCount=" << RemainingLoopCount
3733 <<"\n");
3734return;
3735default:
3736 *E =malformedError("bad rebase info (bad opcode value 0x" +
3737Twine::utohexstr(Opcode) +" for opcode at: 0x" +
3738Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3739 moveToEnd();
3740return;
3741 }
3742 }
3743}
3744
3745uint64_t MachORebaseEntry::readULEB128(constchar **error) {
3746unsigned Count;
3747uint64_t Result =decodeULEB128(Ptr, &Count, Opcodes.end(),error);
3748Ptr += Count;
3749if (Ptr > Opcodes.end())
3750Ptr = Opcodes.end();
3751return Result;
3752}
3753
3754int32_tMachORebaseEntry::segmentIndex() const{return SegmentIndex; }
3755
3756uint64_tMachORebaseEntry::segmentOffset() const{return SegmentOffset; }
3757
3758StringRefMachORebaseEntry::typeName() const{
3759switch (RebaseType) {
3760caseMachO::REBASE_TYPE_POINTER:
3761return"pointer";
3762caseMachO::REBASE_TYPE_TEXT_ABSOLUTE32:
3763return"text abs32";
3764caseMachO::REBASE_TYPE_TEXT_PCREL32:
3765return"text rel32";
3766 }
3767return"unknown";
3768}
3769
3770// For use with the SegIndex of a checked Mach-O Rebase entry
3771// to get the segment name.
3772StringRefMachORebaseEntry::segmentName() const{
3773return O->BindRebaseSegmentName(SegmentIndex);
3774}
3775
3776// For use with a SegIndex,SegOffset pair from a checked Mach-O Rebase entry
3777// to get the section name.
3778StringRefMachORebaseEntry::sectionName() const{
3779return O->BindRebaseSectionName(SegmentIndex, SegmentOffset);
3780}
3781
3782// For use with a SegIndex,SegOffset pair from a checked Mach-O Rebase entry
3783// to get the address.
3784uint64_tMachORebaseEntry::address() const{
3785return O->BindRebaseAddress(SegmentIndex, SegmentOffset);
3786}
3787
3788boolMachORebaseEntry::operator==(constMachORebaseEntry &Other) const{
3789#ifdef EXPENSIVE_CHECKS
3790assert(Opcodes ==Other.Opcodes &&"compare iterators of different files");
3791#else
3792assert(Opcodes.data() ==Other.Opcodes.data() &&"compare iterators of different files");
3793#endif
3794return (Ptr ==Other.Ptr) &&
3795 (RemainingLoopCount ==Other.RemainingLoopCount) &&
3796 (Done ==Other.Done);
3797}
3798
3799iterator_range<rebase_iterator>
3800MachOObjectFile::rebaseTable(Error &Err,MachOObjectFile *O,
3801ArrayRef<uint8_t> Opcodes,bool is64) {
3802if (O->BindRebaseSectionTable ==nullptr)
3803 O->BindRebaseSectionTable = std::make_unique<BindRebaseSegInfo>(O);
3804MachORebaseEntry Start(&Err, O, Opcodes, is64);
3805 Start.moveToFirst();
3806
3807MachORebaseEntry Finish(&Err, O, Opcodes, is64);
3808 Finish.moveToEnd();
3809
3810returnmake_range(rebase_iterator(Start),rebase_iterator(Finish));
3811}
3812
3813iterator_range<rebase_iterator>MachOObjectFile::rebaseTable(Error &Err) {
3814returnrebaseTable(Err,this,getDyldInfoRebaseOpcodes(),is64Bit());
3815}
3816
3817MachOBindEntry::MachOBindEntry(Error *E,constMachOObjectFile *O,
3818ArrayRef<uint8_t> Bytes,boolis64Bit,Kind BK)
3819 : E(E), O(O), Opcodes(Bytes),Ptr(Bytes.begin()),
3820 PointerSize(is64Bit ? 8 : 4), TableKind(BK) {}
3821
3822void MachOBindEntry::moveToFirst() {
3823Ptr = Opcodes.begin();
3824moveNext();
3825}
3826
3827void MachOBindEntry::moveToEnd() {
3828Ptr = Opcodes.end();
3829 RemainingLoopCount = 0;
3830 Done =true;
3831}
3832
3833voidMachOBindEntry::moveNext() {
3834ErrorAsOutParameter ErrAsOutParam(E);
3835// If in the middle of some loop, move to next binding in loop.
3836 SegmentOffset += AdvanceAmount;
3837if (RemainingLoopCount) {
3838 --RemainingLoopCount;
3839return;
3840 }
3841
3842bool More =true;
3843while (More) {
3844// BIND_OPCODE_DONE is only used for padding if we are not aligned to
3845// pointer size. Therefore it is possible to reach the end without ever
3846// having seen BIND_OPCODE_DONE.
3847if (Ptr == Opcodes.end()) {
3848 Done =true;
3849return;
3850 }
3851
3852// Parse next opcode and set up next loop.
3853constuint8_t *OpcodeStart =Ptr;
3854uint8_t Byte = *Ptr++;
3855uint8_t ImmValue = Byte &MachO::BIND_IMMEDIATE_MASK;
3856uint8_t Opcode = Byte &MachO::BIND_OPCODE_MASK;
3857 int8_t SignExtended;
3858constuint8_t *SymStart;
3859uint64_t Count, Skip;
3860constchar *error =nullptr;
3861switch (Opcode) {
3862caseMachO::BIND_OPCODE_DONE:
3863if (TableKind ==Kind::Lazy) {
3864// Lazying bindings have a DONE opcode between entries. Need to ignore
3865// it to advance to next entry. But need not if this is last entry.
3866bool NotLastEntry =false;
3867for (constuint8_t *P =Ptr;P < Opcodes.end(); ++P) {
3868if (*P) {
3869 NotLastEntry =true;
3870 }
3871 }
3872if (NotLastEntry)
3873break;
3874 }
3875 More =false;
3876 moveToEnd();
3877DEBUG_WITH_TYPE("mach-o-bind",dbgs() <<"BIND_OPCODE_DONE\n");
3878break;
3879caseMachO::BIND_OPCODE_SET_DYLIB_ORDINAL_IMM:
3880if (TableKind ==Kind::Weak) {
3881 *E =malformedError("BIND_OPCODE_SET_DYLIB_ORDINAL_IMM not allowed in "
3882"weak bind table for opcode at: 0x" +
3883Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3884 moveToEnd();
3885return;
3886 }
3887 Ordinal = ImmValue;
3888 LibraryOrdinalSet =true;
3889if (ImmValue > O->getLibraryCount()) {
3890 *E =malformedError("for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad "
3891"library ordinal: " +
3892Twine((int)ImmValue) +" (max " +
3893Twine((int)O->getLibraryCount()) +
3894") for opcode at: 0x" +
3895Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3896 moveToEnd();
3897return;
3898 }
3899DEBUG_WITH_TYPE(
3900"mach-o-bind",
3901dbgs() <<"BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: "
3902 <<"Ordinal=" << Ordinal <<"\n");
3903break;
3904caseMachO::BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB:
3905if (TableKind ==Kind::Weak) {
3906 *E =malformedError("BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB not allowed in "
3907"weak bind table for opcode at: 0x" +
3908Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3909 moveToEnd();
3910return;
3911 }
3912 Ordinal = readULEB128(&error);
3913 LibraryOrdinalSet =true;
3914if (error) {
3915 *E =malformedError("for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB " +
3916Twine(error) +" for opcode at: 0x" +
3917Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3918 moveToEnd();
3919return;
3920 }
3921if (Ordinal > (int)O->getLibraryCount()) {
3922 *E =malformedError("for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad "
3923"library ordinal: " +
3924Twine((int)Ordinal) +" (max " +
3925Twine((int)O->getLibraryCount()) +
3926") for opcode at: 0x" +
3927Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3928 moveToEnd();
3929return;
3930 }
3931DEBUG_WITH_TYPE(
3932"mach-o-bind",
3933dbgs() <<"BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: "
3934 <<"Ordinal=" << Ordinal <<"\n");
3935break;
3936caseMachO::BIND_OPCODE_SET_DYLIB_SPECIAL_IMM:
3937if (TableKind ==Kind::Weak) {
3938 *E =malformedError("BIND_OPCODE_SET_DYLIB_SPECIAL_IMM not allowed in "
3939"weak bind table for opcode at: 0x" +
3940Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3941 moveToEnd();
3942return;
3943 }
3944if (ImmValue) {
3945 SignExtended =MachO::BIND_OPCODE_MASK | ImmValue;
3946 Ordinal = SignExtended;
3947if (Ordinal <MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP) {
3948 *E =malformedError("for BIND_OPCODE_SET_DYLIB_SPECIAL_IMM unknown "
3949"special ordinal: " +
3950Twine((int)Ordinal) +" for opcode at: 0x" +
3951Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3952 moveToEnd();
3953return;
3954 }
3955 }else
3956 Ordinal = 0;
3957 LibraryOrdinalSet =true;
3958DEBUG_WITH_TYPE(
3959"mach-o-bind",
3960dbgs() <<"BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: "
3961 <<"Ordinal=" << Ordinal <<"\n");
3962break;
3963caseMachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM:
3964 Flags = ImmValue;
3965 SymStart =Ptr;
3966while (*Ptr && (Ptr < Opcodes.end())) {
3967 ++Ptr;
3968 }
3969if (Ptr == Opcodes.end()) {
3970 *E =malformedError(
3971"for BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM "
3972"symbol name extends past opcodes for opcode at: 0x" +
3973Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3974 moveToEnd();
3975return;
3976 }
3977 SymbolName =StringRef(reinterpret_cast<constchar*>(SymStart),
3978Ptr-SymStart);
3979 ++Ptr;
3980DEBUG_WITH_TYPE(
3981"mach-o-bind",
3982dbgs() <<"BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: "
3983 <<"SymbolName=" << SymbolName <<"\n");
3984if (TableKind ==Kind::Weak) {
3985if (ImmValue &MachO::BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION)
3986return;
3987 }
3988break;
3989caseMachO::BIND_OPCODE_SET_TYPE_IMM:
3990 BindType = ImmValue;
3991if (ImmValue >MachO::BIND_TYPE_TEXT_PCREL32) {
3992 *E =malformedError("for BIND_OPCODE_SET_TYPE_IMM bad bind type: " +
3993Twine((int)ImmValue) +" for opcode at: 0x" +
3994Twine::utohexstr(OpcodeStart - Opcodes.begin()));
3995 moveToEnd();
3996return;
3997 }
3998DEBUG_WITH_TYPE(
3999"mach-o-bind",
4000dbgs() <<"BIND_OPCODE_SET_TYPE_IMM: "
4001 <<"BindType=" << (int)BindType <<"\n");
4002break;
4003caseMachO::BIND_OPCODE_SET_ADDEND_SLEB:
4004 Addend = readSLEB128(&error);
4005if (error) {
4006 *E =malformedError("for BIND_OPCODE_SET_ADDEND_SLEB " +Twine(error) +
4007" for opcode at: 0x" +
4008Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4009 moveToEnd();
4010return;
4011 }
4012DEBUG_WITH_TYPE(
4013"mach-o-bind",
4014dbgs() <<"BIND_OPCODE_SET_ADDEND_SLEB: "
4015 <<"Addend=" << Addend <<"\n");
4016break;
4017caseMachO::BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
4018 SegmentIndex = ImmValue;
4019 SegmentOffset = readULEB128(&error);
4020if (error) {
4021 *E =malformedError("for BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
4022Twine(error) +" for opcode at: 0x" +
4023Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4024 moveToEnd();
4025return;
4026 }
4027error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
4028 PointerSize);
4029if (error) {
4030 *E =malformedError("for BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
4031Twine(error) +" for opcode at: 0x" +
4032Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4033 moveToEnd();
4034return;
4035 }
4036DEBUG_WITH_TYPE(
4037"mach-o-bind",
4038dbgs() <<"BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: "
4039 <<"SegmentIndex=" << SegmentIndex <<", "
4040 <<format("SegmentOffset=0x%06X", SegmentOffset)
4041 <<"\n");
4042break;
4043caseMachO::BIND_OPCODE_ADD_ADDR_ULEB:
4044 SegmentOffset += readULEB128(&error);
4045if (error) {
4046 *E =malformedError("for BIND_OPCODE_ADD_ADDR_ULEB " +Twine(error) +
4047" for opcode at: 0x" +
4048Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4049 moveToEnd();
4050return;
4051 }
4052error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
4053 PointerSize);
4054if (error) {
4055 *E =malformedError("for BIND_OPCODE_ADD_ADDR_ULEB " +Twine(error) +
4056" for opcode at: 0x" +
4057Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4058 moveToEnd();
4059return;
4060 }
4061DEBUG_WITH_TYPE("mach-o-bind",
4062dbgs() <<"BIND_OPCODE_ADD_ADDR_ULEB: "
4063 <<format("SegmentOffset=0x%06X",
4064 SegmentOffset) <<"\n");
4065break;
4066caseMachO::BIND_OPCODE_DO_BIND:
4067 AdvanceAmount = PointerSize;
4068 RemainingLoopCount = 0;
4069error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
4070 PointerSize);
4071if (error) {
4072 *E =malformedError("for BIND_OPCODE_DO_BIND " +Twine(error) +
4073" for opcode at: 0x" +
4074Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4075 moveToEnd();
4076return;
4077 }
4078if (SymbolName ==StringRef()) {
4079 *E =malformedError(
4080"for BIND_OPCODE_DO_BIND missing preceding "
4081"BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for opcode at: 0x" +
4082Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4083 moveToEnd();
4084return;
4085 }
4086if (!LibraryOrdinalSet && TableKind !=Kind::Weak) {
4087 *E =
4088malformedError("for BIND_OPCODE_DO_BIND missing preceding "
4089"BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode at: 0x" +
4090Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4091 moveToEnd();
4092return;
4093 }
4094DEBUG_WITH_TYPE("mach-o-bind",
4095dbgs() <<"BIND_OPCODE_DO_BIND: "
4096 <<format("SegmentOffset=0x%06X",
4097 SegmentOffset) <<"\n");
4098return;
4099caseMachO::BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB:
4100if (TableKind ==Kind::Lazy) {
4101 *E =malformedError("BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB not allowed in "
4102"lazy bind table for opcode at: 0x" +
4103Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4104 moveToEnd();
4105return;
4106 }
4107error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
4108 PointerSize);
4109if (error) {
4110 *E =malformedError("for BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB " +
4111Twine(error) +" for opcode at: 0x" +
4112Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4113 moveToEnd();
4114return;
4115 }
4116if (SymbolName ==StringRef()) {
4117 *E =malformedError(
4118"for BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB missing "
4119"preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for opcode "
4120"at: 0x" +
4121Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4122 moveToEnd();
4123return;
4124 }
4125if (!LibraryOrdinalSet && TableKind !=Kind::Weak) {
4126 *E =malformedError(
4127"for BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB missing "
4128"preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode at: 0x" +
4129Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4130 moveToEnd();
4131return;
4132 }
4133 AdvanceAmount = readULEB128(&error) + PointerSize;
4134if (error) {
4135 *E =malformedError("for BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB " +
4136Twine(error) +" for opcode at: 0x" +
4137Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4138 moveToEnd();
4139return;
4140 }
4141// Note, this is not really an error until the next bind but make no sense
4142// for a BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB to not be followed by another
4143// bind operation.
4144error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset +
4145 AdvanceAmount, PointerSize);
4146if (error) {
4147 *E =malformedError("for BIND_OPCODE_ADD_ADDR_ULEB (after adding "
4148"ULEB) " +
4149Twine(error) +" for opcode at: 0x" +
4150Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4151 moveToEnd();
4152return;
4153 }
4154 RemainingLoopCount = 0;
4155DEBUG_WITH_TYPE(
4156"mach-o-bind",
4157dbgs() <<"BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: "
4158 <<format("SegmentOffset=0x%06X", SegmentOffset)
4159 <<", AdvanceAmount=" << AdvanceAmount
4160 <<", RemainingLoopCount=" << RemainingLoopCount
4161 <<"\n");
4162return;
4163caseMachO::BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED:
4164if (TableKind ==Kind::Lazy) {
4165 *E =malformedError("BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED not "
4166"allowed in lazy bind table for opcode at: 0x" +
4167Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4168 moveToEnd();
4169return;
4170 }
4171if (SymbolName ==StringRef()) {
4172 *E =malformedError(
4173"for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED "
4174"missing preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for "
4175"opcode at: 0x" +
4176Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4177 moveToEnd();
4178return;
4179 }
4180if (!LibraryOrdinalSet && TableKind !=Kind::Weak) {
4181 *E =malformedError(
4182"for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED "
4183"missing preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode "
4184"at: 0x" +
4185Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4186 moveToEnd();
4187return;
4188 }
4189 AdvanceAmount = ImmValue * PointerSize + PointerSize;
4190 RemainingLoopCount = 0;
4191error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset +
4192 AdvanceAmount, PointerSize);
4193if (error) {
4194 *E =malformedError("for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " +
4195Twine(error) +" for opcode at: 0x" +
4196Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4197 moveToEnd();
4198return;
4199 }
4200DEBUG_WITH_TYPE("mach-o-bind",
4201dbgs()
4202 <<"BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: "
4203 <<format("SegmentOffset=0x%06X", SegmentOffset) <<"\n");
4204return;
4205caseMachO::BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:
4206if (TableKind ==Kind::Lazy) {
4207 *E =malformedError("BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB not "
4208"allowed in lazy bind table for opcode at: 0x" +
4209Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4210 moveToEnd();
4211return;
4212 }
4213 Count = readULEB128(&error);
4214if (Count != 0)
4215 RemainingLoopCount = Count - 1;
4216else
4217 RemainingLoopCount = 0;
4218if (error) {
4219 *E =malformedError("for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
4220" (count value) " +
4221Twine(error) +" for opcode at: 0x" +
4222Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4223 moveToEnd();
4224return;
4225 }
4226 Skip = readULEB128(&error);
4227 AdvanceAmount = Skip + PointerSize;
4228if (error) {
4229 *E =malformedError("for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
4230" (skip value) " +
4231Twine(error) +" for opcode at: 0x" +
4232Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4233 moveToEnd();
4234return;
4235 }
4236if (SymbolName ==StringRef()) {
4237 *E =malformedError(
4238"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
4239"missing preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for "
4240"opcode at: 0x" +
4241Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4242 moveToEnd();
4243return;
4244 }
4245if (!LibraryOrdinalSet && TableKind !=Kind::Weak) {
4246 *E =malformedError(
4247"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
4248"missing preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode "
4249"at: 0x" +
4250Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4251 moveToEnd();
4252return;
4253 }
4254error = O->BindEntryCheckSegAndOffsets(SegmentIndex, SegmentOffset,
4255 PointerSize, Count, Skip);
4256if (error) {
4257 *E =
4258malformedError("for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB " +
4259Twine(error) +" for opcode at: 0x" +
4260Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4261 moveToEnd();
4262return;
4263 }
4264DEBUG_WITH_TYPE(
4265"mach-o-bind",
4266dbgs() <<"BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: "
4267 <<format("SegmentOffset=0x%06X", SegmentOffset)
4268 <<", AdvanceAmount=" << AdvanceAmount
4269 <<", RemainingLoopCount=" << RemainingLoopCount
4270 <<"\n");
4271return;
4272default:
4273 *E =malformedError("bad bind info (bad opcode value 0x" +
4274Twine::utohexstr(Opcode) +" for opcode at: 0x" +
4275Twine::utohexstr(OpcodeStart - Opcodes.begin()));
4276 moveToEnd();
4277return;
4278 }
4279 }
4280}
4281
4282uint64_t MachOBindEntry::readULEB128(constchar **error) {
4283unsigned Count;
4284uint64_t Result =decodeULEB128(Ptr, &Count, Opcodes.end(),error);
4285Ptr += Count;
4286if (Ptr > Opcodes.end())
4287Ptr = Opcodes.end();
4288return Result;
4289}
4290
4291int64_t MachOBindEntry::readSLEB128(constchar **error) {
4292unsigned Count;
4293 int64_t Result =decodeSLEB128(Ptr, &Count, Opcodes.end(),error);
4294Ptr += Count;
4295if (Ptr > Opcodes.end())
4296Ptr = Opcodes.end();
4297return Result;
4298}
4299
4300int32_tMachOBindEntry::segmentIndex() const{return SegmentIndex; }
4301
4302uint64_tMachOBindEntry::segmentOffset() const{return SegmentOffset; }
4303
4304StringRefMachOBindEntry::typeName() const{
4305switch (BindType) {
4306caseMachO::BIND_TYPE_POINTER:
4307return"pointer";
4308caseMachO::BIND_TYPE_TEXT_ABSOLUTE32:
4309return"text abs32";
4310caseMachO::BIND_TYPE_TEXT_PCREL32:
4311return"text rel32";
4312 }
4313return"unknown";
4314}
4315
4316StringRefMachOBindEntry::symbolName() const{return SymbolName; }
4317
4318int64_tMachOBindEntry::addend() const{return Addend; }
4319
4320uint32_tMachOBindEntry::flags() const{return Flags; }
4321
4322intMachOBindEntry::ordinal() const{return Ordinal; }
4323
4324// For use with the SegIndex of a checked Mach-O Bind entry
4325// to get the segment name.
4326StringRefMachOBindEntry::segmentName() const{
4327return O->BindRebaseSegmentName(SegmentIndex);
4328}
4329
4330// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind entry
4331// to get the section name.
4332StringRefMachOBindEntry::sectionName() const{
4333return O->BindRebaseSectionName(SegmentIndex, SegmentOffset);
4334}
4335
4336// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind entry
4337// to get the address.
4338uint64_tMachOBindEntry::address() const{
4339return O->BindRebaseAddress(SegmentIndex, SegmentOffset);
4340}
4341
4342boolMachOBindEntry::operator==(constMachOBindEntry &Other) const{
4343#ifdef EXPENSIVE_CHECKS
4344assert(Opcodes ==Other.Opcodes &&"compare iterators of different files");
4345#else
4346assert(Opcodes.data() ==Other.Opcodes.data() &&"compare iterators of different files");
4347#endif
4348return (Ptr ==Other.Ptr) &&
4349 (RemainingLoopCount ==Other.RemainingLoopCount) &&
4350 (Done ==Other.Done);
4351}
4352
4353// Build table of sections so SegIndex/SegOffset pairs can be translated.
4354BindRebaseSegInfo::BindRebaseSegInfo(constobject::MachOObjectFile *Obj) {
4355uint32_t CurSegIndex = Obj->hasPageZeroSegment() ? 1 : 0;
4356StringRef CurSegName;
4357uint64_t CurSegAddress;
4358for (constSectionRef &Section : Obj->sections()) {
4359 SectionInfoInfo;
4360Expected<StringRef> NameOrErr = Section.getName();
4361if (!NameOrErr)
4362consumeError(NameOrErr.takeError());
4363else
4364Info.SectionName = *NameOrErr;
4365Info.Address = Section.getAddress();
4366Info.Size = Section.getSize();
4367Info.SegmentName =
4368 Obj->getSectionFinalSegmentName(Section.getRawDataRefImpl());
4369if (Info.SegmentName != CurSegName) {
4370 ++CurSegIndex;
4371 CurSegName =Info.SegmentName;
4372 CurSegAddress =Info.Address;
4373 }
4374Info.SegmentIndex = CurSegIndex - 1;
4375Info.OffsetInSegment =Info.Address - CurSegAddress;
4376Info.SegmentStartAddress = CurSegAddress;
4377 Sections.push_back(Info);
4378 }
4379 MaxSegIndex = CurSegIndex;
4380}
4381
4382// For use with a SegIndex, SegOffset, and PointerSize triple in
4383// MachOBindEntry::moveNext() to validate a MachOBindEntry or MachORebaseEntry.
4384//
4385// Given a SegIndex, SegOffset, and PointerSize, verify a valid section exists
4386// that fully contains a pointer at that location. Multiple fixups in a bind
4387// (such as with the BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB opcode) can
4388// be tested via the Count and Skip parameters.
4389constchar *BindRebaseSegInfo::checkSegAndOffsets(int32_t SegIndex,
4390uint64_t SegOffset,
4391uint8_t PointerSize,
4392uint64_t Count,
4393uint64_t Skip) {
4394if (SegIndex == -1)
4395return"missing preceding *_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB";
4396if (SegIndex >= MaxSegIndex)
4397return"bad segIndex (too large)";
4398for (uint64_t i = 0; i < Count; ++i) {
4399uint64_t Start = SegOffset + i * (PointerSize + Skip);
4400uint64_tEnd = Start + PointerSize;
4401bool Found =false;
4402for (const SectionInfo &SI : Sections) {
4403if (SI.SegmentIndex != SegIndex)
4404continue;
4405if ((SI.OffsetInSegment<=Start) && (Start<(SI.OffsetInSegment+SI.Size))) {
4406if (End <= SI.OffsetInSegment + SI.Size) {
4407 Found =true;
4408break;
4409 }
4410else
4411return"bad offset, extends beyond section boundary";
4412 }
4413 }
4414if (!Found)
4415return"bad offset, not in section";
4416 }
4417returnnullptr;
4418}
4419
4420// For use with the SegIndex of a checked Mach-O Bind or Rebase entry
4421// to get the segment name.
4422StringRefBindRebaseSegInfo::segmentName(int32_t SegIndex) {
4423for (const SectionInfo &SI : Sections) {
4424if (SI.SegmentIndex == SegIndex)
4425return SI.SegmentName;
4426 }
4427llvm_unreachable("invalid SegIndex");
4428}
4429
4430// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or Rebase
4431// to get the SectionInfo.
4432const BindRebaseSegInfo::SectionInfo &BindRebaseSegInfo::findSection(
4433 int32_t SegIndex,uint64_t SegOffset) {
4434for (const SectionInfo &SI : Sections) {
4435if (SI.SegmentIndex != SegIndex)
4436continue;
4437if (SI.OffsetInSegment > SegOffset)
4438continue;
4439if (SegOffset >= (SI.OffsetInSegment + SI.Size))
4440continue;
4441return SI;
4442 }
4443llvm_unreachable("SegIndex and SegOffset not in any section");
4444}
4445
4446// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or Rebase
4447// entry to get the section name.
4448StringRefBindRebaseSegInfo::sectionName(int32_t SegIndex,
4449uint64_t SegOffset) {
4450return findSection(SegIndex, SegOffset).SectionName;
4451}
4452
4453// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or Rebase
4454// entry to get the address.
4455uint64_tBindRebaseSegInfo::address(uint32_t SegIndex,uint64_t OffsetInSeg) {
4456const SectionInfo &SI = findSection(SegIndex, OffsetInSeg);
4457return SI.SegmentStartAddress + OffsetInSeg;
4458}
4459
4460iterator_range<bind_iterator>
4461MachOObjectFile::bindTable(Error &Err,MachOObjectFile *O,
4462ArrayRef<uint8_t> Opcodes,bool is64,
4463MachOBindEntry::Kind BKind) {
4464if (O->BindRebaseSectionTable ==nullptr)
4465 O->BindRebaseSectionTable = std::make_unique<BindRebaseSegInfo>(O);
4466MachOBindEntry Start(&Err, O, Opcodes, is64, BKind);
4467 Start.moveToFirst();
4468
4469MachOBindEntry Finish(&Err, O, Opcodes, is64, BKind);
4470 Finish.moveToEnd();
4471
4472returnmake_range(bind_iterator(Start),bind_iterator(Finish));
4473}
4474
4475iterator_range<bind_iterator>MachOObjectFile::bindTable(Error &Err) {
4476returnbindTable(Err,this,getDyldInfoBindOpcodes(),is64Bit(),
4477MachOBindEntry::Kind::Regular);
4478}
4479
4480iterator_range<bind_iterator>MachOObjectFile::lazyBindTable(Error &Err) {
4481returnbindTable(Err,this,getDyldInfoLazyBindOpcodes(),is64Bit(),
4482MachOBindEntry::Kind::Lazy);
4483}
4484
4485iterator_range<bind_iterator>MachOObjectFile::weakBindTable(Error &Err) {
4486returnbindTable(Err,this,getDyldInfoWeakBindOpcodes(),is64Bit(),
4487MachOBindEntry::Kind::Weak);
4488}
4489
4490iterator_range<fixup_iterator>MachOObjectFile::fixupTable(Error &Err) {
4491if (BindRebaseSectionTable ==nullptr)
4492 BindRebaseSectionTable = std::make_unique<BindRebaseSegInfo>(this);
4493
4494MachOChainedFixupEntry Start(&Err,this,true);
4495 Start.moveToFirst();
4496
4497MachOChainedFixupEntry Finish(&Err,this,false);
4498 Finish.moveToEnd();
4499
4500returnmake_range(fixup_iterator(Start),fixup_iterator(Finish));
4501}
4502
4503MachOObjectFile::load_command_iterator
4504MachOObjectFile::begin_load_commands() const{
4505return LoadCommands.begin();
4506}
4507
4508MachOObjectFile::load_command_iterator
4509MachOObjectFile::end_load_commands() const{
4510return LoadCommands.end();
4511}
4512
4513iterator_range<MachOObjectFile::load_command_iterator>
4514MachOObjectFile::load_commands() const{
4515returnmake_range(begin_load_commands(),end_load_commands());
4516}
4517
4518StringRef
4519MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec) const{
4520ArrayRef<char> Raw =getSectionRawFinalSegmentName(Sec);
4521returnparseSegmentOrSectionName(Raw.data());
4522}
4523
4524ArrayRef<char>
4525MachOObjectFile::getSectionRawName(DataRefImpl Sec) const{
4526assert(Sec.d.a < Sections.size() &&"Should have detected this earlier");
4527const section_base *Base =
4528reinterpret_cast<constsection_base *>(Sections[Sec.d.a]);
4529returnArrayRef(Base->sectname);
4530}
4531
4532ArrayRef<char>
4533MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const{
4534assert(Sec.d.a < Sections.size() &&"Should have detected this earlier");
4535const section_base *Base =
4536reinterpret_cast<constsection_base *>(Sections[Sec.d.a]);
4537returnArrayRef(Base->segname);
4538}
4539
4540bool
4541MachOObjectFile::isRelocationScattered(constMachO::any_relocation_info &RE)
4542 const{
4543if (getCPUType(*this) ==MachO::CPU_TYPE_X86_64)
4544returnfalse;
4545returngetPlainRelocationAddress(RE) &MachO::R_SCATTERED;
4546}
4547
4548unsignedMachOObjectFile::getPlainRelocationSymbolNum(
4549constMachO::any_relocation_info &RE) const{
4550if (isLittleEndian())
4551return RE.r_word1 & 0xffffff;
4552return RE.r_word1 >> 8;
4553}
4554
4555boolMachOObjectFile::getPlainRelocationExternal(
4556constMachO::any_relocation_info &RE) const{
4557if (isLittleEndian())
4558return (RE.r_word1 >> 27) & 1;
4559return (RE.r_word1 >> 4) & 1;
4560}
4561
4562boolMachOObjectFile::getScatteredRelocationScattered(
4563constMachO::any_relocation_info &RE) const{
4564return RE.r_word0 >> 31;
4565}
4566
4567uint32_tMachOObjectFile::getScatteredRelocationValue(
4568constMachO::any_relocation_info &RE) const{
4569return RE.r_word1;
4570}
4571
4572uint32_tMachOObjectFile::getScatteredRelocationType(
4573constMachO::any_relocation_info &RE) const{
4574return (RE.r_word0 >> 24) & 0xf;
4575}
4576
4577unsignedMachOObjectFile::getAnyRelocationAddress(
4578constMachO::any_relocation_info &RE) const{
4579if (isRelocationScattered(RE))
4580returngetScatteredRelocationAddress(RE);
4581returngetPlainRelocationAddress(RE);
4582}
4583
4584unsignedMachOObjectFile::getAnyRelocationPCRel(
4585constMachO::any_relocation_info &RE) const{
4586if (isRelocationScattered(RE))
4587returngetScatteredRelocationPCRel(RE);
4588returngetPlainRelocationPCRel(*this, RE);
4589}
4590
4591unsignedMachOObjectFile::getAnyRelocationLength(
4592constMachO::any_relocation_info &RE) const{
4593if (isRelocationScattered(RE))
4594returngetScatteredRelocationLength(RE);
4595returngetPlainRelocationLength(*this, RE);
4596}
4597
4598unsigned
4599MachOObjectFile::getAnyRelocationType(
4600constMachO::any_relocation_info &RE) const{
4601if (isRelocationScattered(RE))
4602returngetScatteredRelocationType(RE);
4603returngetPlainRelocationType(*this, RE);
4604}
4605
4606SectionRef
4607MachOObjectFile::getAnyRelocationSection(
4608constMachO::any_relocation_info &RE) const{
4609if (isRelocationScattered(RE) ||getPlainRelocationExternal(RE))
4610return *section_end();
4611unsigned SecNum =getPlainRelocationSymbolNum(RE);
4612if (SecNum ==MachO::R_ABS || SecNum > Sections.size())
4613return *section_end();
4614DataRefImpl DRI;
4615 DRI.d.a = SecNum - 1;
4616returnSectionRef(DRI,this);
4617}
4618
4619MachO::sectionMachOObjectFile::getSection(DataRefImpl DRI) const{
4620assert(DRI.d.a < Sections.size() &&"Should have detected this earlier");
4621return getStruct<MachO::section>(*this, Sections[DRI.d.a]);
4622}
4623
4624MachO::section_64MachOObjectFile::getSection64(DataRefImpl DRI) const{
4625assert(DRI.d.a < Sections.size() &&"Should have detected this earlier");
4626return getStruct<MachO::section_64>(*this, Sections[DRI.d.a]);
4627}
4628
4629MachO::sectionMachOObjectFile::getSection(constLoadCommandInfo &L,
4630unsigned Index) const{
4631constchar *Sec =getSectionPtr(*this, L, Index);
4632return getStruct<MachO::section>(*this, Sec);
4633}
4634
4635MachO::section_64MachOObjectFile::getSection64(constLoadCommandInfo &L,
4636unsigned Index) const{
4637constchar *Sec =getSectionPtr(*this, L, Index);
4638return getStruct<MachO::section_64>(*this, Sec);
4639}
4640
4641MachO::nlist
4642MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const{
4643constchar *P =reinterpret_cast<constchar *>(DRI.p);
4644return getStruct<MachO::nlist>(*this,P);
4645}
4646
4647MachO::nlist_64
4648MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const{
4649constchar *P =reinterpret_cast<constchar *>(DRI.p);
4650return getStruct<MachO::nlist_64>(*this,P);
4651}
4652
4653MachO::linkedit_data_command
4654MachOObjectFile::getLinkeditDataLoadCommand(constLoadCommandInfo &L) const{
4655return getStruct<MachO::linkedit_data_command>(*this, L.Ptr);
4656}
4657
4658MachO::segment_command
4659MachOObjectFile::getSegmentLoadCommand(constLoadCommandInfo &L) const{
4660return getStruct<MachO::segment_command>(*this, L.Ptr);
4661}
4662
4663MachO::segment_command_64
4664MachOObjectFile::getSegment64LoadCommand(constLoadCommandInfo &L) const{
4665return getStruct<MachO::segment_command_64>(*this, L.Ptr);
4666}
4667
4668MachO::linker_option_command
4669MachOObjectFile::getLinkerOptionLoadCommand(constLoadCommandInfo &L) const{
4670return getStruct<MachO::linker_option_command>(*this, L.Ptr);
4671}
4672
4673MachO::version_min_command
4674MachOObjectFile::getVersionMinLoadCommand(constLoadCommandInfo &L) const{
4675return getStruct<MachO::version_min_command>(*this, L.Ptr);
4676}
4677
4678MachO::note_command
4679MachOObjectFile::getNoteLoadCommand(constLoadCommandInfo &L) const{
4680return getStruct<MachO::note_command>(*this, L.Ptr);
4681}
4682
4683MachO::build_version_command
4684MachOObjectFile::getBuildVersionLoadCommand(constLoadCommandInfo &L) const{
4685return getStruct<MachO::build_version_command>(*this, L.Ptr);
4686}
4687
4688MachO::build_tool_version
4689MachOObjectFile::getBuildToolVersion(unsigned index) const{
4690return getStruct<MachO::build_tool_version>(*this, BuildTools[index]);
4691}
4692
4693MachO::dylib_command
4694MachOObjectFile::getDylibIDLoadCommand(constLoadCommandInfo &L) const{
4695return getStruct<MachO::dylib_command>(*this, L.Ptr);
4696}
4697
4698MachO::dyld_info_command
4699MachOObjectFile::getDyldInfoLoadCommand(constLoadCommandInfo &L) const{
4700return getStruct<MachO::dyld_info_command>(*this, L.Ptr);
4701}
4702
4703MachO::dylinker_command
4704MachOObjectFile::getDylinkerCommand(constLoadCommandInfo &L) const{
4705return getStruct<MachO::dylinker_command>(*this, L.Ptr);
4706}
4707
4708MachO::uuid_command
4709MachOObjectFile::getUuidCommand(constLoadCommandInfo &L) const{
4710return getStruct<MachO::uuid_command>(*this, L.Ptr);
4711}
4712
4713MachO::rpath_command
4714MachOObjectFile::getRpathCommand(constLoadCommandInfo &L) const{
4715return getStruct<MachO::rpath_command>(*this, L.Ptr);
4716}
4717
4718MachO::source_version_command
4719MachOObjectFile::getSourceVersionCommand(constLoadCommandInfo &L) const{
4720return getStruct<MachO::source_version_command>(*this, L.Ptr);
4721}
4722
4723MachO::entry_point_command
4724MachOObjectFile::getEntryPointCommand(constLoadCommandInfo &L) const{
4725return getStruct<MachO::entry_point_command>(*this, L.Ptr);
4726}
4727
4728MachO::encryption_info_command
4729MachOObjectFile::getEncryptionInfoCommand(constLoadCommandInfo &L) const{
4730return getStruct<MachO::encryption_info_command>(*this, L.Ptr);
4731}
4732
4733MachO::encryption_info_command_64
4734MachOObjectFile::getEncryptionInfoCommand64(constLoadCommandInfo &L) const{
4735return getStruct<MachO::encryption_info_command_64>(*this, L.Ptr);
4736}
4737
4738MachO::sub_framework_command
4739MachOObjectFile::getSubFrameworkCommand(constLoadCommandInfo &L) const{
4740return getStruct<MachO::sub_framework_command>(*this, L.Ptr);
4741}
4742
4743MachO::sub_umbrella_command
4744MachOObjectFile::getSubUmbrellaCommand(constLoadCommandInfo &L) const{
4745return getStruct<MachO::sub_umbrella_command>(*this, L.Ptr);
4746}
4747
4748MachO::sub_library_command
4749MachOObjectFile::getSubLibraryCommand(constLoadCommandInfo &L) const{
4750return getStruct<MachO::sub_library_command>(*this, L.Ptr);
4751}
4752
4753MachO::sub_client_command
4754MachOObjectFile::getSubClientCommand(constLoadCommandInfo &L) const{
4755return getStruct<MachO::sub_client_command>(*this, L.Ptr);
4756}
4757
4758MachO::routines_command
4759MachOObjectFile::getRoutinesCommand(constLoadCommandInfo &L) const{
4760return getStruct<MachO::routines_command>(*this, L.Ptr);
4761}
4762
4763MachO::routines_command_64
4764MachOObjectFile::getRoutinesCommand64(constLoadCommandInfo &L) const{
4765return getStruct<MachO::routines_command_64>(*this, L.Ptr);
4766}
4767
4768MachO::thread_command
4769MachOObjectFile::getThreadCommand(constLoadCommandInfo &L) const{
4770return getStruct<MachO::thread_command>(*this, L.Ptr);
4771}
4772
4773MachO::fileset_entry_command
4774MachOObjectFile::getFilesetEntryLoadCommand(constLoadCommandInfo &L) const{
4775return getStruct<MachO::fileset_entry_command>(*this, L.Ptr);
4776}
4777
4778MachO::any_relocation_info
4779MachOObjectFile::getRelocation(DataRefImpl Rel) const{
4780uint32_tOffset;
4781if (getHeader().filetype ==MachO::MH_OBJECT) {
4782DataRefImpl Sec;
4783 Sec.d.a = Rel.d.a;
4784if (is64Bit()) {
4785MachO::section_64 Sect =getSection64(Sec);
4786Offset = Sect.reloff;
4787 }else {
4788MachO::section Sect =getSection(Sec);
4789Offset = Sect.reloff;
4790 }
4791 }else {
4792MachO::dysymtab_command DysymtabLoadCmd =getDysymtabLoadCommand();
4793if (Rel.d.a == 0)
4794Offset = DysymtabLoadCmd.extreloff;// Offset to the external relocations
4795else
4796Offset = DysymtabLoadCmd.locreloff;// Offset to the local relocations
4797 }
4798
4799autoP =reinterpret_cast<constMachO::any_relocation_info *>(
4800getPtr(*this,Offset)) + Rel.d.b;
4801return getStruct<MachO::any_relocation_info>(
4802 *this,reinterpret_cast<constchar *>(P));
4803}
4804
4805MachO::data_in_code_entry
4806MachOObjectFile::getDice(DataRefImpl Rel) const{
4807constchar *P =reinterpret_cast<constchar *>(Rel.p);
4808return getStruct<MachO::data_in_code_entry>(*this,P);
4809}
4810
4811constMachO::mach_header &MachOObjectFile::getHeader() const{
4812returnHeader;
4813}
4814
4815constMachO::mach_header_64 &MachOObjectFile::getHeader64() const{
4816assert(is64Bit());
4817returnHeader64;
4818}
4819
4820uint32_tMachOObjectFile::getIndirectSymbolTableEntry(
4821constMachO::dysymtab_command &DLC,
4822unsigned Index) const{
4823uint64_tOffset = DLC.indirectsymoff + Index *sizeof(uint32_t);
4824return getStruct<uint32_t>(*this,getPtr(*this,Offset));
4825}
4826
4827MachO::data_in_code_entry
4828MachOObjectFile::getDataInCodeTableEntry(uint32_t DataOffset,
4829unsigned Index) const{
4830uint64_tOffset = DataOffset + Index *sizeof(MachO::data_in_code_entry);
4831return getStruct<MachO::data_in_code_entry>(*this,getPtr(*this,Offset));
4832}
4833
4834MachO::symtab_commandMachOObjectFile::getSymtabLoadCommand() const{
4835if (SymtabLoadCmd)
4836return getStruct<MachO::symtab_command>(*this, SymtabLoadCmd);
4837
4838// If there is no SymtabLoadCmd return a load command with zero'ed fields.
4839MachO::symtab_command Cmd;
4840 Cmd.cmd = MachO::LC_SYMTAB;
4841 Cmd.cmdsize =sizeof(MachO::symtab_command);
4842 Cmd.symoff = 0;
4843 Cmd.nsyms = 0;
4844 Cmd.stroff = 0;
4845 Cmd.strsize = 0;
4846return Cmd;
4847}
4848
4849MachO::dysymtab_commandMachOObjectFile::getDysymtabLoadCommand() const{
4850if (DysymtabLoadCmd)
4851return getStruct<MachO::dysymtab_command>(*this, DysymtabLoadCmd);
4852
4853// If there is no DysymtabLoadCmd return a load command with zero'ed fields.
4854MachO::dysymtab_command Cmd;
4855 Cmd.cmd = MachO::LC_DYSYMTAB;
4856 Cmd.cmdsize =sizeof(MachO::dysymtab_command);
4857 Cmd.ilocalsym = 0;
4858 Cmd.nlocalsym = 0;
4859 Cmd.iextdefsym = 0;
4860 Cmd.nextdefsym = 0;
4861 Cmd.iundefsym = 0;
4862 Cmd.nundefsym = 0;
4863 Cmd.tocoff = 0;
4864 Cmd.ntoc = 0;
4865 Cmd.modtaboff = 0;
4866 Cmd.nmodtab = 0;
4867 Cmd.extrefsymoff = 0;
4868 Cmd.nextrefsyms = 0;
4869 Cmd.indirectsymoff = 0;
4870 Cmd.nindirectsyms = 0;
4871 Cmd.extreloff = 0;
4872 Cmd.nextrel = 0;
4873 Cmd.locreloff = 0;
4874 Cmd.nlocrel = 0;
4875return Cmd;
4876}
4877
4878MachO::linkedit_data_command
4879MachOObjectFile::getDataInCodeLoadCommand() const{
4880if (DataInCodeLoadCmd)
4881return getStruct<MachO::linkedit_data_command>(*this, DataInCodeLoadCmd);
4882
4883// If there is no DataInCodeLoadCmd return a load command with zero'ed fields.
4884MachO::linkedit_data_command Cmd;
4885 Cmd.cmd = MachO::LC_DATA_IN_CODE;
4886 Cmd.cmdsize =sizeof(MachO::linkedit_data_command);
4887 Cmd.dataoff = 0;
4888 Cmd.datasize = 0;
4889return Cmd;
4890}
4891
4892MachO::linkedit_data_command
4893MachOObjectFile::getLinkOptHintsLoadCommand() const{
4894if (LinkOptHintsLoadCmd)
4895return getStruct<MachO::linkedit_data_command>(*this, LinkOptHintsLoadCmd);
4896
4897// If there is no LinkOptHintsLoadCmd return a load command with zero'ed
4898// fields.
4899MachO::linkedit_data_command Cmd;
4900 Cmd.cmd = MachO::LC_LINKER_OPTIMIZATION_HINT;
4901 Cmd.cmdsize =sizeof(MachO::linkedit_data_command);
4902 Cmd.dataoff = 0;
4903 Cmd.datasize = 0;
4904return Cmd;
4905}
4906
4907ArrayRef<uint8_t>MachOObjectFile::getDyldInfoRebaseOpcodes() const{
4908if (!DyldInfoLoadCmd)
4909return {};
4910
4911auto DyldInfoOrErr =
4912 getStructOrErr<MachO::dyld_info_command>(*this, DyldInfoLoadCmd);
4913if (!DyldInfoOrErr)
4914return {};
4915MachO::dyld_info_command DyldInfo = DyldInfoOrErr.get();
4916constuint8_t *Ptr =
4917reinterpret_cast<constuint8_t *>(getPtr(*this, DyldInfo.rebase_off));
4918returnArrayRef(Ptr, DyldInfo.rebase_size);
4919}
4920
4921ArrayRef<uint8_t>MachOObjectFile::getDyldInfoBindOpcodes() const{
4922if (!DyldInfoLoadCmd)
4923return {};
4924
4925auto DyldInfoOrErr =
4926 getStructOrErr<MachO::dyld_info_command>(*this, DyldInfoLoadCmd);
4927if (!DyldInfoOrErr)
4928return {};
4929MachO::dyld_info_command DyldInfo = DyldInfoOrErr.get();
4930constuint8_t *Ptr =
4931reinterpret_cast<constuint8_t *>(getPtr(*this, DyldInfo.bind_off));
4932returnArrayRef(Ptr, DyldInfo.bind_size);
4933}
4934
4935ArrayRef<uint8_t>MachOObjectFile::getDyldInfoWeakBindOpcodes() const{
4936if (!DyldInfoLoadCmd)
4937return {};
4938
4939auto DyldInfoOrErr =
4940 getStructOrErr<MachO::dyld_info_command>(*this, DyldInfoLoadCmd);
4941if (!DyldInfoOrErr)
4942return {};
4943MachO::dyld_info_command DyldInfo = DyldInfoOrErr.get();
4944constuint8_t *Ptr =
4945reinterpret_cast<constuint8_t *>(getPtr(*this, DyldInfo.weak_bind_off));
4946returnArrayRef(Ptr, DyldInfo.weak_bind_size);
4947}
4948
4949ArrayRef<uint8_t>MachOObjectFile::getDyldInfoLazyBindOpcodes() const{
4950if (!DyldInfoLoadCmd)
4951return {};
4952
4953auto DyldInfoOrErr =
4954 getStructOrErr<MachO::dyld_info_command>(*this, DyldInfoLoadCmd);
4955if (!DyldInfoOrErr)
4956return {};
4957MachO::dyld_info_command DyldInfo = DyldInfoOrErr.get();
4958constuint8_t *Ptr =
4959reinterpret_cast<constuint8_t *>(getPtr(*this, DyldInfo.lazy_bind_off));
4960returnArrayRef(Ptr, DyldInfo.lazy_bind_size);
4961}
4962
4963ArrayRef<uint8_t>MachOObjectFile::getDyldInfoExportsTrie() const{
4964if (!DyldInfoLoadCmd)
4965return {};
4966
4967auto DyldInfoOrErr =
4968 getStructOrErr<MachO::dyld_info_command>(*this, DyldInfoLoadCmd);
4969if (!DyldInfoOrErr)
4970return {};
4971MachO::dyld_info_command DyldInfo = DyldInfoOrErr.get();
4972constuint8_t *Ptr =
4973reinterpret_cast<constuint8_t *>(getPtr(*this, DyldInfo.export_off));
4974returnArrayRef(Ptr, DyldInfo.export_size);
4975}
4976
4977Expected<std::optional<MachO::linkedit_data_command>>
4978MachOObjectFile::getChainedFixupsLoadCommand() const{
4979// Load the dyld chained fixups load command.
4980if (!DyldChainedFixupsLoadCmd)
4981return std::nullopt;
4982auto DyldChainedFixupsOrErr = getStructOrErr<MachO::linkedit_data_command>(
4983 *this, DyldChainedFixupsLoadCmd);
4984if (!DyldChainedFixupsOrErr)
4985return DyldChainedFixupsOrErr.takeError();
4986constMachO::linkedit_data_command &DyldChainedFixups =
4987 *DyldChainedFixupsOrErr;
4988
4989// If the load command is present but the data offset has been zeroed out,
4990// as is the case for dylib stubs, return std::nullopt (no error).
4991if (!DyldChainedFixups.dataoff)
4992return std::nullopt;
4993return DyldChainedFixups;
4994}
4995
4996Expected<std::optional<MachO::dyld_chained_fixups_header>>
4997MachOObjectFile::getChainedFixupsHeader() const{
4998auto CFOrErr =getChainedFixupsLoadCommand();
4999if (!CFOrErr)
5000return CFOrErr.takeError();
5001if (!CFOrErr->has_value())
5002return std::nullopt;
5003
5004constMachO::linkedit_data_command &DyldChainedFixups = **CFOrErr;
5005
5006uint64_t CFHeaderOffset = DyldChainedFixups.dataoff;
5007uint64_t CFSize = DyldChainedFixups.datasize;
5008
5009// Load the dyld chained fixups header.
5010constchar *CFHeaderPtr =getPtr(*this, CFHeaderOffset);
5011auto CFHeaderOrErr =
5012 getStructOrErr<MachO::dyld_chained_fixups_header>(*this, CFHeaderPtr);
5013if (!CFHeaderOrErr)
5014return CFHeaderOrErr.takeError();
5015MachO::dyld_chained_fixups_header CFHeader = CFHeaderOrErr.get();
5016
5017// Reject unknown chained fixup formats.
5018if (CFHeader.fixups_version != 0)
5019returnmalformedError(Twine("bad chained fixups: unknown version: ") +
5020Twine(CFHeader.fixups_version));
5021if (CFHeader.imports_format < 1 || CFHeader.imports_format > 3)
5022returnmalformedError(
5023Twine("bad chained fixups: unknown imports format: ") +
5024Twine(CFHeader.imports_format));
5025
5026// Validate the image format.
5027//
5028// Load the image starts.
5029uint64_t CFImageStartsOffset = (CFHeaderOffset + CFHeader.starts_offset);
5030if (CFHeader.starts_offset <sizeof(MachO::dyld_chained_fixups_header)) {
5031returnmalformedError(Twine("bad chained fixups: image starts offset ") +
5032Twine(CFHeader.starts_offset) +
5033" overlaps with chained fixups header");
5034 }
5035uint32_t EndOffset = CFHeaderOffset + CFSize;
5036if (CFImageStartsOffset +sizeof(MachO::dyld_chained_starts_in_image) >
5037 EndOffset) {
5038returnmalformedError(Twine("bad chained fixups: image starts end ") +
5039Twine(CFImageStartsOffset +
5040sizeof(MachO::dyld_chained_starts_in_image)) +
5041" extends past end " +Twine(EndOffset));
5042 }
5043
5044return CFHeader;
5045}
5046
5047Expected<std::pair<size_t, std::vector<ChainedFixupsSegment>>>
5048MachOObjectFile::getChainedFixupsSegments() const{
5049auto CFOrErr =getChainedFixupsLoadCommand();
5050if (!CFOrErr)
5051return CFOrErr.takeError();
5052
5053 std::vector<ChainedFixupsSegment> Segments;
5054if (!CFOrErr->has_value())
5055return std::make_pair(0, Segments);
5056
5057constMachO::linkedit_data_command &DyldChainedFixups = **CFOrErr;
5058
5059auto HeaderOrErr =getChainedFixupsHeader();
5060if (!HeaderOrErr)
5061return HeaderOrErr.takeError();
5062if (!HeaderOrErr->has_value())
5063return std::make_pair(0, Segments);
5064constMachO::dyld_chained_fixups_header &Header = **HeaderOrErr;
5065
5066constchar *Contents =getPtr(*this, DyldChainedFixups.dataoff);
5067
5068auto ImageStartsOrErr = getStructOrErr<MachO::dyld_chained_starts_in_image>(
5069 *this, Contents +Header.starts_offset);
5070if (!ImageStartsOrErr)
5071return ImageStartsOrErr.takeError();
5072constMachO::dyld_chained_starts_in_image &ImageStarts = *ImageStartsOrErr;
5073
5074constchar *SegOffsPtr =
5075 Contents +Header.starts_offset +
5076offsetof(MachO::dyld_chained_starts_in_image, seg_info_offset);
5077constchar *SegOffsEnd =
5078 SegOffsPtr + ImageStarts.seg_count *sizeof(uint32_t);
5079if (SegOffsEnd > Contents + DyldChainedFixups.datasize)
5080returnmalformedError(
5081"bad chained fixups: seg_info_offset extends past end");
5082
5083constchar *LastSegEnd =nullptr;
5084for (size_tI = 0,N = ImageStarts.seg_count;I <N; ++I) {
5085auto OffOrErr =
5086 getStructOrErr<uint32_t>(*this, SegOffsPtr +I *sizeof(uint32_t));
5087if (!OffOrErr)
5088return OffOrErr.takeError();
5089// seg_info_offset == 0 means there is no associated starts_in_segment
5090// entry.
5091if (!*OffOrErr)
5092continue;
5093
5094autoFail = [&](Twine Message) {
5095returnmalformedError("bad chained fixups: segment info" +Twine(I) +
5096" at offset " +Twine(*OffOrErr) + Message);
5097 };
5098
5099constchar *SegPtr = Contents +Header.starts_offset + *OffOrErr;
5100if (LastSegEnd && SegPtr < LastSegEnd)
5101returnFail(" overlaps with previous segment info");
5102
5103auto SegOrErr =
5104 getStructOrErr<MachO::dyld_chained_starts_in_segment>(*this, SegPtr);
5105if (!SegOrErr)
5106return SegOrErr.takeError();
5107constMachO::dyld_chained_starts_in_segment &Seg = *SegOrErr;
5108
5109 LastSegEnd = SegPtr + Seg.size;
5110if (Seg.pointer_format < 1 || Seg.pointer_format > 12)
5111returnFail(" has unknown pointer format: " +Twine(Seg.pointer_format));
5112
5113constchar *PageStart =
5114 SegPtr +offsetof(MachO::dyld_chained_starts_in_segment, page_start);
5115constchar *PageEnd = PageStart + Seg.page_count *sizeof(uint16_t);
5116if (PageEnd > SegPtr + Seg.size)
5117returnFail(" : page_starts extend past seg_info size");
5118
5119// FIXME: This does not account for multiple offsets on a single page
5120// (DYLD_CHAINED_PTR_START_MULTI; 32-bit only).
5121 std::vector<uint16_t> PageStarts;
5122for (size_t PageIdx = 0; PageIdx < Seg.page_count; ++PageIdx) {
5123uint16_t Start;
5124 memcpy(&Start, PageStart + PageIdx *sizeof(uint16_t),sizeof(uint16_t));
5125if (isLittleEndian() !=sys::IsLittleEndianHost)
5126sys::swapByteOrder(Start);
5127 PageStarts.push_back(Start);
5128 }
5129
5130 Segments.emplace_back(I, *OffOrErr, Seg, std::move(PageStarts));
5131 }
5132
5133return std::make_pair(ImageStarts.seg_count, Segments);
5134}
5135
5136// The special library ordinals have a negative value, but they are encoded in
5137// an unsigned bitfield, so we need to sign extend the value.
5138template <typename T>staticintgetEncodedOrdinal(TValue) {
5139if (Value ==static_cast<T>(MachO::BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE) ||
5140Value ==static_cast<T>(MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP) ||
5141Value ==static_cast<T>(MachO::BIND_SPECIAL_DYLIB_WEAK_LOOKUP))
5142return SignExtend32<sizeof(T) * CHAR_BIT>(Value);
5143returnValue;
5144}
5145
5146template <typename T,unsigned N>
5147static std::array<T, N>getArray(constMachOObjectFile &O,constvoid *Ptr) {
5148 std::array<T, N> RawValue;
5149 memcpy(RawValue.data(),Ptr,N *sizeof(T));
5150if (O.isLittleEndian() !=sys::IsLittleEndianHost)
5151for (auto &Element : RawValue)
5152sys::swapByteOrder(Element);
5153return RawValue;
5154}
5155
5156Expected<std::vector<ChainedFixupTarget>>
5157MachOObjectFile::getDyldChainedFixupTargets() const{
5158auto CFOrErr =getChainedFixupsLoadCommand();
5159if (!CFOrErr)
5160return CFOrErr.takeError();
5161
5162 std::vector<ChainedFixupTarget> Targets;
5163if (!CFOrErr->has_value())
5164return Targets;
5165
5166constMachO::linkedit_data_command &DyldChainedFixups = **CFOrErr;
5167
5168auto CFHeaderOrErr =getChainedFixupsHeader();
5169if (!CFHeaderOrErr)
5170return CFHeaderOrErr.takeError();
5171if (!(*CFHeaderOrErr))
5172return Targets;
5173constMachO::dyld_chained_fixups_header &Header = **CFHeaderOrErr;
5174
5175size_t ImportSize = 0;
5176if (Header.imports_format ==MachO::DYLD_CHAINED_IMPORT)
5177 ImportSize =sizeof(MachO::dyld_chained_import);
5178elseif (Header.imports_format ==MachO::DYLD_CHAINED_IMPORT_ADDEND)
5179 ImportSize =sizeof(MachO::dyld_chained_import_addend);
5180elseif (Header.imports_format ==MachO::DYLD_CHAINED_IMPORT_ADDEND64)
5181 ImportSize =sizeof(MachO::dyld_chained_import_addend64);
5182else
5183returnmalformedError("bad chained fixups: unknown imports format: " +
5184Twine(Header.imports_format));
5185
5186constchar *Contents =getPtr(*this, DyldChainedFixups.dataoff);
5187constchar *Imports = Contents +Header.imports_offset;
5188size_t ImportsEndOffset =
5189Header.imports_offset + ImportSize *Header.imports_count;
5190constchar *ImportsEnd = Contents + ImportsEndOffset;
5191constchar *Symbols = Contents +Header.symbols_offset;
5192constchar *SymbolsEnd = Contents + DyldChainedFixups.datasize;
5193
5194if (ImportsEnd > Symbols)
5195returnmalformedError("bad chained fixups: imports end " +
5196Twine(ImportsEndOffset) +" overlaps with symbols");
5197
5198// We use bit manipulation to extract data from the bitfields. This is correct
5199// for both LE and BE hosts, but we assume that the object is little-endian.
5200if (!isLittleEndian())
5201returncreateError("parsing big-endian chained fixups is not implemented");
5202for (constchar *ImportPtr = Imports; ImportPtr < ImportsEnd;
5203 ImportPtr += ImportSize) {
5204int LibOrdinal;
5205bool WeakImport;
5206uint32_t NameOffset;
5207uint64_t Addend;
5208if (Header.imports_format ==MachO::DYLD_CHAINED_IMPORT) {
5209static_assert(sizeof(uint32_t) ==sizeof(MachO::dyld_chained_import));
5210auto RawValue = getArray<uint32_t, 1>(*this, ImportPtr);
5211
5212 LibOrdinal = getEncodedOrdinal<uint8_t>(RawValue[0] & 0xFF);
5213 WeakImport = (RawValue[0] >> 8) & 1;
5214 NameOffset = RawValue[0] >> 9;
5215 Addend = 0;
5216 }elseif (Header.imports_format ==MachO::DYLD_CHAINED_IMPORT_ADDEND) {
5217static_assert(sizeof(uint64_t) ==
5218sizeof(MachO::dyld_chained_import_addend));
5219auto RawValue = getArray<uint32_t, 2>(*this, ImportPtr);
5220
5221 LibOrdinal = getEncodedOrdinal<uint8_t>(RawValue[0] & 0xFF);
5222 WeakImport = (RawValue[0] >> 8) & 1;
5223 NameOffset = RawValue[0] >> 9;
5224 Addend = bit_cast<int32_t>(RawValue[1]);
5225 }elseif (Header.imports_format ==MachO::DYLD_CHAINED_IMPORT_ADDEND64) {
5226static_assert(2 *sizeof(uint64_t) ==
5227sizeof(MachO::dyld_chained_import_addend64));
5228auto RawValue = getArray<uint64_t, 2>(*this, ImportPtr);
5229
5230 LibOrdinal = getEncodedOrdinal<uint16_t>(RawValue[0] & 0xFFFF);
5231 NameOffset = (RawValue[0] >> 16) & 1;
5232 WeakImport = RawValue[0] >> 17;
5233 Addend = RawValue[1];
5234 }else {
5235llvm_unreachable("Import format should have been checked");
5236 }
5237
5238constchar *Str = Symbols + NameOffset;
5239if (Str >= SymbolsEnd)
5240returnmalformedError("bad chained fixups: symbol offset " +
5241Twine(NameOffset) +" extends past end " +
5242Twine(DyldChainedFixups.datasize));
5243 Targets.emplace_back(LibOrdinal, NameOffset, Str, Addend, WeakImport);
5244 }
5245
5246return std::move(Targets);
5247}
5248
5249ArrayRef<uint8_t>MachOObjectFile::getDyldExportsTrie() const{
5250if (!DyldExportsTrieLoadCmd)
5251return {};
5252
5253auto DyldExportsTrieOrError = getStructOrErr<MachO::linkedit_data_command>(
5254 *this, DyldExportsTrieLoadCmd);
5255if (!DyldExportsTrieOrError)
5256return {};
5257MachO::linkedit_data_command DyldExportsTrie = DyldExportsTrieOrError.get();
5258constuint8_t *Ptr =
5259reinterpret_cast<constuint8_t *>(getPtr(*this, DyldExportsTrie.dataoff));
5260returnArrayRef(Ptr, DyldExportsTrie.datasize);
5261}
5262
5263SmallVector<uint64_t>MachOObjectFile::getFunctionStarts() const{
5264if (!FuncStartsLoadCmd)
5265return {};
5266
5267auto InfoOrErr =
5268 getStructOrErr<MachO::linkedit_data_command>(*this, FuncStartsLoadCmd);
5269if (!InfoOrErr)
5270return {};
5271
5272MachO::linkedit_data_commandInfo = InfoOrErr.get();
5273SmallVector<uint64_t, 8> FunctionStarts;
5274 this->ReadULEB128s(Info.dataoff, FunctionStarts);
5275return std::move(FunctionStarts);
5276}
5277
5278ArrayRef<uint8_t>MachOObjectFile::getUuid() const{
5279if (!UuidLoadCmd)
5280return {};
5281// Returning a pointer is fine as uuid doesn't need endian swapping.
5282constchar *Ptr = UuidLoadCmd +offsetof(MachO::uuid_command, uuid);
5283returnArrayRef(reinterpret_cast<constuint8_t *>(Ptr), 16);
5284}
5285
5286StringRefMachOObjectFile::getStringTableData() const{
5287MachO::symtab_command S =getSymtabLoadCommand();
5288returngetData().substr(S.stroff, S.strsize);
5289}
5290
5291boolMachOObjectFile::is64Bit() const{
5292returngetType() ==getMachOType(false,true) ||
5293getType() ==getMachOType(true,true);
5294}
5295
5296voidMachOObjectFile::ReadULEB128s(uint64_t Index,
5297SmallVectorImpl<uint64_t> &Out) const{
5298DataExtractor extractor(ObjectFile::getData(),true, 0);
5299
5300uint64_t offset = Index;
5301uint64_tdata = 0;
5302while (uint64_t delta = extractor.getULEB128(&offset)) {
5303data += delta;
5304 Out.push_back(data);
5305 }
5306}
5307
5308boolMachOObjectFile::isRelocatableObject() const{
5309returngetHeader().filetype ==MachO::MH_OBJECT;
5310}
5311
5312/// Create a MachOObjectFile instance from a given buffer.
5313///
5314/// \param Buffer Memory buffer containing the MachO binary data.
5315/// \param UniversalCputype CPU type when the MachO part of a universal binary.
5316/// \param UniversalIndex Index of the MachO within a universal binary.
5317/// \param MachOFilesetEntryOffset Offset of the MachO entry in a fileset MachO.
5318/// \returns A std::unique_ptr to a MachOObjectFile instance on success.
5319Expected<std::unique_ptr<MachOObjectFile>>ObjectFile::createMachOObjectFile(
5320MemoryBufferRef Buffer,uint32_t UniversalCputype,uint32_t UniversalIndex,
5321size_t MachOFilesetEntryOffset) {
5322StringRef Magic = Buffer.getBuffer().slice(0, 4);
5323if (Magic =="\xFE\xED\xFA\xCE")
5324returnMachOObjectFile::create(Buffer,false,false, UniversalCputype,
5325 UniversalIndex, MachOFilesetEntryOffset);
5326if (Magic =="\xCE\xFA\xED\xFE")
5327returnMachOObjectFile::create(Buffer,true,false, UniversalCputype,
5328 UniversalIndex, MachOFilesetEntryOffset);
5329if (Magic =="\xFE\xED\xFA\xCF")
5330returnMachOObjectFile::create(Buffer,false,true, UniversalCputype,
5331 UniversalIndex, MachOFilesetEntryOffset);
5332if (Magic =="\xCF\xFA\xED\xFE")
5333returnMachOObjectFile::create(Buffer,true,true, UniversalCputype,
5334 UniversalIndex, MachOFilesetEntryOffset);
5335return make_error<GenericBinaryError>("Unrecognized MachO magic number",
5336object_error::invalid_file_type);
5337}
5338
5339StringRefMachOObjectFile::mapDebugSectionName(StringRefName) const{
5340returnStringSwitch<StringRef>(Name)
5341 .Case("debug_str_offs","debug_str_offsets")
5342 .Default(Name);
5343}
5344
5345Expected<std::vector<std::string>>
5346MachOObjectFile::findDsymObjectMembers(StringRef Path) {
5347SmallString<256> BundlePath(Path);
5348// Normalize input path. This is necessary to accept `bundle.dSYM/`.
5349sys::path::remove_dots(BundlePath);
5350if (!sys::fs::is_directory(BundlePath) ||
5351sys::path::extension(BundlePath) !=".dSYM")
5352return std::vector<std::string>();
5353sys::path::append(BundlePath,"Contents","Resources","DWARF");
5354bool IsDir;
5355auto EC =sys::fs::is_directory(BundlePath, IsDir);
5356if (EC ==errc::no_such_file_or_directory || (!EC && !IsDir))
5357returncreateStringError(
5358 EC,"%s: expected directory 'Contents/Resources/DWARF' in dSYM bundle",
5359 Path.str().c_str());
5360if (EC)
5361returncreateFileError(BundlePath,errorCodeToError(EC));
5362
5363 std::vector<std::string> ObjectPaths;
5364for (sys::fs::directory_iterator Dir(BundlePath, EC), DirEnd;
5365 Dir != DirEnd && !EC; Dir.increment(EC)) {
5366StringRef ObjectPath = Dir->path();
5367sys::fs::file_statusStatus;
5368if (auto EC =sys::fs::status(ObjectPath,Status))
5369returncreateFileError(ObjectPath,errorCodeToError(EC));
5370switch (Status.type()) {
5371casesys::fs::file_type::regular_file:
5372casesys::fs::file_type::symlink_file:
5373casesys::fs::file_type::type_unknown:
5374 ObjectPaths.push_back(ObjectPath.str());
5375break;
5376default:/*ignore*/;
5377 }
5378 }
5379if (EC)
5380returncreateFileError(BundlePath,errorCodeToError(EC));
5381if (ObjectPaths.empty())
5382returncreateStringError(std::error_code(),
5383"%s: no objects found in dSYM bundle",
5384 Path.str().c_str());
5385return ObjectPaths;
5386}
5387
5388llvm::binaryformat::Swift5ReflectionSectionKind
5389MachOObjectFile::mapReflectionSectionNameToEnumValue(
5390StringRefSectionName) const{
5391#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
5392 .Case(MACHO, llvm::binaryformat::Swift5ReflectionSectionKind::KIND)
5393returnStringSwitch<llvm::binaryformat::Swift5ReflectionSectionKind>(
5394SectionName)
5395#include "llvm/BinaryFormat/Swift.def"
5396 .Default(llvm::binaryformat::Swift5ReflectionSectionKind::unknown);
5397#undef HANDLE_SWIFT_SECTION
5398}
5399
5400boolMachOObjectFile::isMachOPairedReloc(uint64_t RelocType,uint64_t Arch) {
5401switch (Arch) {
5402caseTriple::x86:
5403return RelocType ==MachO::GENERIC_RELOC_SECTDIFF ||
5404 RelocType ==MachO::GENERIC_RELOC_LOCAL_SECTDIFF;
5405caseTriple::x86_64:
5406return RelocType ==MachO::X86_64_RELOC_SUBTRACTOR;
5407caseTriple::arm:
5408caseTriple::thumb:
5409return RelocType ==MachO::ARM_RELOC_SECTDIFF ||
5410 RelocType ==MachO::ARM_RELOC_LOCAL_SECTDIFF ||
5411 RelocType ==MachO::ARM_RELOC_HALF ||
5412 RelocType ==MachO::ARM_RELOC_HALF_SECTDIFF;
5413caseTriple::aarch64:
5414return RelocType ==MachO::ARM64_RELOC_SUBTRACTOR;
5415default:
5416returnfalse;
5417 }
5418}
Fail
#define Fail
Definition:AArch64Disassembler.cpp:221
for
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
Definition:AArch64ExpandPseudoInsts.cpp:115
offsetof
#define offsetof(TYPE, MEMBER)
Definition:AMDHSAKernelDescriptor.h:30
ArrayRef.h
MachO.h
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Info
Analysis containing CSE Info
Definition:CSEInfo.cpp:27
DataExtractor.h
Idx
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Definition:DeadArgumentElimination.cpp:353
Debug.h
DEBUG_WITH_TYPE
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition:Debug.h:64
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
End
bool End
Definition:ELF_riscv.cpp:480
Sym
Symbol * Sym
Definition:ELF_riscv.cpp:479
Errc.h
FileSystem.h
Format.h
Host.h
LEB128.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
H
#define H(x, y, z)
Definition:MD5.cpp:57
getSymbolTableEntryBase
static MachO::nlist_base getSymbolTableEntryBase(const MachOObjectFile &O, DataRefImpl DRI)
Definition:MachOObjectFile.cpp:119
checkVersCommand
static Error checkVersCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, const char *CmdName)
Definition:MachOObjectFile.cpp:818
checkSymtabCommand
static Error checkSymtabCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **SymtabLoadCmd, std::list< MachOElement > &Elements)
Definition:MachOObjectFile.cpp:409
checkTwoLevelHintsCommand
static Error checkTwoLevelHintsCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, std::list< MachOElement > &Elements)
Definition:MachOObjectFile.cpp:1199
parseBuildVersionCommand
static Error parseBuildVersionCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, SmallVectorImpl< const char * > &BuildTools, uint32_t LoadCommandIndex)
Definition:MachOObjectFile.cpp:862
getPlainRelocationType
static unsigned getPlainRelocationType(const MachOObjectFile &O, const MachO::any_relocation_info &RE)
Definition:MachOObjectFile.cpp:174
checkDysymtabCommand
static Error checkDysymtabCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **DysymtabLoadCmd, std::list< MachOElement > &Elements)
Definition:MachOObjectFile.cpp:467
checkDylibCommand
static Error checkDylibCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
Definition:MachOObjectFile.cpp:737
getStructOrErr
static Expected< T > getStructOrErr(const MachOObjectFile &O, const char *P)
Definition:MachOObjectFile.cpp:84
getFirstLoadCommandInfo
static Expected< MachOObjectFile::LoadCommandInfo > getFirstLoadCommandInfo(const MachOObjectFile &Obj)
Definition:MachOObjectFile.cpp:207
getPtr
static const char * getPtr(const MachOObjectFile &O, size_t Offset, size_t MachOFilesetEntryOffset=0)
Definition:MachOObjectFile.cpp:111
parseSegmentLoadCommand
static Error parseSegmentLoadCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, SmallVectorImpl< const char * > &Sections, bool &IsPageZeroSegment, uint32_t LoadCommandIndex, const char *CmdName, uint64_t SizeOfHeaders, std::list< MachOElement > &Elements)
Definition:MachOObjectFile.cpp:285
checkDyldInfoCommand
static Error checkDyldInfoCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, const char *CmdName, std::list< MachOElement > &Elements)
Definition:MachOObjectFile.cpp:638
getScatteredRelocationLength
static unsigned getScatteredRelocationLength(const MachO::any_relocation_info &RE)
Definition:MachOObjectFile.cpp:170
getPlainRelocationLength
static unsigned getPlainRelocationLength(const MachOObjectFile &O, const MachO::any_relocation_info &RE)
Definition:MachOObjectFile.cpp:162
checkSubCommand
static Error checkSubCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName, size_t SizeOfCmd, const char *CmdStructName, uint32_t PathOffset, const char *PathFieldName)
Definition:MachOObjectFile.cpp:981
checkRpathCommand
static Error checkRpathCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex)
Definition:MachOObjectFile.cpp:885
getStruct
static T getStruct(const MachOObjectFile &O, const char *P)
Definition:MachOObjectFile.cpp:71
getPlainRelocationAddress
static uint32_t getPlainRelocationAddress(const MachO::any_relocation_info &RE)
Definition:MachOObjectFile.cpp:141
getSectionPtr
static const char * getSectionPtr(const MachOObjectFile &O, MachOObjectFile::LoadCommandInfo L, unsigned Sec)
Definition:MachOObjectFile.cpp:97
checkLinkerOptCommand
static Error checkLinkerOptCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex)
Definition:MachOObjectFile.cpp:941
getPlainRelocationPCRel
static bool getPlainRelocationPCRel(const MachOObjectFile &O, const MachO::any_relocation_info &RE)
Definition:MachOObjectFile.cpp:150
getArray
static std::array< T, N > getArray(const MachOObjectFile &O, const void *Ptr)
Definition:MachOObjectFile.cpp:5147
getScatteredRelocationAddress
static unsigned getScatteredRelocationAddress(const MachO::any_relocation_info &RE)
Definition:MachOObjectFile.cpp:146
checkThreadCommand
static Error checkThreadCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
Definition:MachOObjectFile.cpp:1008
checkLinkeditDataCommand
static Error checkLinkeditDataCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, const char *CmdName, std::list< MachOElement > &Elements, const char *ElementName)
Definition:MachOObjectFile.cpp:600
malformedError
static Error malformedError(const Twine &Msg)
Definition:MachOObjectFile.cpp:63
isLoadCommandObsolete
static bool isLoadCommandObsolete(uint32_t cmd)
Definition:MachOObjectFile.cpp:1238
getSectionFlags
static uint32_t getSectionFlags(const MachOObjectFile &O, DataRefImpl Sec)
Definition:MachOObjectFile.cpp:181
getEncodedOrdinal
static int getEncodedOrdinal(T Value)
Definition:MachOObjectFile.cpp:5138
getScatteredRelocationPCRel
static bool getScatteredRelocationPCRel(const MachO::any_relocation_info &RE)
Definition:MachOObjectFile.cpp:158
checkOverlappingElement
static Error checkOverlappingElement(std::list< MachOElement > &Elements, uint64_t Offset, uint64_t Size, const char *Name)
Definition:MachOObjectFile.cpp:252
parseSegmentOrSectionName
static StringRef parseSegmentOrSectionName(const char *P)
Definition:MachOObjectFile.cpp:124
getLoadCommandInfo
static Expected< MachOObjectFile::LoadCommandInfo > getLoadCommandInfo(const MachOObjectFile &Obj, const char *Ptr, uint32_t LoadCommandIndex)
Definition:MachOObjectFile.cpp:192
parseHeader
static void parseHeader(const MachOObjectFile &Obj, T &Header, Error &Err)
Definition:MachOObjectFile.cpp:231
getCPUType
static unsigned getCPUType(const MachOObjectFile &O)
Definition:MachOObjectFile.cpp:132
checkDyldCommand
static Error checkDyldCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
Definition:MachOObjectFile.cpp:786
checkNoteCommand
static Error checkNoteCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, std::list< MachOElement > &Elements)
Definition:MachOObjectFile.cpp:833
checkDylibIdCommand
static Error checkDylibIdCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd)
Definition:MachOObjectFile.cpp:769
getCPUSubType
static unsigned getCPUSubType(const MachOObjectFile &O)
Definition:MachOObjectFile.cpp:136
checkEncryptCommand
static Error checkEncryptCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, uint64_t cryptoff, uint64_t cryptsize, const char **LoadCmd, const char *CmdName)
Definition:MachOObjectFile.cpp:917
getNextLoadCommandInfo
static Expected< MachOObjectFile::LoadCommandInfo > getNextLoadCommandInfo(const MachOObjectFile &Obj, uint32_t LoadCommandIndex, const MachOObjectFile::LoadCommandInfo &L)
Definition:MachOObjectFile.cpp:218
MemoryBufferRef.h
ObjectFile.h
malformedError
static Error malformedError(Twine Msg)
Definition:Archive.cpp:43
MachO.h
Field
OptimizedStructLayoutField Field
Definition:OptimizedStructLayout.cpp:18
P
#define P(N)
Path.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
STLExtras.h
This file contains some templates that are useful if you are working with the STL at all.
substr
static StringRef substr(StringRef Str, uint64_t Len)
Definition:SimplifyLibCalls.cpp:356
SmallVector.h
This file defines the SmallVector class.
data
static Split data
Definition:StaticDataSplitter.cpp:176
StringRef.h
StringSwitch.h
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
SwapByteOrder.h
Swift.h
error
#define error(X)
Definition:SymbolRecordMapping.cpp:14
SymbolicFile.h
Ptr
@ Ptr
Definition:TargetLibraryInfo.cpp:77
Triple.h
Twine.h
is64Bit
static bool is64Bit(const char *name)
Definition:X86Disassembler.cpp:1085
bit.h
This file implements the C++20 <bit> header.
T
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::end
iterator end() const
Definition:ArrayRef.h:157
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::ArrayRef::begin
iterator begin() const
Definition:ArrayRef.h:156
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition:ArrayRef.h:163
llvm::ArrayRef::data
const T * data() const
Definition:ArrayRef.h:165
llvm::DataExtractor
Definition:DataExtractor.h:41
llvm::DataExtractor::getULEB128
uint64_t getULEB128(uint64_t *offset_ptr, llvm::Error *Err=nullptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Definition:DataExtractor.cpp:221
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition:Error.h:1130
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition:Error.h:608
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition:Error.h:578
llvm::MemoryBufferRef
Definition:MemoryBufferRef.h:22
llvm::MemoryBufferRef::getBuffer
StringRef getBuffer() const
Definition:MemoryBufferRef.h:32
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition:SmallString.h:26
llvm::SmallString::equals
bool equals(StringRef RHS) const
Check for string equality.
Definition:SmallString.h:92
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorImpl::clear
void clear()
Definition:SmallVector.h:610
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition:SmallVector.h:638
llvm::SmallVectorTemplateBase::pop_back
void pop_back()
Definition:SmallVector.h:425
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVectorTemplateCommon::end
iterator end()
Definition:SmallVector.h:269
llvm::SmallVectorTemplateCommon::begin
iterator begin()
Definition:SmallVector.h:267
llvm::SmallVectorTemplateCommon::back
reference back()
Definition:SmallVector.h:308
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::str
std::string str() const
str - Get the contents as an std::string.
Definition:StringRef.h:229
llvm::StringRef::substr
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition:StringRef.h:571
llvm::StringRef::starts_with
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition:StringRef.h:265
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::StringRef::begin
iterator begin() const
Definition:StringRef.h:116
llvm::StringRef::slice
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition:StringRef.h:684
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition:StringRef.h:150
llvm::StringRef::data
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition:StringRef.h:144
llvm::StringRef::rfind
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
Definition:StringRef.h:347
llvm::StringRef::end
iterator end() const
Definition:StringRef.h:118
llvm::StringRef::find
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition:StringRef.h:297
llvm::StringRef::npos
static constexpr size_t npos
Definition:StringRef.h:53
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition:StringSwitch.h:44
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition:StringSwitch.h:69
llvm::StringSwitch::Default
R Default(T Value)
Definition:StringSwitch.h:182
llvm::StringTable
A table of densely packed, null-terminated strings indexed by offset.
Definition:StringTable.h:33
llvm::StringTable::size
constexpr size_t size() const
Returns the byte size of the table.
Definition:StringTable.h:97
llvm::Target
Target - Wrapper for Target specific information.
Definition:TargetRegistry.h:144
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition:Triple.h:44
llvm::Triple::ArchType
ArchType
Definition:Triple.h:46
llvm::Triple::x86
@ x86
Definition:Triple.h:85
llvm::Triple::x86_64
@ x86_64
Definition:Triple.h:86
llvm::Triple::UnknownArch
@ UnknownArch
Definition:Triple.h:47
llvm::Triple::arm
@ arm
Definition:Triple.h:49
llvm::Triple::ppc64
@ ppc64
Definition:Triple.h:71
llvm::Triple::ppc
@ ppc
Definition:Triple.h:69
llvm::Triple::thumb
@ thumb
Definition:Triple.h:83
llvm::Triple::aarch64
@ aarch64
Definition:Triple.h:51
llvm::Triple::aarch64_32
@ aarch64_32
Definition:Triple.h:53
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::Twine::utohexstr
static Twine utohexstr(const uint64_t &Val)
Definition:Twine.h:416
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition:iterator_range.h:42
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition:SymbolicFile.h:111
llvm::object::BasicSymbolRef::SF_Hidden
@ SF_Hidden
Definition:SymbolicFile.h:120
llvm::object::BasicSymbolRef::SF_Exported
@ SF_Exported
Definition:SymbolicFile.h:116
llvm::object::BasicSymbolRef::SF_Thumb
@ SF_Thumb
Definition:SymbolicFile.h:119
llvm::object::BasicSymbolRef::SF_Common
@ SF_Common
Definition:SymbolicFile.h:114
llvm::object::BasicSymbolRef::SF_Indirect
@ SF_Indirect
Definition:SymbolicFile.h:115
llvm::object::BasicSymbolRef::SF_FormatSpecific
@ SF_FormatSpecific
Definition:SymbolicFile.h:117
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition:SymbolicFile.h:112
llvm::object::BasicSymbolRef::SF_Absolute
@ SF_Absolute
Definition:SymbolicFile.h:113
llvm::object::BasicSymbolRef::SF_Undefined
@ SF_Undefined
Definition:SymbolicFile.h:110
llvm::object::BasicSymbolRef::SF_None
@ SF_None
Definition:SymbolicFile.h:109
llvm::object::Binary::getData
StringRef getData() const
Definition:Binary.cpp:39
llvm::object::Binary::getType
unsigned int getType() const
Definition:Binary.h:104
llvm::object::Binary::isLittleEndian
bool isLittleEndian() const
Definition:Binary.h:155
llvm::object::Binary::getMachOType
static unsigned int getMachOType(bool isLE, bool is64Bits)
Definition:Binary.h:85
llvm::object::BindRebaseSegInfo::segmentName
StringRef segmentName(int32_t SegIndex)
Definition:MachOObjectFile.cpp:4422
llvm::object::BindRebaseSegInfo::sectionName
StringRef sectionName(int32_t SegIndex, uint64_t SegOffset)
Definition:MachOObjectFile.cpp:4448
llvm::object::BindRebaseSegInfo::BindRebaseSegInfo
BindRebaseSegInfo(const MachOObjectFile *Obj)
Definition:MachOObjectFile.cpp:4354
llvm::object::BindRebaseSegInfo::checkSegAndOffsets
const char * checkSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint64_t Count=1, uint64_t Skip=0)
Definition:MachOObjectFile.cpp:4389
llvm::object::BindRebaseSegInfo::address
uint64_t address(uint32_t SegIndex, uint64_t SegOffset)
Definition:MachOObjectFile.cpp:4455
llvm::object::DiceRef
DiceRef - This is a value type class that represents a single data in code entry in the table in a Ma...
Definition:MachO.h:44
llvm::object::ExportEntry
ExportEntry encapsulates the current-state-of-the-walk used when doing a non-recursive walk of the tr...
Definition:MachO.h:73
llvm::object::ExportEntry::moveNext
void moveNext()
Definition:MachOObjectFile.cpp:3196
llvm::object::ExportEntry::name
StringRef name() const
Definition:MachOObjectFile.cpp:2963
llvm::object::ExportEntry::ExportEntry
ExportEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Trie)
Definition:MachOObjectFile.cpp:2920
llvm::object::ExportEntry::operator==
bool operator==(const ExportEntry &) const
Definition:MachOObjectFile.cpp:2936
llvm::object::ExportEntry::otherName
StringRef otherName() const
Definition:MachOObjectFile.cpp:2979
llvm::object::ExportEntry::address
uint64_t address() const
Definition:MachOObjectFile.cpp:2971
llvm::object::ExportEntry::flags
uint64_t flags() const
Definition:MachOObjectFile.cpp:2967
llvm::object::ExportEntry::nodeOffset
uint32_t nodeOffset() const
Definition:MachOObjectFile.cpp:2986
llvm::object::ExportEntry::other
uint64_t other() const
Definition:MachOObjectFile.cpp:2975
llvm::object::MachOAbstractFixupEntry
MachOAbstractFixupEntry is an abstract class representing a fixup in a MH_DYLDLINK file.
Definition:MachO.h:322
llvm::object::MachOAbstractFixupEntry::sectionName
StringRef sectionName() const
Definition:MachOObjectFile.cpp:3285
llvm::object::MachOAbstractFixupEntry::Flags
uint32_t Flags
Definition:MachO.h:362
llvm::object::MachOAbstractFixupEntry::segmentAddress
uint64_t segmentAddress() const
Definition:MachOObjectFile.cpp:3277
llvm::object::MachOAbstractFixupEntry::RawValue
uint64_t RawValue
Definition:MachO.h:365
llvm::object::MachOAbstractFixupEntry::segmentIndex
int32_t segmentIndex() const
Definition:MachOObjectFile.cpp:3271
llvm::object::MachOAbstractFixupEntry::address
uint64_t address() const
Definition:MachOObjectFile.cpp:3289
llvm::object::MachOAbstractFixupEntry::SegmentOffset
uint64_t SegmentOffset
Definition:MachO.h:358
llvm::object::MachOAbstractFixupEntry::moveNext
void moveNext()
Definition:MachOObjectFile.cpp:3314
llvm::object::MachOAbstractFixupEntry::SymbolName
StringRef SymbolName
Definition:MachO.h:360
llvm::object::MachOAbstractFixupEntry::typeName
StringRef typeName() const
Definition:MachOObjectFile.cpp:3301
llvm::object::MachOAbstractFixupEntry::addend
int64_t addend() const
Definition:MachOObjectFile.cpp:3295
llvm::object::MachOAbstractFixupEntry::MachOAbstractFixupEntry
MachOAbstractFixupEntry(Error *Err, const MachOObjectFile *O)
Definition:MachOObjectFile.cpp:3250
llvm::object::MachOAbstractFixupEntry::textAddress
uint64_t textAddress() const
Definition:MachO.h:372
llvm::object::MachOAbstractFixupEntry::flags
uint32_t flags() const
Definition:MachOObjectFile.cpp:3297
llvm::object::MachOAbstractFixupEntry::symbolName
StringRef symbolName() const
Definition:MachOObjectFile.cpp:3293
llvm::object::MachOAbstractFixupEntry::Done
bool Done
Definition:MachO.h:366
llvm::object::MachOAbstractFixupEntry::moveToFirst
void moveToFirst()
Definition:MachOObjectFile.cpp:3303
llvm::object::MachOAbstractFixupEntry::PointerValue
uint64_t PointerValue
Definition:MachO.h:364
llvm::object::MachOAbstractFixupEntry::SegmentIndex
int32_t SegmentIndex
Definition:MachO.h:359
llvm::object::MachOAbstractFixupEntry::ordinal
int ordinal() const
Definition:MachOObjectFile.cpp:3299
llvm::object::MachOAbstractFixupEntry::segmentName
StringRef segmentName() const
Definition:MachOObjectFile.cpp:3281
llvm::object::MachOAbstractFixupEntry::E
Error * E
Definition:MachO.h:356
llvm::object::MachOAbstractFixupEntry::moveToEnd
void moveToEnd()
Definition:MachOObjectFile.cpp:3312
llvm::object::MachOAbstractFixupEntry::Addend
int64_t Addend
Definition:MachO.h:363
llvm::object::MachOAbstractFixupEntry::Ordinal
int32_t Ordinal
Definition:MachO.h:361
llvm::object::MachOAbstractFixupEntry::O
const MachOObjectFile * O
Definition:MachO.h:357
llvm::object::MachOAbstractFixupEntry::segmentOffset
uint64_t segmentOffset() const
Definition:MachOObjectFile.cpp:3273
llvm::object::MachOBindEntry
MachOBindEntry encapsulates the current state in the decompression of binding opcodes.
Definition:MachO.h:212
llvm::object::MachOBindEntry::flags
uint32_t flags() const
Definition:MachOObjectFile.cpp:4320
llvm::object::MachOBindEntry::operator==
bool operator==(const MachOBindEntry &) const
Definition:MachOObjectFile.cpp:4342
llvm::object::MachOBindEntry::moveNext
void moveNext()
Definition:MachOObjectFile.cpp:3833
llvm::object::MachOBindEntry::symbolName
StringRef symbolName() const
Definition:MachOObjectFile.cpp:4316
llvm::object::MachOBindEntry::ordinal
int ordinal() const
Definition:MachOObjectFile.cpp:4322
llvm::object::MachOBindEntry::sectionName
StringRef sectionName() const
Definition:MachOObjectFile.cpp:4332
llvm::object::MachOBindEntry::MachOBindEntry
MachOBindEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Opcodes, bool is64Bit, MachOBindEntry::Kind)
Definition:MachOObjectFile.cpp:3817
llvm::object::MachOBindEntry::segmentName
StringRef segmentName() const
Definition:MachOObjectFile.cpp:4326
llvm::object::MachOBindEntry::segmentOffset
uint64_t segmentOffset() const
Definition:MachOObjectFile.cpp:4302
llvm::object::MachOBindEntry::addend
int64_t addend() const
Definition:MachOObjectFile.cpp:4318
llvm::object::MachOBindEntry::address
uint64_t address() const
Definition:MachOObjectFile.cpp:4338
llvm::object::MachOBindEntry::segmentIndex
int32_t segmentIndex() const
Definition:MachOObjectFile.cpp:4300
llvm::object::MachOBindEntry::typeName
StringRef typeName() const
Definition:MachOObjectFile.cpp:4304
llvm::object::MachOBindEntry::Kind
Kind
Definition:MachO.h:214
llvm::object::MachOBindEntry::Kind::Lazy
@ Lazy
llvm::object::MachOBindEntry::Kind::Weak
@ Weak
llvm::object::MachOBindEntry::Kind::Regular
@ Regular
llvm::object::MachOChainedFixupEntry
Definition:MachO.h:378
llvm::object::MachOChainedFixupEntry::moveNext
void moveNext()
Definition:MachOObjectFile.cpp:3378
llvm::object::MachOChainedFixupEntry::operator==
bool operator==(const MachOChainedFixupEntry &) const
Definition:MachOObjectFile.cpp:3468
llvm::object::MachOChainedFixupEntry::MachOChainedFixupEntry
MachOChainedFixupEntry(Error *Err, const MachOObjectFile *O, bool Parse)
Definition:MachOObjectFile.cpp:3316
llvm::object::MachOChainedFixupEntry::moveToEnd
void moveToEnd()
Definition:MachOObjectFile.cpp:3374
llvm::object::MachOChainedFixupEntry::moveToFirst
void moveToFirst()
Definition:MachOObjectFile.cpp:3360
llvm::object::MachOChainedFixupEntry::FixupKind::Bind
@ Bind
llvm::object::MachOChainedFixupEntry::FixupKind::Rebase
@ Rebase
llvm::object::MachOObjectFile
Definition:MachO.h:406
llvm::object::MachOObjectFile::getSubClientCommand
MachO::sub_client_command getSubClientCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4754
llvm::object::MachOObjectFile::moveSectionNext
void moveSectionNext(DataRefImpl &Sec) const override
Definition:MachOObjectFile.cpp:1932
llvm::object::MachOObjectFile::getSectionRawFinalSegmentName
ArrayRef< char > getSectionRawFinalSegmentName(DataRefImpl Sec) const
Definition:MachOObjectFile.cpp:4533
llvm::object::MachOObjectFile::getBytesInAddress
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
Definition:MachOObjectFile.cpp:2654
llvm::object::MachOObjectFile::getArch
Triple::ArchType getArch() const override
Definition:MachOObjectFile.cpp:2879
llvm::object::MachOObjectFile::Header64
MachO::mach_header_64 Header64
Definition:MachO.h:849
llvm::object::MachOObjectFile::isSectionData
bool isSectionData(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2045
llvm::object::MachOObjectFile::getHeader64
const MachO::mach_header_64 & getHeader64() const
Definition:MachOObjectFile.cpp:4815
llvm::object::MachOObjectFile::getDyldChainedFixupTargets
Expected< std::vector< ChainedFixupTarget > > getDyldChainedFixupTargets() const
Definition:MachOObjectFile.cpp:5157
llvm::object::MachOObjectFile::getSectionAlignment
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2003
llvm::object::MachOObjectFile::getScatteredRelocationType
uint32_t getScatteredRelocationType(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4572
llvm::object::MachOObjectFile::getRelocationSymbol
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Definition:MachOObjectFile.cpp:2245
llvm::object::MachOObjectFile::getSection
Expected< SectionRef > getSection(unsigned SectionIndex) const
Definition:MachOObjectFile.cpp:2016
llvm::object::MachOObjectFile::rebaseTable
iterator_range< rebase_iterator > rebaseTable(Error &Err)
For use iterating over all rebase table entries.
Definition:MachOObjectFile.cpp:3813
llvm::object::MachOObjectFile::getIndirectName
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const
Definition:MachOObjectFile.cpp:1806
llvm::object::MachOObjectFile::begin_load_commands
load_command_iterator begin_load_commands() const
Definition:MachOObjectFile.cpp:4504
llvm::object::MachOObjectFile::getEncryptionInfoCommand64
MachO::encryption_info_command_64 getEncryptionInfoCommand64(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4734
llvm::object::MachOObjectFile::getFileFormatName
StringRef getFileFormatName() const override
Definition:MachOObjectFile.cpp:2658
llvm::object::MachOObjectFile::begin_dices
dice_iterator begin_dices() const
Definition:MachOObjectFile.cpp:2899
llvm::object::MachOObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition:MachOObjectFile.cpp:2595
llvm::object::MachOObjectFile::getChainedFixupsLoadCommand
Expected< std::optional< MachO::linkedit_data_command > > getChainedFixupsLoadCommand() const
Definition:MachOObjectFile.cpp:4978
llvm::object::MachOObjectFile::exports
iterator_range< export_iterator > exports(Error &Err) const
For use iterating over all exported symbols.
Definition:MachOObjectFile.cpp:3240
llvm::object::MachOObjectFile::getSymbolIndex
uint64_t getSymbolIndex(DataRefImpl Symb) const
Definition:MachOObjectFile.cpp:2631
llvm::object::MachOObjectFile::getBuildVersionLoadCommand
MachO::build_version_command getBuildVersionLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4684
llvm::object::MachOObjectFile::section_end
section_iterator section_end() const override
Definition:MachOObjectFile.cpp:2648
llvm::object::MachOObjectFile::getBuildToolVersion
MachO::build_tool_version getBuildToolVersion(unsigned index) const
Definition:MachOObjectFile.cpp:4689
llvm::object::MachOObjectFile::getDataInCodeLoadCommand
MachO::linkedit_data_command getDataInCodeLoadCommand() const
Definition:MachOObjectFile.cpp:4879
llvm::object::MachOObjectFile::getRoutinesCommand
MachO::routines_command getRoutinesCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4759
llvm::object::MachOObjectFile::getSymbolTableEntry
MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const
Definition:MachOObjectFile.cpp:4642
llvm::object::MachOObjectFile::getSymbolSectionID
unsigned getSymbolSectionID(SymbolRef Symb) const
Definition:MachOObjectFile.cpp:1926
llvm::object::MachOObjectFile::findDsymObjectMembers
static Expected< std::vector< std::string > > findDsymObjectMembers(StringRef Path)
If the input path is a .dSYM bundle (as created by the dsymutil tool), return the paths to the object...
Definition:MachOObjectFile.cpp:5346
llvm::object::MachOObjectFile::getScatteredRelocationValue
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4567
llvm::object::MachOObjectFile::getLinkerOptionLoadCommand
MachO::linker_option_command getLinkerOptionLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4669
llvm::object::MachOObjectFile::getLibraryCount
uint32_t getLibraryCount() const
Definition:MachOObjectFile.cpp:2584
llvm::object::MachOObjectFile::getEntryPointCommand
MachO::entry_point_command getEntryPointCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4724
llvm::object::MachOObjectFile::getSymbolSection
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
Definition:MachOObjectFile.cpp:1911
llvm::object::MachOObjectFile::RebaseEntryCheckSegAndOffsets
const char * RebaseEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint64_t Count=1, uint64_t Skip=0) const
Definition:MachO.h:592
llvm::object::MachOObjectFile::getRelocationOffset
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Definition:MachOObjectFile.cpp:2236
llvm::object::MachOObjectFile::getDyldInfoLazyBindOpcodes
ArrayRef< uint8_t > getDyldInfoLazyBindOpcodes() const
Definition:MachOObjectFile.cpp:4949
llvm::object::MachOObjectFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition:MachOObjectFile.cpp:1767
llvm::object::MachOObjectFile::getAnyRelocationSection
SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4607
llvm::object::MachOObjectFile::getDysymtabLoadCommand
MachO::dysymtab_command getDysymtabLoadCommand() const
Definition:MachOObjectFile.cpp:4849
llvm::object::MachOObjectFile::bindTable
iterator_range< bind_iterator > bindTable(Error &Err)
For use iterating over all bind table entries.
Definition:MachOObjectFile.cpp:4475
llvm::object::MachOObjectFile::Header
MachO::mach_header Header
Definition:MachO.h:850
llvm::object::MachOObjectFile::getCommonSymbolSizeImpl
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
Definition:MachOObjectFile.cpp:1837
llvm::object::MachOObjectFile::section_rel_begin
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2174
llvm::object::MachOObjectFile::getSection64
MachO::section_64 getSection64(DataRefImpl DRI) const
Definition:MachOObjectFile.cpp:4624
llvm::object::MachOObjectFile::getFilesetEntryLoadCommand
MachO::fileset_entry_command getFilesetEntryLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4774
llvm::object::MachOObjectFile::getNoteLoadCommand
MachO::note_command getNoteLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4679
llvm::object::MachOObjectFile::getThreadCommand
MachO::thread_command getThreadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4769
llvm::object::MachOObjectFile::getSectionContents
ArrayRef< uint8_t > getSectionContents(uint32_t Offset, uint64_t Size) const
Definition:MachOObjectFile.cpp:1980
llvm::object::MachOObjectFile::BindEntryCheckSegAndOffsets
const char * BindEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint64_t Count=1, uint64_t Skip=0) const
Definition:MachO.h:578
llvm::object::MachOObjectFile::section_begin
section_iterator section_begin() const override
Definition:MachOObjectFile.cpp:2643
llvm::object::MachOObjectFile::checkSymbolTable
Error checkSymbolTable() const
Definition:MachOObjectFile.cpp:1700
llvm::object::MachOObjectFile::isRelocatableObject
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
Definition:MachOObjectFile.cpp:5308
llvm::object::MachOObjectFile::getSegment64LoadCommand
MachO::segment_command_64 getSegment64LoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4664
llvm::object::MachOObjectFile::section_rel_end
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2182
llvm::object::MachOObjectFile::getDyldInfoExportsTrie
ArrayRef< uint8_t > getDyldInfoExportsTrie() const
Definition:MachOObjectFile.cpp:4963
llvm::object::MachOObjectFile::isDebugSection
bool isDebugSection(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2061
llvm::object::MachOObjectFile::getSymbol64TableEntry
MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const
Definition:MachOObjectFile.cpp:4648
llvm::object::MachOObjectFile::getSectionType
unsigned getSectionType(SectionRef Sec) const
Definition:MachOObjectFile.cpp:1789
llvm::object::MachOObjectFile::getSegmentLoadCommand
MachO::segment_command getSegmentLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4659
llvm::object::MachOObjectFile::create
static Expected< std::unique_ptr< MachOObjectFile > > create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0, size_t MachOFilesetEntryOffset=0)
Definition:MachOObjectFile.cpp:1253
llvm::object::MachOObjectFile::getSectionFinalSegmentName
StringRef getSectionFinalSegmentName(DataRefImpl Sec) const
Definition:MachOObjectFile.cpp:4519
llvm::object::MachOObjectFile::getLinkOptHintsLoadCommand
MachO::linkedit_data_command getLinkOptHintsLoadCommand() const
Definition:MachOObjectFile.cpp:4893
llvm::object::MachOObjectFile::getAnyRelocationType
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4599
llvm::object::MachOObjectFile::getRpathCommand
MachO::rpath_command getRpathCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4714
llvm::object::MachOObjectFile::end_dices
dice_iterator end_dices() const
Definition:MachOObjectFile.cpp:2909
llvm::object::MachOObjectFile::getRoutinesCommand64
MachO::routines_command_64 getRoutinesCommand64(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4764
llvm::object::MachOObjectFile::getSubFrameworkCommand
MachO::sub_framework_command getSubFrameworkCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4739
llvm::object::MachOObjectFile::getFunctionStarts
SmallVector< uint64_t > getFunctionStarts() const
Definition:MachOObjectFile.cpp:5263
llvm::object::MachOObjectFile::getSubLibraryCommand
MachO::sub_library_command getSubLibraryCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4749
llvm::object::MachOObjectFile::getDyldInfoLoadCommand
MachO::dyld_info_command getDyldInfoLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4699
llvm::object::MachOObjectFile::getSubUmbrellaCommand
MachO::sub_umbrella_command getSubUmbrellaCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4744
llvm::object::MachOObjectFile::getDyldExportsTrie
ArrayRef< uint8_t > getDyldExportsTrie() const
Definition:MachOObjectFile.cpp:5249
llvm::object::MachOObjectFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition:MachOObjectFile.cpp:1867
llvm::object::MachOObjectFile::getRelocationRelocatedSection
section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const
Definition:MachOObjectFile.cpp:2589
llvm::object::MachOObjectFile::isSectionBSS
bool isSectionBSS(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2053
llvm::object::MachOObjectFile::getChainedFixupsSegments
Expected< std::pair< size_t, std::vector< ChainedFixupsSegment > > > getChainedFixupsSegments() const
Definition:MachOObjectFile.cpp:5048
llvm::object::MachOObjectFile::isSectionVirtual
bool isSectionVirtual(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2154
llvm::object::MachOObjectFile::getScatteredRelocationScattered
bool getScatteredRelocationScattered(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4562
llvm::object::MachOObjectFile::getSymbolName
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
Definition:MachOObjectFile.cpp:1774
llvm::object::MachOObjectFile::getPlainRelocationExternal
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4555
llvm::object::MachOObjectFile::getSymbolByIndex
symbol_iterator getSymbolByIndex(unsigned Index) const
Definition:MachOObjectFile.cpp:2619
llvm::object::MachOObjectFile::getHostArch
static Triple getHostArch()
Definition:MachOObjectFile.cpp:2845
llvm::object::MachOObjectFile::getEncryptionInfoCommand
MachO::encryption_info_command getEncryptionInfoCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4729
llvm::object::MachOObjectFile::getHeader
const MachO::mach_header & getHeader() const
Definition:MachOObjectFile.cpp:4811
llvm::object::MachOObjectFile::getAnyRelocationPCRel
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4584
llvm::object::MachOObjectFile::weakBindTable
iterator_range< bind_iterator > weakBindTable(Error &Err)
For use iterating over all weak bind table entries.
Definition:MachOObjectFile.cpp:4485
llvm::object::MachOObjectFile::isMachOPairedReloc
static bool isMachOPairedReloc(uint64_t RelocType, uint64_t Arch)
Definition:MachOObjectFile.cpp:5400
llvm::object::MachOObjectFile::getDyldInfoRebaseOpcodes
ArrayRef< uint8_t > getDyldInfoRebaseOpcodes() const
Definition:MachOObjectFile.cpp:4907
llvm::object::MachOObjectFile::load_commands
iterator_range< load_command_iterator > load_commands() const
Definition:MachOObjectFile.cpp:4514
llvm::object::MachOObjectFile::getAnyRelocationLength
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4591
llvm::object::MachOObjectFile::getSymtabLoadCommand
MachO::symtab_command getSymtabLoadCommand() const
Definition:MachOObjectFile.cpp:4834
llvm::object::MachOObjectFile::getArchTriple
Triple getArchTriple(const char **McpuDefault=nullptr) const
Definition:MachOObjectFile.cpp:2883
llvm::object::MachOObjectFile::getUuidCommand
MachO::uuid_command getUuidCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4709
llvm::object::MachOObjectFile::getPlainRelocationSymbolNum
unsigned getPlainRelocationSymbolNum(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4548
llvm::object::MachOObjectFile::getUuid
ArrayRef< uint8_t > getUuid() const
Definition:MachOObjectFile.cpp:5278
llvm::object::MachOObjectFile::BindRebaseAddress
uint64_t BindRebaseAddress(uint32_t SegIndex, uint64_t SegOffset) const
For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or Rebase entry to get the address.
Definition:MachO.h:615
llvm::object::MachOObjectFile::is64Bit
bool is64Bit() const override
Definition:MachOObjectFile.cpp:5291
llvm::object::MachOObjectFile::getVersionMinLoadCommand
MachO::version_min_command getVersionMinLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4674
llvm::object::MachOObjectFile::mapDebugSectionName
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
Definition:MachOObjectFile.cpp:5339
llvm::object::MachOObjectFile::getDylinkerCommand
MachO::dylinker_command getDylinkerCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4704
llvm::object::MachOObjectFile::getRelocationType
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition:MachOObjectFile.cpp:2270
llvm::object::MachOObjectFile::BindRebaseSegmentName
StringRef BindRebaseSegmentName(int32_t SegIndex) const
For use with the SegIndex of a checked Mach-O Bind or Rebase entry to get the segment name.
Definition:MachO.h:603
llvm::object::MachOObjectFile::extrel_begin
relocation_iterator extrel_begin() const
Definition:MachOObjectFile.cpp:2198
llvm::object::MachOObjectFile::moveRelocationNext
void moveRelocationNext(DataRefImpl &Rel) const override
Definition:MachOObjectFile.cpp:2232
llvm::object::MachOObjectFile::getRelocation
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
Definition:MachOObjectFile.cpp:4779
llvm::object::MachOObjectFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition:MachOObjectFile.cpp:2604
llvm::object::MachOObjectFile::getDataInCodeTableEntry
MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset, unsigned Index) const
Definition:MachOObjectFile.cpp:4828
llvm::object::MachOObjectFile::getDice
MachO::data_in_code_entry getDice(DataRefImpl Rel) const
Definition:MachOObjectFile.cpp:4806
llvm::object::MachOObjectFile::isSectionStripped
bool isSectionStripped(DataRefImpl Sec) const override
When dsymutil generates the companion file, it strips all unnecessary sections (e....
Definition:MachOObjectFile.cpp:2168
llvm::object::MachOObjectFile::getSectionIndex
uint64_t getSectionIndex(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:1947
llvm::object::MachOObjectFile::fixupTable
iterator_range< fixup_iterator > fixupTable(Error &Err)
For iterating over all chained fixups.
Definition:MachOObjectFile.cpp:4490
llvm::object::MachOObjectFile::ReadULEB128s
void ReadULEB128s(uint64_t Index, SmallVectorImpl< uint64_t > &Out) const
Definition:MachOObjectFile.cpp:5296
llvm::object::MachOObjectFile::BindRebaseSectionName
StringRef BindRebaseSectionName(uint32_t SegIndex, uint64_t SegOffset) const
For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or Rebase entry to get the section ...
Definition:MachO.h:609
llvm::object::MachOObjectFile::lazyBindTable
iterator_range< bind_iterator > lazyBindTable(Error &Err)
For use iterating over all lazy bind table entries.
Definition:MachOObjectFile.cpp:4480
llvm::object::MachOObjectFile::end_load_commands
load_command_iterator end_load_commands() const
Definition:MachOObjectFile.cpp:4509
llvm::object::MachOObjectFile::getDyldInfoBindOpcodes
ArrayRef< uint8_t > getDyldInfoBindOpcodes() const
Definition:MachOObjectFile.cpp:4921
llvm::object::MachOObjectFile::getSymbolType
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Definition:MachOObjectFile.cpp:1842
llvm::object::MachOObjectFile::getSectionAddress
uint64_t getSectionAddress(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:1941
llvm::object::MachOObjectFile::hasPageZeroSegment
bool hasPageZeroSegment() const
Definition:MachO.h:765
llvm::object::MachOObjectFile::getSectionName
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:1936
llvm::object::MachOObjectFile::getRelocationLength
uint8_t getRelocationLength(DataRefImpl Rel) const
Definition:MachOObjectFile.cpp:2385
llvm::object::MachOObjectFile::mapReflectionSectionNameToEnumValue
llvm::binaryformat::Swift5ReflectionSectionKind mapReflectionSectionNameToEnumValue(StringRef SectionName) const override
Definition:MachOObjectFile.cpp:5389
llvm::object::MachOObjectFile::getDyldInfoWeakBindOpcodes
ArrayRef< uint8_t > getDyldInfoWeakBindOpcodes() const
Definition:MachOObjectFile.cpp:4935
llvm::object::MachOObjectFile::isValidArch
static bool isValidArch(StringRef ArchFlag)
Definition:MachOObjectFile.cpp:2849
llvm::object::MachOObjectFile::isSectionText
bool isSectionText(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2040
llvm::object::MachOObjectFile::isSectionCompressed
bool isSectionCompressed(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2036
llvm::object::MachOObjectFile::getValidArchs
static ArrayRef< StringRef > getValidArchs()
Definition:MachOObjectFile.cpp:2854
llvm::object::MachOObjectFile::isSectionBitcode
bool isSectionBitcode(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:2161
llvm::object::MachOObjectFile::isRelocationScattered
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4541
llvm::object::MachOObjectFile::locrel_begin
relocation_iterator locrel_begin() const
Definition:MachOObjectFile.cpp:2215
llvm::object::MachOObjectFile::getChainedFixupsHeader
Expected< std::optional< MachO::dyld_chained_fixups_header > > getChainedFixupsHeader() const
If the optional is std::nullopt, no header was found, but the object was well-formed.
Definition:MachOObjectFile.cpp:4997
llvm::object::MachOObjectFile::getSymbolAlignment
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Definition:MachOObjectFile.cpp:1828
llvm::object::MachOObjectFile::getSourceVersionCommand
MachO::source_version_command getSourceVersionCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4719
llvm::object::MachOObjectFile::getAnyRelocationAddress
unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const
Definition:MachOObjectFile.cpp:4577
llvm::object::MachOObjectFile::getStringTableData
StringRef getStringTableData() const
Definition:MachOObjectFile.cpp:5286
llvm::object::MachOObjectFile::getRelocationTypeName
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
Definition:MachOObjectFile.cpp:2275
llvm::object::MachOObjectFile::getSectionRawName
ArrayRef< char > getSectionRawName(DataRefImpl Sec) const
Definition:MachOObjectFile.cpp:4525
llvm::object::MachOObjectFile::getNValue
uint64_t getNValue(DataRefImpl Sym) const
Definition:MachOObjectFile.cpp:1795
llvm::object::MachOObjectFile::getSegmentContents
ArrayRef< uint8_t > getSegmentContents(StringRef SegmentName) const
Return the raw contents of an entire segment.
Definition:MachOObjectFile.cpp:2107
llvm::object::MachOObjectFile::getRelocationSection
section_iterator getRelocationSection(DataRefImpl Rel) const
Definition:MachOObjectFile.cpp:2266
llvm::object::MachOObjectFile::getSectionID
unsigned getSectionID(SectionRef Sec) const
Definition:MachOObjectFile.cpp:2150
llvm::object::MachOObjectFile::getLinkeditDataLoadCommand
MachO::linkedit_data_command getLinkeditDataLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4654
llvm::object::MachOObjectFile::getSymbolAddress
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Definition:MachOObjectFile.cpp:1824
llvm::object::MachOObjectFile::getDylibIDLoadCommand
MachO::dylib_command getDylibIDLoadCommand(const LoadCommandInfo &L) const
Definition:MachOObjectFile.cpp:4694
llvm::object::MachOObjectFile::getMachOFilesetEntryOffset
size_t getMachOFilesetEntryOffset() const
Definition:MachO.h:767
llvm::object::MachOObjectFile::getIndirectSymbolTableEntry
uint32_t getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
Definition:MachOObjectFile.cpp:4820
llvm::object::MachOObjectFile::getSectionSize
uint64_t getSectionSize(DataRefImpl Sec) const override
Definition:MachOObjectFile.cpp:1951
llvm::object::MachOObjectFile::extrel_end
relocation_iterator extrel_end() const
Definition:MachOObjectFile.cpp:2206
llvm::object::MachOObjectFile::guessLibraryShortName
static StringRef guessLibraryShortName(StringRef Name, bool &isFramework, StringRef &Suffix)
Definition:MachOObjectFile.cpp:2426
llvm::object::MachOObjectFile::locrel_end
relocation_iterator locrel_end() const
Definition:MachOObjectFile.cpp:2223
llvm::object::MachOObjectFile::getLibraryShortNameByIndex
std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const
Definition:MachOObjectFile.cpp:2550
llvm::object::MachORebaseEntry
MachORebaseEntry encapsulates the current state in the decompression of rebasing opcodes.
Definition:MachO.h:168
llvm::object::MachORebaseEntry::segmentIndex
int32_t segmentIndex() const
Definition:MachOObjectFile.cpp:3754
llvm::object::MachORebaseEntry::segmentName
StringRef segmentName() const
Definition:MachOObjectFile.cpp:3772
llvm::object::MachORebaseEntry::MachORebaseEntry
MachORebaseEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > opcodes, bool is64Bit)
Definition:MachOObjectFile.cpp:3478
llvm::object::MachORebaseEntry::operator==
bool operator==(const MachORebaseEntry &) const
Definition:MachOObjectFile.cpp:3788
llvm::object::MachORebaseEntry::address
uint64_t address() const
Definition:MachOObjectFile.cpp:3784
llvm::object::MachORebaseEntry::moveNext
void moveNext()
Definition:MachOObjectFile.cpp:3494
llvm::object::MachORebaseEntry::sectionName
StringRef sectionName() const
Definition:MachOObjectFile.cpp:3778
llvm::object::MachORebaseEntry::segmentOffset
uint64_t segmentOffset() const
Definition:MachOObjectFile.cpp:3756
llvm::object::MachORebaseEntry::typeName
StringRef typeName() const
Definition:MachOObjectFile.cpp:3758
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition:ObjectFile.h:229
llvm::object::ObjectFile::RelocationRef
friend class RelocationRef
Definition:ObjectFile.h:287
llvm::object::ObjectFile::SymbolRef
friend class SymbolRef
Definition:ObjectFile.h:247
llvm::object::ObjectFile::createMachOObjectFile
static Expected< std::unique_ptr< MachOObjectFile > > createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0, size_t MachOFilesetEntryOffset=0)
Create a MachOObjectFile instance from a given buffer.
Definition:MachOObjectFile.cpp:5319
llvm::object::ObjectFile::sections
section_iterator_range sections() const
Definition:ObjectFile.h:329
llvm::object::ObjectFile::SectionRef
friend class SectionRef
Definition:ObjectFile.h:261
llvm::object::ObjectFile::symbols
symbol_iterator_range symbols() const
Definition:ObjectFile.h:321
llvm::object::ObjectFile::getSymbolValue
Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const
Definition:ObjectFile.cpp:56
llvm::object::SectionRef
This is a value type class that represents a single section in the list of sections in the object fil...
Definition:ObjectFile.h:81
llvm::object::SectionRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition:ObjectFile.h:598
llvm::object::SectionRef::isData
bool isData() const
Whether this section contains data, not instructions.
Definition:ObjectFile.h:554
llvm::object::SectionRef::isBSS
bool isBSS() const
Whether this section contains BSS uninitialized data.
Definition:ObjectFile.h:558
llvm::object::SymbolRef
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition:ObjectFile.h:168
llvm::object::SymbolRef::ST_Other
@ ST_Other
Definition:ObjectFile.h:174
llvm::object::SymbolRef::ST_Unknown
@ ST_Unknown
Definition:ObjectFile.h:173
llvm::object::SymbolRef::ST_Function
@ ST_Function
Definition:ObjectFile.h:178
llvm::object::SymbolRef::ST_Data
@ ST_Data
Definition:ObjectFile.h:175
llvm::object::SymbolRef::ST_Debug
@ ST_Debug
Definition:ObjectFile.h:176
llvm::object::content_iterator< SectionRef >
llvm::object::symbol_iterator
Definition:ObjectFile.h:208
llvm::sys::fs::directory_iterator
directory_iterator - Iterates through the entries in path.
Definition:FileSystem.h:1416
llvm::sys::fs::file_status
Represents the result of a call to sys::fs::status().
Definition:FileSystem.h:221
uint16_t
uint32_t
uint64_t
uint8_t
Error.h
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
Error.h
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::MachO::x86_FLOAT_STATE_COUNT
const uint32_t x86_FLOAT_STATE_COUNT
Definition:MachO.h:1976
llvm::MachO::DYLD_CHAINED_IMPORT
@ DYLD_CHAINED_IMPORT
Definition:MachO.h:1027
llvm::MachO::DYLD_CHAINED_IMPORT_ADDEND
@ DYLD_CHAINED_IMPORT_ADDEND
Definition:MachO.h:1028
llvm::MachO::DYLD_CHAINED_IMPORT_ADDEND64
@ DYLD_CHAINED_IMPORT_ADDEND64
Definition:MachO.h:1029
llvm::MachO::SECTION_TYPE
@ SECTION_TYPE
Definition:MachO.h:114
llvm::MachO::ARM_THREAD_STATE64_COUNT
const uint32_t ARM_THREAD_STATE64_COUNT
Definition:MachO.h:2054
llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE
@ EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE
Definition:MachO.h:301
llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL
@ EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL
Definition:MachO.h:300
llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_REGULAR
@ EXPORT_SYMBOL_FLAGS_KIND_REGULAR
Definition:MachO.h:299
llvm::MachO::BIND_TYPE_TEXT_PCREL32
@ BIND_TYPE_TEXT_PCREL32
Definition:MachO.h:257
llvm::MachO::BIND_TYPE_POINTER
@ BIND_TYPE_POINTER
Definition:MachO.h:255
llvm::MachO::BIND_TYPE_TEXT_ABSOLUTE32
@ BIND_TYPE_TEXT_ABSOLUTE32
Definition:MachO.h:256
llvm::MachO::S_ATTR_PURE_INSTRUCTIONS
@ S_ATTR_PURE_INSTRUCTIONS
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition:MachO.h:192
llvm::MachO::x86_EXCEPTION_STATE_COUNT
const uint32_t x86_EXCEPTION_STATE_COUNT
Definition:MachO.h:1978
llvm::MachO::ARM_THREAD_STATE64
@ ARM_THREAD_STATE64
Definition:MachO.h:2041
llvm::MachO::ARM_THREAD_STATE
@ ARM_THREAD_STATE
Definition:MachO.h:2036
llvm::MachO::REBASE_TYPE_POINTER
@ REBASE_TYPE_POINTER
Definition:MachO.h:235
llvm::MachO::REBASE_TYPE_TEXT_ABSOLUTE32
@ REBASE_TYPE_TEXT_ABSOLUTE32
Definition:MachO.h:236
llvm::MachO::REBASE_TYPE_TEXT_PCREL32
@ REBASE_TYPE_TEXT_PCREL32
Definition:MachO.h:237
llvm::MachO::MH_OBJECT
@ MH_OBJECT
Definition:MachO.h:43
llvm::MachO::MH_CORE
@ MH_CORE
Definition:MachO.h:46
llvm::MachO::MH_DSYM
@ MH_DSYM
Definition:MachO.h:52
llvm::MachO::MH_DYLIB
@ MH_DYLIB
Definition:MachO.h:48
llvm::MachO::MH_DYLIB_STUB
@ MH_DYLIB_STUB
Definition:MachO.h:51
llvm::MachO::MH_KEXT_BUNDLE
@ MH_KEXT_BUNDLE
Definition:MachO.h:53
llvm::MachO::N_TYPE
@ N_TYPE
Definition:MachO.h:309
llvm::MachO::N_EXT
@ N_EXT
Definition:MachO.h:310
llvm::MachO::N_PEXT
@ N_PEXT
Definition:MachO.h:308
llvm::MachO::N_STAB
@ N_STAB
Definition:MachO.h:307
llvm::MachO::S_GB_ZEROFILL
@ S_GB_ZEROFILL
S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 gigabytes).
Definition:MachO.h:155
llvm::MachO::S_THREAD_LOCAL_ZEROFILL
@ S_THREAD_LOCAL_ZEROFILL
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition:MachO.h:169
llvm::MachO::S_ZEROFILL
@ S_ZEROFILL
S_ZEROFILL - Zero fill on demand section.
Definition:MachO.h:129
llvm::MachO::BIND_SPECIAL_DYLIB_WEAK_LOOKUP
@ BIND_SPECIAL_DYLIB_WEAK_LOOKUP
Definition:MachO.h:264
llvm::MachO::BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE
@ BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE
Definition:MachO.h:262
llvm::MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP
@ BIND_SPECIAL_DYLIB_FLAT_LOOKUP
Definition:MachO.h:263
llvm::MachO::DYLD_CHAINED_PTR_START_NONE
@ DYLD_CHAINED_PTR_START_NONE
Definition:MachO.h:1040
llvm::MachO::CPU_SUBTYPE_MASK
@ CPU_SUBTYPE_MASK
Definition:MachO.h:1579
llvm::MachO::GET_COMM_ALIGN
uint8_t GET_COMM_ALIGN(uint16_t n_desc)
Definition:MachO.h:1545
llvm::MachO::swapStruct
void swapStruct(fat_header &mh)
Definition:MachO.h:1140
llvm::MachO::x86_THREAD_STATE32_COUNT
const uint32_t x86_THREAD_STATE32_COUNT
Definition:MachO.h:1964
llvm::MachO::PPC_THREAD_STATE
@ PPC_THREAD_STATE
Definition:MachO.h:2161
llvm::MachO::EXPORT_SYMBOL_FLAGS_REEXPORT
@ EXPORT_SYMBOL_FLAGS_REEXPORT
Definition:MachO.h:294
llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_MASK
@ EXPORT_SYMBOL_FLAGS_KIND_MASK
Definition:MachO.h:292
llvm::MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
@ EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
Definition:MachO.h:295
llvm::MachO::CPU_SUBTYPE_POWERPC_ALL
@ CPU_SUBTYPE_POWERPC_ALL
Definition:MachO.h:1683
llvm::MachO::BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
@ BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
Definition:MachO.h:288
llvm::MachO::BIND_OPCODE_DONE
@ BIND_OPCODE_DONE
Definition:MachO.h:276
llvm::MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
@ BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
Definition:MachO.h:286
llvm::MachO::BIND_OPCODE_SET_ADDEND_SLEB
@ BIND_OPCODE_SET_ADDEND_SLEB
Definition:MachO.h:282
llvm::MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB
@ BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB
Definition:MachO.h:278
llvm::MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
@ BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
Definition:MachO.h:280
llvm::MachO::BIND_OPCODE_ADD_ADDR_ULEB
@ BIND_OPCODE_ADD_ADDR_ULEB
Definition:MachO.h:284
llvm::MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
@ BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
Definition:MachO.h:287
llvm::MachO::BIND_OPCODE_SET_DYLIB_SPECIAL_IMM
@ BIND_OPCODE_SET_DYLIB_SPECIAL_IMM
Definition:MachO.h:279
llvm::MachO::BIND_OPCODE_DO_BIND
@ BIND_OPCODE_DO_BIND
Definition:MachO.h:285
llvm::MachO::BIND_OPCODE_SET_TYPE_IMM
@ BIND_OPCODE_SET_TYPE_IMM
Definition:MachO.h:281
llvm::MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
@ BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
Definition:MachO.h:277
llvm::MachO::BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
@ BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
Definition:MachO.h:283
llvm::MachO::x86_THREAD_STATE
@ x86_THREAD_STATE
Definition:MachO.h:1938
llvm::MachO::x86_THREAD_STATE64
@ x86_THREAD_STATE64
Definition:MachO.h:1935
llvm::MachO::x86_EXCEPTION_STATE64
@ x86_EXCEPTION_STATE64
Definition:MachO.h:1937
llvm::MachO::x86_EXCEPTION_STATE
@ x86_EXCEPTION_STATE
Definition:MachO.h:1940
llvm::MachO::x86_THREAD_STATE32
@ x86_THREAD_STATE32
Definition:MachO.h:1932
llvm::MachO::x86_FLOAT_STATE
@ x86_FLOAT_STATE
Definition:MachO.h:1939
llvm::MachO::PPC_THREAD_STATE_COUNT
const uint32_t PPC_THREAD_STATE_COUNT
Definition:MachO.h:2176
llvm::MachO::ARM_THREAD_STATE_COUNT
const uint32_t ARM_THREAD_STATE_COUNT
Definition:MachO.h:2051
llvm::MachO::REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
@ REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
Definition:MachO.h:245
llvm::MachO::REBASE_OPCODE_DO_REBASE_IMM_TIMES
@ REBASE_OPCODE_DO_REBASE_IMM_TIMES
Definition:MachO.h:248
llvm::MachO::REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB
@ REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB
Definition:MachO.h:250
llvm::MachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB
@ REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB
Definition:MachO.h:251
llvm::MachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES
@ REBASE_OPCODE_DO_REBASE_ULEB_TIMES
Definition:MachO.h:249
llvm::MachO::REBASE_OPCODE_ADD_ADDR_ULEB
@ REBASE_OPCODE_ADD_ADDR_ULEB
Definition:MachO.h:246
llvm::MachO::REBASE_OPCODE_SET_TYPE_IMM
@ REBASE_OPCODE_SET_TYPE_IMM
Definition:MachO.h:244
llvm::MachO::REBASE_OPCODE_DONE
@ REBASE_OPCODE_DONE
Definition:MachO.h:243
llvm::MachO::REBASE_OPCODE_ADD_ADDR_IMM_SCALED
@ REBASE_OPCODE_ADD_ADDR_IMM_SCALED
Definition:MachO.h:247
llvm::MachO::N_SECT
@ N_SECT
Definition:MachO.h:318
llvm::MachO::N_PBUD
@ N_PBUD
Definition:MachO.h:319
llvm::MachO::N_ABS
@ N_ABS
Definition:MachO.h:317
llvm::MachO::N_INDR
@ N_INDR
Definition:MachO.h:320
llvm::MachO::N_UNDF
@ N_UNDF
Definition:MachO.h:316
llvm::MachO::REBASE_IMMEDIATE_MASK
@ REBASE_IMMEDIATE_MASK
Definition:MachO.h:240
llvm::MachO::REBASE_OPCODE_MASK
@ REBASE_OPCODE_MASK
Definition:MachO.h:240
llvm::MachO::CPU_SUBTYPE_ARM_V7
@ CPU_SUBTYPE_ARM_V7
Definition:MachO.h:1631
llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ
@ CPU_SUBTYPE_ARM_V5TEJ
Definition:MachO.h:1629
llvm::MachO::CPU_SUBTYPE_ARM_V7M
@ CPU_SUBTYPE_ARM_V7M
Definition:MachO.h:1636
llvm::MachO::CPU_SUBTYPE_ARM_V6
@ CPU_SUBTYPE_ARM_V6
Definition:MachO.h:1627
llvm::MachO::CPU_SUBTYPE_ARM_XSCALE
@ CPU_SUBTYPE_ARM_XSCALE
Definition:MachO.h:1630
llvm::MachO::CPU_SUBTYPE_ARM_V7K
@ CPU_SUBTYPE_ARM_V7K
Definition:MachO.h:1634
llvm::MachO::CPU_SUBTYPE_ARM_V6M
@ CPU_SUBTYPE_ARM_V6M
Definition:MachO.h:1635
llvm::MachO::CPU_SUBTYPE_ARM_V7EM
@ CPU_SUBTYPE_ARM_V7EM
Definition:MachO.h:1637
llvm::MachO::CPU_SUBTYPE_ARM_V7S
@ CPU_SUBTYPE_ARM_V7S
Definition:MachO.h:1633
llvm::MachO::CPU_SUBTYPE_ARM_V4T
@ CPU_SUBTYPE_ARM_V4T
Definition:MachO.h:1626
llvm::MachO::CPU_SUBTYPE_ARM64E
@ CPU_SUBTYPE_ARM64E
Definition:MachO.h:1643
llvm::MachO::CPU_SUBTYPE_ARM64_ALL
@ CPU_SUBTYPE_ARM64_ALL
Definition:MachO.h:1641
llvm::MachO::x86_THREAD_STATE_COUNT
const uint32_t x86_THREAD_STATE_COUNT
Definition:MachO.h:1974
llvm::MachO::CPU_SUBTYPE_ARM64_32_V8
@ CPU_SUBTYPE_ARM64_32_V8
Definition:MachO.h:1678
llvm::MachO::GENERIC_RELOC_LOCAL_SECTDIFF
@ GENERIC_RELOC_LOCAL_SECTDIFF
Definition:MachO.h:414
llvm::MachO::ARM_RELOC_LOCAL_SECTDIFF
@ ARM_RELOC_LOCAL_SECTDIFF
Definition:MachO.h:443
llvm::MachO::ARM64_RELOC_SUBTRACTOR
@ ARM64_RELOC_SUBTRACTOR
Definition:MachO.h:458
llvm::MachO::ARM_RELOC_HALF_SECTDIFF
@ ARM_RELOC_HALF_SECTDIFF
Definition:MachO.h:449
llvm::MachO::ARM_RELOC_SECTDIFF
@ ARM_RELOC_SECTDIFF
Definition:MachO.h:442
llvm::MachO::GENERIC_RELOC_SECTDIFF
@ GENERIC_RELOC_SECTDIFF
Definition:MachO.h:412
llvm::MachO::X86_64_RELOC_SUBTRACTOR
@ X86_64_RELOC_SUBTRACTOR
Definition:MachO.h:488
llvm::MachO::ARM_RELOC_HALF
@ ARM_RELOC_HALF
Definition:MachO.h:448
llvm::MachO::R_ABS
@ R_ABS
Definition:MachO.h:398
llvm::MachO::R_SCATTERED
@ R_SCATTERED
Definition:MachO.h:402
llvm::MachO::GET_LIBRARY_ORDINAL
uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc)
Definition:MachO.h:1537
llvm::MachO::DYLD_CHAINED_PTR_64_OFFSET
@ DYLD_CHAINED_PTR_64_OFFSET
Definition:MachO.h:1052
llvm::MachO::DYLD_CHAINED_PTR_64
@ DYLD_CHAINED_PTR_64
Definition:MachO.h:1048
llvm::MachO::x86_EXCEPTION_STATE64_COUNT
const uint32_t x86_EXCEPTION_STATE64_COUNT
Definition:MachO.h:1971
llvm::MachO::CPU_SUBTYPE_I386_ALL
@ CPU_SUBTYPE_I386_ALL
Definition:MachO.h:1588
llvm::MachO::CPU_SUBTYPE_X86_64_H
@ CPU_SUBTYPE_X86_64_H
Definition:MachO.h:1613
llvm::MachO::CPU_SUBTYPE_X86_64_ALL
@ CPU_SUBTYPE_X86_64_ALL
Definition:MachO.h:1611
llvm::MachO::DYNAMIC_LOOKUP_ORDINAL
@ DYNAMIC_LOOKUP_ORDINAL
Definition:MachO.h:354
llvm::MachO::N_WEAK_DEF
@ N_WEAK_DEF
Definition:MachO.h:346
llvm::MachO::EXECUTABLE_ORDINAL
@ EXECUTABLE_ORDINAL
Definition:MachO.h:355
llvm::MachO::N_ARM_THUMB_DEF
@ N_ARM_THUMB_DEF
Definition:MachO.h:342
llvm::MachO::N_WEAK_REF
@ N_WEAK_REF
Definition:MachO.h:345
llvm::MachO::x86_THREAD_STATE64_COUNT
const uint32_t x86_THREAD_STATE64_COUNT
Definition:MachO.h:1967
llvm::MachO::CPU_TYPE_ARM64_32
@ CPU_TYPE_ARM64_32
Definition:MachO.h:1571
llvm::MachO::CPU_TYPE_ARM64
@ CPU_TYPE_ARM64
Definition:MachO.h:1570
llvm::MachO::CPU_TYPE_POWERPC
@ CPU_TYPE_POWERPC
Definition:MachO.h:1573
llvm::MachO::CPU_TYPE_X86_64
@ CPU_TYPE_X86_64
Definition:MachO.h:1566
llvm::MachO::CPU_TYPE_POWERPC64
@ CPU_TYPE_POWERPC64
Definition:MachO.h:1574
llvm::MachO::CPU_TYPE_I386
@ CPU_TYPE_I386
Definition:MachO.h:1565
llvm::MachO::CPU_TYPE_ARM
@ CPU_TYPE_ARM
Definition:MachO.h:1569
llvm::MachO::MH_TWOLEVEL
@ MH_TWOLEVEL
Definition:MachO.h:67
llvm::MachO::BIND_SYMBOL_FLAGS_WEAK_IMPORT
@ BIND_SYMBOL_FLAGS_WEAK_IMPORT
Definition:MachO.h:268
llvm::MachO::BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION
@ BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION
Definition:MachO.h:269
llvm::MachO::BIND_OPCODE_MASK
@ BIND_OPCODE_MASK
Definition:MachO.h:271
llvm::MachO::BIND_IMMEDIATE_MASK
@ BIND_IMMEDIATE_MASK
Definition:MachO.h:272
llvm::SPII::Load
@ Load
Definition:SparcInstrInfo.h:32
llvm::XCOFF::SymbolTableEntrySize
constexpr size_t SymbolTableEntrySize
Definition:XCOFF.h:38
llvm::binaryformat::Swift5ReflectionSectionKind
Swift5ReflectionSectionKind
Definition:Swift.h:14
llvm::binaryformat::unknown
@ unknown
Definition:Swift.h:18
llvm::logicalview::LVPrintKind::Elements
@ Elements
llvm::logicalview::LVReportKind::Children
@ Children
llvm::object::createError
Error createError(const Twine &Err)
Definition:Error.h:84
llvm::object::export_iterator
content_iterator< ExportEntry > export_iterator
Definition:MachO.h:126
llvm::object::Kind
Kind
Definition:COFFModuleDefinition.cpp:31
llvm::object::object_error::invalid_file_type
@ invalid_file_type
llvm::object::object_error::parse_failed
@ parse_failed
llvm::object::fixup_iterator
content_iterator< MachOChainedFixupEntry > fixup_iterator
Definition:MachO.h:404
llvm::object::dice_iterator
content_iterator< DiceRef > dice_iterator
Definition:MachO.h:64
llvm::object::section_iterator
content_iterator< SectionRef > section_iterator
Definition:ObjectFile.h:47
llvm::object::bind_iterator
content_iterator< MachOBindEntry > bind_iterator
Definition:MachO.h:261
llvm::object::relocation_iterator
content_iterator< RelocationRef > relocation_iterator
Definition:ObjectFile.h:77
llvm::object::basic_symbol_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
Definition:SymbolicFile.h:143
llvm::object::rebase_iterator
content_iterator< MachORebaseEntry > rebase_iterator
Definition:MachO.h:203
llvm::sampleprof::Base
@ Base
Definition:Discriminator.h:58
llvm::sys::fs::status
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
llvm::sys::fs::file_type::type_unknown
@ type_unknown
llvm::sys::fs::file_type::regular_file
@ regular_file
llvm::sys::fs::file_type::symlink_file
@ symlink_file
llvm::sys::fs::is_directory
bool is_directory(const basic_file_status &status)
Does status represent a directory?
Definition:Path.cpp:1092
llvm::sys::path::remove_dots
bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
Definition:Path.cpp:715
llvm::sys::path::append
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition:Path.cpp:456
llvm::sys::path::extension
StringRef extension(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get extension.
Definition:Path.cpp:590
llvm::sys::IsLittleEndianHost
static const bool IsLittleEndianHost
Definition:SwapByteOrder.h:29
llvm::sys::swapByteOrder
void swapByteOrder(T &Value)
Definition:SwapByteOrder.h:61
llvm::sys::getDefaultTargetTriple
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::createFileError
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition:Error.h:1385
llvm::AlignStyle::Right
@ Right
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition:iterator_range.h:77
llvm::decodeULEB128
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
Definition:LEB128.h:131
llvm::SubDirectoryType::Lib
@ Lib
llvm::decodeSLEB128
int64_t decodeSLEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a SLEB128 value.
Definition:LEB128.h:165
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition:Error.h:1291
llvm::errc::no_such_file_or_directory
@ no_such_file_or_directory
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition:Format.h:125
llvm::IRMemLocation::Other
@ Other
Any other memory.
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition:Error.h:756
llvm::count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition:STLExtras.h:1938
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition:STLExtras.h:1903
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition:Error.cpp:111
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition:Error.h:1069
raw_ostream.h
N
#define N
MachOElement
Definition:MachOObjectFile.cpp:246
MachOElement::Offset
uint64_t Offset
Definition:MachOObjectFile.cpp:247
MachOElement::Name
const char * Name
Definition:MachOObjectFile.cpp:249
MachOElement::Size
uint64_t Size
Definition:MachOObjectFile.cpp:248
Status
Definition:SIModeRegister.cpp:29
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::MachO::any_relocation_info
Definition:MachO.h:997
llvm::MachO::any_relocation_info::r_word0
uint32_t r_word0
Definition:MachO.h:998
llvm::MachO::any_relocation_info::r_word1
uint32_t r_word1
Definition:MachO.h:998
llvm::MachO::arm_thread_state32_t
Definition:MachO.h:1981
llvm::MachO::arm_thread_state64_t
Definition:MachO.h:1998
llvm::MachO::build_tool_version
Definition:MachO.h:853
llvm::MachO::build_version_command
Definition:MachO.h:858
llvm::MachO::build_version_command::ntools
uint32_t ntools
Definition:MachO.h:865
llvm::MachO::data_in_code_entry
Definition:MachO.h:808
llvm::MachO::dyld_chained_fixups_header
Structs for dyld chained fixups.
Definition:MachO.h:1064
llvm::MachO::dyld_chained_fixups_header::imports_format
uint32_t imports_format
DYLD_CHAINED_IMPORT*.
Definition:MachO.h:1070
llvm::MachO::dyld_chained_fixups_header::starts_offset
uint32_t starts_offset
Offset of dyld_chained_starts_in_image.
Definition:MachO.h:1066
llvm::MachO::dyld_chained_fixups_header::fixups_version
uint32_t fixups_version
0
Definition:MachO.h:1065
llvm::MachO::dyld_chained_import_addend64
Definition:MachO.h:1109
llvm::MachO::dyld_chained_import_addend
Definition:MachO.h:1101
llvm::MachO::dyld_chained_import
Definition:MachO.h:1094
llvm::MachO::dyld_chained_starts_in_image
dyld_chained_starts_in_image is embedded in LC_DYLD_CHAINED_FIXUPS payload.
Definition:MachO.h:1077
llvm::MachO::dyld_chained_starts_in_image::seg_count
uint32_t seg_count
Definition:MachO.h:1078
llvm::MachO::dyld_chained_starts_in_segment
Definition:MachO.h:1082
llvm::MachO::dyld_chained_starts_in_segment::page_count
uint16_t page_count
Length of the page_start array.
Definition:MachO.h:1088
llvm::MachO::dyld_chained_starts_in_segment::page_size
uint16_t page_size
Page size in bytes (0x1000 or 0x4000)
Definition:MachO.h:1084
llvm::MachO::dyld_chained_starts_in_segment::pointer_format
uint16_t pointer_format
DYLD_CHAINED_PTR*.
Definition:MachO.h:1085
llvm::MachO::dyld_chained_starts_in_segment::size
uint32_t size
Size of this, including chain_starts entries.
Definition:MachO.h:1083
llvm::MachO::dyld_info_command
Definition:MachO.h:874
llvm::MachO::dyld_info_command::cmdsize
uint32_t cmdsize
Definition:MachO.h:876
llvm::MachO::dyld_info_command::lazy_bind_off
uint32_t lazy_bind_off
Definition:MachO.h:883
llvm::MachO::dyld_info_command::export_off
uint32_t export_off
Definition:MachO.h:885
llvm::MachO::dyld_info_command::rebase_size
uint32_t rebase_size
Definition:MachO.h:878
llvm::MachO::dyld_info_command::export_size
uint32_t export_size
Definition:MachO.h:886
llvm::MachO::dyld_info_command::bind_size
uint32_t bind_size
Definition:MachO.h:880
llvm::MachO::dyld_info_command::lazy_bind_size
uint32_t lazy_bind_size
Definition:MachO.h:884
llvm::MachO::dyld_info_command::weak_bind_size
uint32_t weak_bind_size
Definition:MachO.h:882
llvm::MachO::dyld_info_command::bind_off
uint32_t bind_off
Definition:MachO.h:879
llvm::MachO::dyld_info_command::rebase_off
uint32_t rebase_off
Definition:MachO.h:877
llvm::MachO::dyld_info_command::weak_bind_off
uint32_t weak_bind_off
Definition:MachO.h:881
llvm::MachO::dylib_command
Definition:MachO.h:620
llvm::MachO::dylib_module_64
Definition:MachO.h:749
llvm::MachO::dylib_module
Definition:MachO.h:733
llvm::MachO::dylib_reference
Definition:MachO.h:765
llvm::MachO::dylib_table_of_contents
Definition:MachO.h:728
llvm::MachO::dylinker_command
Definition:MachO.h:659
llvm::MachO::dysymtab_command
Definition:MachO.h:705
llvm::MachO::dysymtab_command::ntoc
uint32_t ntoc
Definition:MachO.h:715
llvm::MachO::dysymtab_command::tocoff
uint32_t tocoff
Definition:MachO.h:714
llvm::MachO::dysymtab_command::indirectsymoff
uint32_t indirectsymoff
Definition:MachO.h:720
llvm::MachO::dysymtab_command::cmdsize
uint32_t cmdsize
Definition:MachO.h:707
llvm::MachO::dysymtab_command::modtaboff
uint32_t modtaboff
Definition:MachO.h:716
llvm::MachO::dysymtab_command::extrefsymoff
uint32_t extrefsymoff
Definition:MachO.h:718
llvm::MachO::dysymtab_command::iextdefsym
uint32_t iextdefsym
Definition:MachO.h:710
llvm::MachO::dysymtab_command::nlocrel
uint32_t nlocrel
Definition:MachO.h:725
llvm::MachO::dysymtab_command::ilocalsym
uint32_t ilocalsym
Definition:MachO.h:708
llvm::MachO::dysymtab_command::nextrel
uint32_t nextrel
Definition:MachO.h:723
llvm::MachO::dysymtab_command::nlocalsym
uint32_t nlocalsym
Definition:MachO.h:709
llvm::MachO::dysymtab_command::nextdefsym
uint32_t nextdefsym
Definition:MachO.h:711
llvm::MachO::dysymtab_command::nindirectsyms
uint32_t nindirectsyms
Definition:MachO.h:721
llvm::MachO::dysymtab_command::nmodtab
uint32_t nmodtab
Definition:MachO.h:717
llvm::MachO::dysymtab_command::extreloff
uint32_t extreloff
Definition:MachO.h:722
llvm::MachO::dysymtab_command::nextrefsyms
uint32_t nextrefsyms
Definition:MachO.h:719
llvm::MachO::dysymtab_command::locreloff
uint32_t locreloff
Definition:MachO.h:724
llvm::MachO::dysymtab_command::nundefsym
uint32_t nundefsym
Definition:MachO.h:713
llvm::MachO::dysymtab_command::iundefsym
uint32_t iundefsym
Definition:MachO.h:712
llvm::MachO::dysymtab_command::cmd
uint32_t cmd
Definition:MachO.h:706
llvm::MachO::encryption_info_command_64
Definition:MachO.h:828
llvm::MachO::encryption_info_command
Definition:MachO.h:820
llvm::MachO::entry_point_command
Definition:MachO.h:948
llvm::MachO::fileset_entry_command
Definition:MachO.h:899
llvm::MachO::linkedit_data_command
Definition:MachO.h:801
llvm::MachO::linkedit_data_command::dataoff
uint32_t dataoff
Definition:MachO.h:804
llvm::MachO::linkedit_data_command::cmd
uint32_t cmd
Definition:MachO.h:802
llvm::MachO::linkedit_data_command::datasize
uint32_t datasize
Definition:MachO.h:805
llvm::MachO::linkedit_data_command::cmdsize
uint32_t cmdsize
Definition:MachO.h:803
llvm::MachO::linker_option_command
Definition:MachO.h:889
llvm::MachO::linker_option_command::cmd
uint32_t cmd
Definition:MachO.h:890
llvm::MachO::load_command
Definition:MachO.h:533
llvm::MachO::load_command::cmd
uint32_t cmd
Definition:MachO.h:534
llvm::MachO::mach_header_64
Definition:MachO.h:522
llvm::MachO::mach_header_64::cputype
uint32_t cputype
Definition:MachO.h:524
llvm::MachO::mach_header_64::flags
uint32_t flags
Definition:MachO.h:529
llvm::MachO::mach_header
Definition:MachO.h:512
llvm::MachO::mach_header::cpusubtype
uint32_t cpusubtype
Definition:MachO.h:515
llvm::MachO::mach_header::sizeofcmds
uint32_t sizeofcmds
Definition:MachO.h:518
llvm::MachO::mach_header::filetype
uint32_t filetype
Definition:MachO.h:516
llvm::MachO::mach_header::ncmds
uint32_t ncmds
Definition:MachO.h:517
llvm::MachO::mach_header::cputype
uint32_t cputype
Definition:MachO.h:514
llvm::MachO::nlist_64
Definition:MachO.h:1017
llvm::MachO::nlist_64::n_desc
uint16_t n_desc
Definition:MachO.h:1021
llvm::MachO::nlist_64::n_strx
uint32_t n_strx
Definition:MachO.h:1018
llvm::MachO::nlist_64::n_value
uint64_t n_value
Definition:MachO.h:1022
llvm::MachO::nlist_64::n_type
uint8_t n_type
Definition:MachO.h:1019
llvm::MachO::nlist_64::n_sect
uint8_t n_sect
Definition:MachO.h:1020
llvm::MachO::nlist_base
Definition:MachO.h:1002
llvm::MachO::nlist
Definition:MachO.h:1009
llvm::MachO::nlist::n_strx
uint32_t n_strx
Definition:MachO.h:1010
llvm::MachO::nlist::n_sect
uint8_t n_sect
Definition:MachO.h:1012
llvm::MachO::nlist::n_desc
int16_t n_desc
Definition:MachO.h:1013
llvm::MachO::nlist::n_type
uint8_t n_type
Definition:MachO.h:1011
llvm::MachO::nlist::n_value
uint32_t n_value
Definition:MachO.h:1014
llvm::MachO::note_command
Definition:MachO.h:845
llvm::MachO::note_command::offset
uint64_t offset
Definition:MachO.h:849
llvm::MachO::note_command::size
uint64_t size
Definition:MachO.h:850
llvm::MachO::ppc_thread_state32_t
Definition:MachO.h:2057
llvm::MachO::relocation_info
Definition:MachO.h:979
llvm::MachO::routines_command_64
Definition:MachO.h:683
llvm::MachO::routines_command
Definition:MachO.h:670
llvm::MachO::rpath_command
Definition:MachO.h:795
llvm::MachO::section_64
Definition:MachO.h:580
llvm::MachO::section_64::addr
uint64_t addr
Definition:MachO.h:583
llvm::MachO::section_64::offset
uint32_t offset
Definition:MachO.h:585
llvm::MachO::section_64::align
uint32_t align
Definition:MachO.h:586
llvm::MachO::section_64::reloff
uint32_t reloff
Definition:MachO.h:587
llvm::MachO::section_64::size
uint64_t size
Definition:MachO.h:584
llvm::MachO::section_64::nreloc
uint32_t nreloc
Definition:MachO.h:588
llvm::MachO::section_64::flags
uint32_t flags
Definition:MachO.h:589
llvm::MachO::section
Definition:MachO.h:566
llvm::MachO::section::size
uint32_t size
Definition:MachO.h:570
llvm::MachO::section::reloff
uint32_t reloff
Definition:MachO.h:573
llvm::MachO::section::align
uint32_t align
Definition:MachO.h:572
llvm::MachO::section::flags
uint32_t flags
Definition:MachO.h:575
llvm::MachO::section::offset
uint32_t offset
Definition:MachO.h:571
llvm::MachO::section::nreloc
uint32_t nreloc
Definition:MachO.h:574
llvm::MachO::segment_command_64
Definition:MachO.h:552
llvm::MachO::segment_command_64::vmaddr
uint64_t vmaddr
Definition:MachO.h:556
llvm::MachO::segment_command_64::segname
char segname[16]
Definition:MachO.h:555
llvm::MachO::segment_command
Definition:MachO.h:538
llvm::MachO::source_version_command
Definition:MachO.h:814
llvm::MachO::sub_client_command
Definition:MachO.h:632
llvm::MachO::sub_client_command::client
uint32_t client
Definition:MachO.h:635
llvm::MachO::sub_framework_command
Definition:MachO.h:626
llvm::MachO::sub_framework_command::umbrella
uint32_t umbrella
Definition:MachO.h:629
llvm::MachO::sub_library_command
Definition:MachO.h:644
llvm::MachO::sub_library_command::sub_library
uint32_t sub_library
Definition:MachO.h:647
llvm::MachO::sub_umbrella_command
Definition:MachO.h:638
llvm::MachO::sub_umbrella_command::sub_umbrella
uint32_t sub_umbrella
Definition:MachO.h:641
llvm::MachO::symtab_command
Definition:MachO.h:696
llvm::MachO::symtab_command::strsize
uint32_t strsize
Definition:MachO.h:702
llvm::MachO::symtab_command::nsyms
uint32_t nsyms
Definition:MachO.h:700
llvm::MachO::symtab_command::cmdsize
uint32_t cmdsize
Definition:MachO.h:698
llvm::MachO::symtab_command::cmd
uint32_t cmd
Definition:MachO.h:697
llvm::MachO::symtab_command::stroff
uint32_t stroff
Definition:MachO.h:701
llvm::MachO::symtab_command::symoff
uint32_t symoff
Definition:MachO.h:699
llvm::MachO::thread_command
Definition:MachO.h:665
llvm::MachO::twolevel_hint
Definition:MachO.h:778
llvm::MachO::twolevel_hints_command
Definition:MachO.h:770
llvm::MachO::twolevel_hints_command::nhints
uint32_t nhints
Definition:MachO.h:774
llvm::MachO::twolevel_hints_command::offset
uint32_t offset
Definition:MachO.h:773
llvm::MachO::uuid_command
Definition:MachO.h:789
llvm::MachO::version_min_command
Definition:MachO.h:837
llvm::MachO::x86_exception_state64_t
Definition:MachO.h:1825
llvm::MachO::x86_exception_state_t
Definition:MachO.h:1919
llvm::MachO::x86_float_state_t
Definition:MachO.h:1912
llvm::MachO::x86_thread_state32_t
Definition:MachO.h:1706
llvm::MachO::x86_thread_state64_t
Definition:MachO.h:1725
llvm::MachO::x86_thread_state_t
Definition:MachO.h:1904
llvm::OptimizedStructLayoutField
A field in a structure.
Definition:OptimizedStructLayout.h:45
llvm::SectionName
Definition:DWARFSection.h:21
llvm::object::ChainedFixupTarget
ChainedFixupTarget holds all the information about an external symbol necessary to bind this binary t...
Definition:MachO.h:275
llvm::object::ChainedFixupsSegment
Definition:MachO.h:299
llvm::object::ChainedFixupsSegment::SegIdx
uint32_t SegIdx
Definition:MachO.h:306
llvm::object::ChainedFixupsSegment::Header
MachO::dyld_chained_starts_in_segment Header
Definition:MachO.h:308
llvm::object::ChainedFixupsSegment::PageStarts
std::vector< uint16_t > PageStarts
Definition:MachO.h:309
llvm::object::MachOObjectFile::LoadCommandInfo
Definition:MachO.h:408
llvm::object::MachOObjectFile::LoadCommandInfo::Ptr
const char * Ptr
Definition:MachO.h:409
llvm::object::MachOObjectFile::LoadCommandInfo::C
MachO::load_command C
Definition:MachO.h:410
llvm::object::DataRefImpl
Definition:SymbolicFile.h:35
llvm::object::DataRefImpl::b
uint32_t b
Definition:SymbolicFile.h:39
llvm::object::DataRefImpl::p
uintptr_t p
Definition:SymbolicFile.h:41
llvm::object::DataRefImpl::d
struct llvm::object::DataRefImpl::@370 d
llvm::object::DataRefImpl::a
uint32_t a
Definition:SymbolicFile.h:39

Generated on Fri Jul 18 2025 11:45:57 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp