48 #include <system_error>
51 using namespace object;
64 std::string StringMsg =
"truncated or malformed object (" + Msg.
str() +
")";
65 return make_error<GenericBinaryError>(std::move(StringMsg),
73 if (P < O.getData().begin() || P +
sizeof(
T) > O.getData().end())
77 memcpy(&Cmd, P,
sizeof(
T));
86 if (P < O.getData().begin() || P +
sizeof(
T) > O.getData().end())
90 memcpy(&Cmd, P,
sizeof(
T));
99 uintptr_t CommandAddr =
reinterpret_cast<uintptr_t
>(L.Ptr);
101 bool Is64 = O.is64Bit();
107 uintptr_t SectionAddr = CommandAddr + SegmentLoadSize + Sec *
SectionSize;
108 return reinterpret_cast<const char*
>(SectionAddr);
112 return O.getData().substr(Offset, 1).data();
117 const char *
P =
reinterpret_cast<const char *
>(DRI.p);
118 return getStruct<MachO::nlist_base>(O,
P);
130 return O.getHeader().cputype;
145 if (O.isLittleEndian())
157 if (O.isLittleEndian())
169 if (O.isLittleEndian())
187 if (
auto CmdOrErr = getStructOrErr<MachO::load_command>(Obj, Ptr)) {
188 if (CmdOrErr->cmdsize < 8)
190 " with size less than 8 bytes");
191 return MachOObjectFile::LoadCommandInfo({
Ptr, *CmdOrErr});
193 return CmdOrErr.takeError();
201 return malformedError(
"load command 0 extends past the end all load "
202 "commands in the file");
208 const MachOObjectFile::LoadCommandInfo &
L) {
212 Obj.getData().data() + HeaderSize + Obj.getHeader().sizeofcmds)
214 " extends past the end all load commands in the file");
218 template <
typename T>
221 if (
sizeof(
T) > Obj.getData().size()) {
222 Err =
malformedError(
"the mach header extends past the end of the "
226 if (
auto HeaderOrErr = getStructOrErr<T>(Obj,
getPtr(Obj, 0)))
227 Header = *HeaderOrErr;
229 Err = HeaderOrErr.takeError();
245 for (
auto it=Elements.begin() ; it != Elements.end(); ++it) {
247 if ((Offset >=
E.Offset && Offset <
E.Offset +
E.Size) ||
248 (Offset + Size >
E.Offset && Offset + Size <
E.Offset +
E.Size) ||
249 (Offset <= E.Offset && Offset + Size >=
E.Offset +
E.Size))
251 " with a size of " +
Twine(Size) +
", overlaps " +
252 E.Name +
" at offset " +
Twine(
E.Offset) +
" with "
253 "a size of " +
Twine(
E.Size));
256 if (nt != Elements.end()) {
258 if (Offset + Size <=
N.Offset) {
271 template <
typename Segment,
typename Section>
273 const MachOObjectFile &Obj,
const MachOObjectFile::LoadCommandInfo &
Load,
275 uint32_t LoadCommandIndex,
const char *CmdName, uint64_t SizeOfHeaders,
276 std::list<MachOElement> &Elements) {
277 const unsigned SegmentLoadSize =
sizeof(Segment);
278 if (Load.C.cmdsize < SegmentLoadSize)
280 " " + CmdName +
" cmdsize too small");
281 if (
auto SegOrErr = getStructOrErr<Segment>(Obj, Load.Ptr)) {
282 Segment S = SegOrErr.get();
284 uint64_t FileSize = Obj.getData().size();
286 S.nsects * SectionSize > Load.C.cmdsize - SegmentLoadSize)
288 " inconsistent cmdsize in " + CmdName +
289 " for the number of sections");
290 for (
unsigned J = 0; J < S.nsects; ++J) {
293 Section s = getStruct<Section>(Obj, Sec);
300 CmdName +
" command " +
Twine(LoadCommandIndex) +
301 " extends past the end of the file");
306 s.offset < SizeOfHeaders && s.size != 0)
308 CmdName +
" command " +
Twine(LoadCommandIndex) +
309 " not past the headers of the file");
310 uint64_t BigSize = s.offset;
317 return malformedError(
"offset field plus size field of section " +
318 Twine(J) +
" in " + CmdName +
" command " +
319 Twine(LoadCommandIndex) +
320 " extends past the end of the file");
327 Twine(J) +
" in " + CmdName +
" command " +
328 Twine(LoadCommandIndex) +
329 " greater than the segment");
334 CmdName +
" command " +
Twine(LoadCommandIndex) +
335 " less than the segment's vmaddr");
338 uint64_t BigEnd = S.vmaddr;
340 if (S.vmsize != 0 && s.size != 0 && BigSize > BigEnd)
342 " in " + CmdName +
" command " +
343 Twine(LoadCommandIndex) +
344 " greater than than "
345 "the segment's vmaddr plus vmsize");
353 if (s.reloff > FileSize)
355 CmdName +
" command " +
Twine(LoadCommandIndex) +
356 " extends past the end of the file");
360 if (BigSize > FileSize)
361 return malformedError(
"reloff field plus nreloc field times sizeof("
362 "struct relocation_info) of section " +
363 Twine(J) +
" in " + CmdName +
" command " +
364 Twine(LoadCommandIndex) +
365 " extends past the end of the file");
369 "section relocation entries"))
372 if (S.fileoff > FileSize)
374 " fileoff field in " + CmdName +
375 " extends past the end of the file");
376 uint64_t BigSize = S.fileoff;
377 BigSize += S.filesize;
378 if (BigSize > FileSize)
380 " fileoff field plus filesize field in " +
381 CmdName +
" extends past the end of the file");
382 if (S.vmsize != 0 && S.filesize > S.vmsize)
384 " filesize field in " + CmdName +
385 " greater than vmsize field");
388 return SegOrErr.takeError();
394 const MachOObjectFile::LoadCommandInfo &
Load,
396 const char **SymtabLoadCmd,
397 std::list<MachOElement> &Elements) {
400 " LC_SYMTAB cmdsize too small");
401 if (*SymtabLoadCmd !=
nullptr)
404 getStruct<MachO::symtab_command>(Obj, Load.Ptr);
407 " has incorrect cmdsize");
408 uint64_t FileSize = Obj.getData().size();
409 if (Symtab.
symoff > FileSize)
411 Twine(LoadCommandIndex) +
" extends past the end "
413 uint64_t SymtabSize = Symtab.
nsyms;
414 const char *struct_nlist_name;
417 struct_nlist_name =
"struct nlist_64";
420 struct_nlist_name =
"struct nlist";
422 uint64_t BigSize = SymtabSize;
424 if (BigSize > FileSize)
425 return malformedError(
"symoff field plus nsyms field times sizeof(" +
426 Twine(struct_nlist_name) +
") of LC_SYMTAB command " +
427 Twine(LoadCommandIndex) +
" extends past the end "
432 if (Symtab.
stroff > FileSize)
434 Twine(LoadCommandIndex) +
" extends past the end "
438 if (BigSize > FileSize)
439 return malformedError(
"stroff field plus strsize field of LC_SYMTAB "
440 "command " +
Twine(LoadCommandIndex) +
" extends "
441 "past the end of the file");
443 Symtab.
strsize,
"string table"))
445 *SymtabLoadCmd = Load.Ptr;
450 const MachOObjectFile::LoadCommandInfo &
Load,
452 const char **DysymtabLoadCmd,
453 std::list<MachOElement> &Elements) {
456 " LC_DYSYMTAB cmdsize too small");
457 if (*DysymtabLoadCmd !=
nullptr)
460 getStruct<MachO::dysymtab_command>(Obj, Load.Ptr);
463 " has incorrect cmdsize");
464 uint64_t FileSize = Obj.getData().size();
465 if (Dysymtab.
tocoff > FileSize)
467 Twine(LoadCommandIndex) +
" extends past the end of "
469 uint64_t BigSize = Dysymtab.
ntoc;
471 BigSize += Dysymtab.
tocoff;
472 if (BigSize > FileSize)
473 return malformedError(
"tocoff field plus ntoc field times sizeof(struct "
474 "dylib_table_of_contents) of LC_DYSYMTAB command " +
475 Twine(LoadCommandIndex) +
" extends past the end of "
478 Dysymtab.
ntoc *
sizeof(
struct
480 "table of contents"))
484 Twine(LoadCommandIndex) +
" extends past the end of "
487 const char *struct_dylib_module_name;
488 uint64_t sizeof_modtab;
491 struct_dylib_module_name =
"struct dylib_module_64";
494 struct_dylib_module_name =
"struct dylib_module";
496 BigSize *= sizeof_modtab;
498 if (BigSize > FileSize)
499 return malformedError(
"modtaboff field plus nmodtab field times sizeof(" +
500 Twine(struct_dylib_module_name) +
") of LC_DYSYMTAB "
501 "command " +
Twine(LoadCommandIndex) +
" extends "
502 "past the end of the file");
504 Dysymtab.
nmodtab * sizeof_modtab,
508 return malformedError(
"extrefsymoff field of LC_DYSYMTAB command " +
509 Twine(LoadCommandIndex) +
" extends past the end of "
514 if (BigSize > FileSize)
515 return malformedError(
"extrefsymoff field plus nextrefsyms field times "
516 "sizeof(struct dylib_reference) of LC_DYSYMTAB "
517 "command " +
Twine(LoadCommandIndex) +
" extends "
518 "past the end of the file");
525 return malformedError(
"indirectsymoff field of LC_DYSYMTAB command " +
526 Twine(LoadCommandIndex) +
" extends past the end of "
531 if (BigSize > FileSize)
532 return malformedError(
"indirectsymoff field plus nindirectsyms field times "
533 "sizeof(uint32_t) of LC_DYSYMTAB command " +
534 Twine(LoadCommandIndex) +
" extends past the end of "
543 Twine(LoadCommandIndex) +
" extends past the end of "
548 if (BigSize > FileSize)
549 return malformedError(
"extreloff field plus nextrel field times sizeof"
550 "(struct relocation_info) of LC_DYSYMTAB command " +
551 Twine(LoadCommandIndex) +
" extends past the end of "
556 "external relocation table"))
560 Twine(LoadCommandIndex) +
" extends past the end of "
565 if (BigSize > FileSize)
566 return malformedError(
"locreloff field plus nlocrel field times sizeof"
567 "(struct relocation_info) of LC_DYSYMTAB command " +
568 Twine(LoadCommandIndex) +
" extends past the end of "
573 "local relocation table"))
575 *DysymtabLoadCmd = Load.Ptr;
580 const MachOObjectFile::LoadCommandInfo &
Load,
582 const char **LoadCmd,
const char *CmdName,
583 std::list<MachOElement> &Elements,
584 const char *ElementName) {
587 CmdName +
" cmdsize too small");
588 if (*LoadCmd !=
nullptr)
591 getStruct<MachO::linkedit_data_command>(Obj, Load.Ptr);
594 Twine(LoadCommandIndex) +
" has incorrect cmdsize");
595 uint64_t FileSize = Obj.getData().size();
596 if (LinkData.
dataoff > FileSize)
598 Twine(LoadCommandIndex) +
" extends past the end of "
600 uint64_t BigSize = LinkData.
dataoff;
602 if (BigSize > FileSize)
604 Twine(CmdName) +
" command " +
605 Twine(LoadCommandIndex) +
" extends past the end of "
615 const MachOObjectFile::LoadCommandInfo &
Load,
617 const char **LoadCmd,
const char *CmdName,
618 std::list<MachOElement> &Elements) {
621 CmdName +
" cmdsize too small");
622 if (*LoadCmd !=
nullptr)
623 return malformedError(
"more than one LC_DYLD_INFO and or LC_DYLD_INFO_ONLY "
626 getStruct<MachO::dyld_info_command>(Obj, Load.Ptr);
629 Twine(LoadCommandIndex) +
" has incorrect cmdsize");
630 uint64_t FileSize = Obj.getData().size();
633 " command " +
Twine(LoadCommandIndex) +
" extends "
634 "past the end of the file");
637 if (BigSize > FileSize)
638 return malformedError(
"rebase_off field plus rebase_size field of " +
639 Twine(CmdName) +
" command " +
640 Twine(LoadCommandIndex) +
" extends past the end of "
648 " command " +
Twine(LoadCommandIndex) +
" extends "
649 "past the end of the file");
652 if (BigSize > FileSize)
654 Twine(CmdName) +
" command " +
655 Twine(LoadCommandIndex) +
" extends past the end of "
663 " command " +
Twine(LoadCommandIndex) +
" extends "
664 "past the end of the file");
667 if (BigSize > FileSize)
668 return malformedError(
"weak_bind_off field plus weak_bind_size field of " +
669 Twine(CmdName) +
" command " +
670 Twine(LoadCommandIndex) +
" extends past the end of "
674 "dyld weak bind info"))
678 " command " +
Twine(LoadCommandIndex) +
" extends "
679 "past the end of the file");
682 if (BigSize > FileSize)
683 return malformedError(
"lazy_bind_off field plus lazy_bind_size field of " +
684 Twine(CmdName) +
" command " +
685 Twine(LoadCommandIndex) +
" extends past the end of "
689 "dyld lazy bind info"))
693 " command " +
Twine(LoadCommandIndex) +
" extends "
694 "past the end of the file");
697 if (BigSize > FileSize)
698 return malformedError(
"export_off field plus export_size field of " +
699 Twine(CmdName) +
" command " +
700 Twine(LoadCommandIndex) +
" extends past the end of "
711 const MachOObjectFile::LoadCommandInfo &
Load,
712 uint32_t LoadCommandIndex,
const char *CmdName) {
715 CmdName +
" cmdsize too small");
719 CmdName +
" name.offset field too small, not past "
720 "the end of the dylib_command struct");
723 CmdName +
" name.offset field extends past the end "
724 "of the load command");
728 const char *
P = (
const char *)Load.Ptr;
734 CmdName +
" library name extends past the end of the "
740 const MachOObjectFile::LoadCommandInfo &
Load,
742 const char **LoadCmd) {
746 if (*LoadCmd !=
nullptr)
750 return malformedError(
"LC_ID_DYLIB load command in non-dynamic library "
757 const MachOObjectFile::LoadCommandInfo &
Load,
758 uint32_t LoadCommandIndex,
const char *CmdName) {
761 CmdName +
" cmdsize too small");
765 CmdName +
" name.offset field too small, not past "
766 "the end of the dylinker_command struct");
769 CmdName +
" name.offset field extends past the end "
770 "of the load command");
774 const char *
P = (
const char *)Load.Ptr;
780 CmdName +
" dyld name extends past the end of the "
786 const MachOObjectFile::LoadCommandInfo &
Load,
788 const char **LoadCmd,
const char *CmdName) {
791 CmdName +
" has incorrect cmdsize");
792 if (*LoadCmd !=
nullptr)
794 "LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_TVOS or "
795 "LC_VERSION_MIN_WATCHOS command");
801 const MachOObjectFile::LoadCommandInfo &
Load,
803 std::list<MachOElement> &Elements) {
806 " LC_NOTE has incorrect cmdsize");
808 uint64_t FileSize = Obj.getData().
size();
811 Twine(LoadCommandIndex) +
" extends "
812 "past the end of the file");
813 uint64_t BigSize = Nt.
offset;
815 if (BigSize > FileSize)
816 return malformedError(
"size field plus offset field of LC_NOTE command " +
817 Twine(LoadCommandIndex) +
" extends past the end of "
827 const MachOObjectFile::LoadCommandInfo &
Load,
831 getStruct<MachO::build_version_command>(Obj, Load.Ptr);
832 if (Load.C.cmdsize !=
836 " LC_BUILD_VERSION_COMMAND has incorrect cmdsize");
840 for (
unsigned i = 0; i < BVC.
ntools; ++i)
847 const MachOObjectFile::LoadCommandInfo &
Load,
851 " LC_RPATH cmdsize too small");
855 " LC_RPATH path.offset field too small, not past "
856 "the end of the rpath_command struct");
859 " LC_RPATH path.offset field extends past the end "
860 "of the load command");
864 const char *
P = (
const char *)Load.Ptr;
870 " LC_RPATH library name extends past the end of the "
876 const MachOObjectFile::LoadCommandInfo &
Load,
878 uint64_t cryptoff, uint64_t cryptsize,
879 const char **LoadCmd,
const char *CmdName) {
880 if (*LoadCmd !=
nullptr)
882 "LC_ENCRYPTION_INFO_64 command");
883 uint64_t FileSize = Obj.getData().size();
884 if (cryptoff > FileSize)
886 " command " +
Twine(LoadCommandIndex) +
" extends "
887 "past the end of the file");
888 uint64_t BigSize = cryptoff;
889 BigSize += cryptsize;
890 if (BigSize > FileSize)
892 Twine(CmdName) +
" command " +
893 Twine(LoadCommandIndex) +
" extends past the end of "
900 const MachOObjectFile::LoadCommandInfo &
Load,
904 " LC_LINKER_OPTION cmdsize too small");
906 getStruct<MachO::linker_option_command>(Obj, Load.Ptr);
908 const char *
string = (
const char *)Load.Ptr +
913 while (*
string ==
'\0' && left > 0) {
927 " LC_LINKER_OPTION string count " +
Twine(L.
count) +
928 " does not match number of strings");
933 const MachOObjectFile::LoadCommandInfo &
Load,
934 uint32_t LoadCommandIndex,
const char *CmdName,
935 size_t SizeOfCmd,
const char *CmdStructName,
936 uint32_t PathOffset,
const char *PathFieldName) {
937 if (PathOffset < SizeOfCmd)
939 CmdName +
" " + PathFieldName +
".offset field too "
940 "small, not past the end of the " + CmdStructName);
941 if (PathOffset >= Load.C.cmdsize)
943 CmdName +
" " + PathFieldName +
".offset field "
944 "extends past the end of the load command");
948 const char *
P = (
const char *)Load.Ptr;
949 for (i = PathOffset; i < Load.C.cmdsize; i++)
952 if (i >= Load.C.cmdsize)
954 CmdName +
" " + PathFieldName +
" name extends past "
955 "the end of the load command");
960 const MachOObjectFile::LoadCommandInfo &
Load,
962 const char *CmdName) {
965 CmdName +
" cmdsize too small");
967 getStruct<MachO::thread_command>(Obj, Load.Ptr);
972 while (state < end) {
975 "flavor in " + CmdName +
" extends past end of "
978 memcpy(&flavor, state,
sizeof(
uint32_t));
985 " count in " + CmdName +
" extends past end of "
988 memcpy(&count, state,
sizeof(
uint32_t));
997 " count not x86_THREAD_STATE32_COUNT for "
998 "flavor number " +
Twine(nflavor) +
" which is "
999 "a x86_THREAD_STATE32 flavor in " + CmdName +
1003 " x86_THREAD_STATE32 extends past end of "
1004 "command in " + CmdName +
" command");
1008 " unknown flavor (" +
Twine(flavor) +
") for "
1009 "flavor number " +
Twine(nflavor) +
" in " +
1010 CmdName +
" command");
1016 " count not x86_THREAD_STATE64_COUNT for "
1017 "flavor number " +
Twine(nflavor) +
" which is "
1018 "a x86_THREAD_STATE64 flavor in " + CmdName +
1022 " x86_THREAD_STATE64 extends past end of "
1023 "command in " + CmdName +
" command");
1027 " unknown flavor (" +
Twine(flavor) +
") for "
1028 "flavor number " +
Twine(nflavor) +
" in " +
1029 CmdName +
" command");
1035 " count not ARM_THREAD_STATE_COUNT for "
1036 "flavor number " +
Twine(nflavor) +
" which is "
1037 "a ARM_THREAD_STATE flavor in " + CmdName +
1041 " ARM_THREAD_STATE extends past end of "
1042 "command in " + CmdName +
" command");
1046 " unknown flavor (" +
Twine(flavor) +
") for "
1047 "flavor number " +
Twine(nflavor) +
" in " +
1048 CmdName +
" command");
1054 " count not ARM_THREAD_STATE64_COUNT for "
1055 "flavor number " +
Twine(nflavor) +
" which is "
1056 "a ARM_THREAD_STATE64 flavor in " + CmdName +
1060 " ARM_THREAD_STATE64 extends past end of "
1061 "command in " + CmdName +
" command");
1065 " unknown flavor (" +
Twine(flavor) +
") for "
1066 "flavor number " +
Twine(nflavor) +
" in " +
1067 CmdName +
" command");
1073 " count not PPC_THREAD_STATE_COUNT for "
1074 "flavor number " +
Twine(nflavor) +
" which is "
1075 "a PPC_THREAD_STATE flavor in " + CmdName +
1079 " PPC_THREAD_STATE extends past end of "
1080 "command in " + CmdName +
" command");
1084 " unknown flavor (" +
Twine(flavor) +
") for "
1085 "flavor number " +
Twine(nflavor) +
" in " +
1086 CmdName +
" command");
1090 "command " +
Twine(LoadCommandIndex) +
" for " +
1091 CmdName +
" command can't be checked");
1099 const MachOObjectFile::LoadCommandInfo
1102 const char **LoadCmd,
1103 std::list<MachOElement> &Elements) {
1106 " LC_TWOLEVEL_HINTS has incorrect cmdsize");
1107 if (*LoadCmd !=
nullptr)
1108 return malformedError(
"more than one LC_TWOLEVEL_HINTS command");
1110 getStruct<MachO::twolevel_hints_command>(Obj, Load.Ptr);
1111 uint64_t FileSize = Obj.getData().size();
1112 if (Hints.
offset > FileSize)
1113 return malformedError(
"offset field of LC_TWOLEVEL_HINTS command " +
1114 Twine(LoadCommandIndex) +
" extends past the end of "
1116 uint64_t BigSize = Hints.
nhints;
1119 if (BigSize > FileSize)
1120 return malformedError(
"offset field plus nhints times sizeof(struct "
1121 "twolevel_hint) field of LC_TWOLEVEL_HINTS command " +
1122 Twine(LoadCommandIndex) +
" extends past the end of "
1128 *LoadCmd = Load.Ptr;
1136 if (cmd == MachO::LC_SYMSEG ||
1137 cmd == MachO::LC_LOADFVMLIB ||
1138 cmd == MachO::LC_IDFVMLIB ||
1139 cmd == MachO::LC_IDENT ||
1140 cmd == MachO::LC_FVMFILE ||
1141 cmd == MachO::LC_PREPAGE ||
1142 cmd == MachO::LC_PREBOUND_DYLIB ||
1143 cmd == MachO::LC_TWOLEVEL_HINTS ||
1144 cmd == MachO::LC_PREBIND_CKSUM)
1151 bool Is64Bits,
uint32_t UniversalCputype,
1154 std::unique_ptr<MachOObjectFile> Obj(
1156 Is64Bits, Err, UniversalCputype,
1159 return std::move(Err);
1160 return std::move(Obj);
1163 MachOObjectFile::MachOObjectFile(
MemoryBufferRef Object,
bool IsLittleEndian,
1164 bool Is64bits,
Error &Err,
1167 :
ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object) {
1169 uint64_t SizeOfHeaders;
1184 Err =
malformedError(
"load commands extend past the end of the file");
1187 if (UniversalCputype != 0 && cputype != UniversalCputype) {
1189 Twine(UniversalIndex) +
"'s cputype does not match "
1190 "object file's mach header");
1193 std::list<MachOElement> Elements;
1194 Elements.push_back({0, SizeOfHeaders,
"Mach-O headers"});
1197 LoadCommandInfo
Load;
1198 if (LoadCommandCount != 0) {
1202 Err = LoadOrErr.takeError();
1207 const char *DyldIdLoadCmd =
nullptr;
1208 const char *FuncStartsLoadCmd =
nullptr;
1209 const char *SplitInfoLoadCmd =
nullptr;
1210 const char *CodeSignDrsLoadCmd =
nullptr;
1211 const char *CodeSignLoadCmd =
nullptr;
1212 const char *VersLoadCmd =
nullptr;
1213 const char *SourceLoadCmd =
nullptr;
1214 const char *EntryPointLoadCmd =
nullptr;
1215 const char *EncryptLoadCmd =
nullptr;
1216 const char *RoutinesLoadCmd =
nullptr;
1217 const char *UnixThreadLoadCmd =
nullptr;
1218 const char *TwoLevelHintsLoadCmd =
nullptr;
1219 for (
unsigned I = 0;
I < LoadCommandCount; ++
I) {
1221 if (Load.C.cmdsize % 8 != 0) {
1226 Load.C.cmd != MachO::LC_THREAD || Load.C.cmdsize % 4) {
1233 if (Load.C.cmdsize % 4 != 0) {
1240 if (Load.C.cmd == MachO::LC_SYMTAB) {
1243 }
else if (Load.C.cmd == MachO::LC_DYSYMTAB) {
1247 }
else if (Load.C.cmd == MachO::LC_DATA_IN_CODE) {
1249 "LC_DATA_IN_CODE", Elements,
1250 "data in code info")))
1252 }
else if (Load.C.cmd == MachO::LC_LINKER_OPTIMIZATION_HINT) {
1254 "LC_LINKER_OPTIMIZATION_HINT",
1255 Elements,
"linker optimization "
1258 }
else if (Load.C.cmd == MachO::LC_FUNCTION_STARTS) {
1260 "LC_FUNCTION_STARTS", Elements,
1261 "function starts data")))
1263 }
else if (Load.C.cmd == MachO::LC_SEGMENT_SPLIT_INFO) {
1265 "LC_SEGMENT_SPLIT_INFO", Elements,
1266 "split info data")))
1268 }
else if (Load.C.cmd == MachO::LC_DYLIB_CODE_SIGN_DRS) {
1270 "LC_DYLIB_CODE_SIGN_DRS", Elements,
1271 "code signing RDs data")))
1273 }
else if (Load.C.cmd == MachO::LC_CODE_SIGNATURE) {
1275 "LC_CODE_SIGNATURE", Elements,
1276 "code signature data")))
1278 }
else if (Load.C.cmd == MachO::LC_DYLD_INFO) {
1280 "LC_DYLD_INFO", Elements)))
1282 }
else if (Load.C.cmd == MachO::LC_DYLD_INFO_ONLY) {
1284 "LC_DYLD_INFO_ONLY", Elements)))
1286 }
else if (Load.C.cmd == MachO::LC_UUID) {
1296 UuidLoadCmd = Load.Ptr;
1297 }
else if (Load.C.cmd == MachO::LC_SEGMENT_64) {
1300 *
this, Load, Sections, HasPageZeroSegment,
I,
1301 "LC_SEGMENT_64", SizeOfHeaders, Elements)))
1303 }
else if (Load.C.cmd == MachO::LC_SEGMENT) {
1306 *
this, Load, Sections, HasPageZeroSegment,
I,
1307 "LC_SEGMENT", SizeOfHeaders, Elements)))
1309 }
else if (Load.C.cmd == MachO::LC_ID_DYLIB) {
1312 }
else if (Load.C.cmd == MachO::LC_LOAD_DYLIB) {
1316 }
else if (Load.C.cmd == MachO::LC_LOAD_WEAK_DYLIB) {
1320 }
else if (Load.C.cmd == MachO::LC_LAZY_LOAD_DYLIB) {
1324 }
else if (Load.C.cmd == MachO::LC_REEXPORT_DYLIB) {
1328 }
else if (Load.C.cmd == MachO::LC_LOAD_UPWARD_DYLIB) {
1332 }
else if (Load.C.cmd == MachO::LC_ID_DYLINKER) {
1335 }
else if (Load.C.cmd == MachO::LC_LOAD_DYLINKER) {
1338 }
else if (Load.C.cmd == MachO::LC_DYLD_ENVIRONMENT) {
1341 }
else if (Load.C.cmd == MachO::LC_VERSION_MIN_MACOSX) {
1343 "LC_VERSION_MIN_MACOSX")))
1345 }
else if (Load.C.cmd == MachO::LC_VERSION_MIN_IPHONEOS) {
1347 "LC_VERSION_MIN_IPHONEOS")))
1349 }
else if (Load.C.cmd == MachO::LC_VERSION_MIN_TVOS) {
1351 "LC_VERSION_MIN_TVOS")))
1353 }
else if (Load.C.cmd == MachO::LC_VERSION_MIN_WATCHOS) {
1355 "LC_VERSION_MIN_WATCHOS")))
1357 }
else if (Load.C.cmd == MachO::LC_NOTE) {
1360 }
else if (Load.C.cmd == MachO::LC_BUILD_VERSION) {
1363 }
else if (Load.C.cmd == MachO::LC_RPATH) {
1366 }
else if (Load.C.cmd == MachO::LC_SOURCE_VERSION) {
1369 " has incorrect cmdsize");
1372 if (SourceLoadCmd) {
1376 SourceLoadCmd = Load.Ptr;
1377 }
else if (Load.C.cmd == MachO::LC_MAIN) {
1380 " has incorrect cmdsize");
1383 if (EntryPointLoadCmd) {
1387 EntryPointLoadCmd = Load.Ptr;
1388 }
else if (Load.C.cmd == MachO::LC_ENCRYPTION_INFO) {
1391 " has incorrect cmdsize");
1395 getStruct<MachO::encryption_info_command>(*
this, Load.Ptr);
1397 &EncryptLoadCmd,
"LC_ENCRYPTION_INFO")))
1399 }
else if (Load.C.cmd == MachO::LC_ENCRYPTION_INFO_64) {
1402 " has incorrect cmdsize");
1406 getStruct<MachO::encryption_info_command_64>(*
this, Load.Ptr);
1408 &EncryptLoadCmd,
"LC_ENCRYPTION_INFO_64")))
1410 }
else if (Load.C.cmd == MachO::LC_LINKER_OPTION) {
1413 }
else if (Load.C.cmd == MachO::LC_SUB_FRAMEWORK) {
1416 " LC_SUB_FRAMEWORK cmdsize too small");
1420 getStruct<MachO::sub_framework_command>(*
this, Load.Ptr);
1423 "sub_framework_command", S.
umbrella,
1426 }
else if (Load.C.cmd == MachO::LC_SUB_UMBRELLA) {
1429 " LC_SUB_UMBRELLA cmdsize too small");
1433 getStruct<MachO::sub_umbrella_command>(*
this, Load.Ptr);
1439 }
else if (Load.C.cmd == MachO::LC_SUB_LIBRARY) {
1442 " LC_SUB_LIBRARY cmdsize too small");
1446 getStruct<MachO::sub_library_command>(*
this, Load.Ptr);
1452 }
else if (Load.C.cmd == MachO::LC_SUB_CLIENT) {
1455 " LC_SUB_CLIENT cmdsize too small");
1459 getStruct<MachO::sub_client_command>(*
this, Load.Ptr);
1462 "sub_client_command", S.
client,
"client")))
1464 }
else if (Load.C.cmd == MachO::LC_ROUTINES) {
1467 " has incorrect cmdsize");
1470 if (RoutinesLoadCmd) {
1471 Err =
malformedError(
"more than one LC_ROUTINES and or LC_ROUTINES_64 "
1475 RoutinesLoadCmd = Load.Ptr;
1476 }
else if (Load.C.cmd == MachO::LC_ROUTINES_64) {
1479 " has incorrect cmdsize");
1482 if (RoutinesLoadCmd) {
1483 Err =
malformedError(
"more than one LC_ROUTINES_64 and or LC_ROUTINES "
1487 RoutinesLoadCmd = Load.Ptr;
1488 }
else if (Load.C.cmd == MachO::LC_UNIXTHREAD) {
1491 if (UnixThreadLoadCmd) {
1495 UnixThreadLoadCmd = Load.Ptr;
1496 }
else if (Load.C.cmd == MachO::LC_THREAD) {
1500 }
else if (Load.C.cmd == MachO::LC_TWOLEVEL_HINTS) {
1502 &TwoLevelHintsLoadCmd, Elements)))
1506 Twine(Load.C.cmd) +
" is obsolete and not "
1513 if (
I < LoadCommandCount - 1) {
1517 Err = LoadOrErr.takeError();
1522 if (!SymtabLoadCmd) {
1523 if (DysymtabLoadCmd) {
1524 Err =
malformedError(
"contains LC_DYSYMTAB load command without a "
1525 "LC_SYMTAB load command");
1528 }
else if (DysymtabLoadCmd) {
1530 getStruct<MachO::symtab_command>(*
this, SymtabLoadCmd);
1532 getStruct<MachO::dysymtab_command>(*
this, DysymtabLoadCmd);
1533 if (Dysymtab.nlocalsym != 0 && Dysymtab.ilocalsym > Symtab.
nsyms) {
1535 "extends past the end of the symbol table");
1538 uint64_t BigSize = Dysymtab.ilocalsym;
1539 BigSize += Dysymtab.nlocalsym;
1540 if (Dysymtab.nlocalsym != 0 && BigSize > Symtab.
nsyms) {
1541 Err =
malformedError(
"ilocalsym plus nlocalsym in LC_DYSYMTAB load "
1542 "command extends past the end of the symbol table");
1545 if (Dysymtab.nextdefsym != 0 && Dysymtab.ilocalsym > Symtab.
nsyms) {
1547 "extends past the end of the symbol table");
1550 BigSize = Dysymtab.iextdefsym;
1551 BigSize += Dysymtab.nextdefsym;
1552 if (Dysymtab.nextdefsym != 0 && BigSize > Symtab.
nsyms) {
1553 Err =
malformedError(
"iextdefsym plus nextdefsym in LC_DYSYMTAB "
1554 "load command extends past the end of the symbol "
1558 if (Dysymtab.nundefsym != 0 && Dysymtab.iundefsym > Symtab.
nsyms) {
1560 "extends past the end of the symbol table");
1563 BigSize = Dysymtab.iundefsym;
1564 BigSize += Dysymtab.nundefsym;
1565 if (Dysymtab.nundefsym != 0 && BigSize > Symtab.
nsyms) {
1566 Err =
malformedError(
"iundefsym plus nundefsym in LC_DYSYMTAB load "
1567 " command extends past the end of the symbol table");
1573 DyldIdLoadCmd ==
nullptr) {
1574 Err =
malformedError(
"no LC_ID_DYLIB load command in dynamic library "
1578 assert(LoadCommands.
size() == LoadCommandCount);
1596 uint64_t NValue = 0;
1619 if (NSect == 0 || NSect > Sections.
size())
1621 " for symbol at index " +
Twine(SymbolIndex));
1623 if ((NType & MachO::N_STAB) == 0 &&
1627 "the end of string table, for N_INDR symbol at "
1628 "index " +
Twine(SymbolIndex));
1631 (((NType & MachO::N_TYPE) ==
MachO::N_UNDF && NValue == 0) ||
1634 if (LibraryOrdinal != 0 &&
1637 LibraryOrdinal - 1 >= Libraries.
size() ) {
1639 " for symbol at index " +
Twine(SymbolIndex));
1644 " past the end of string table, for symbol at "
1645 "index " +
Twine(SymbolIndex));
1652 unsigned SymbolTableEntrySize =
is64Bit() ?
1655 Symb.
p += SymbolTableEntrySize;
1661 const char *Start = &StringTable.
data()[Entry.
n_strx];
1693 if (NValue >= StringTable.
size())
1695 const char *Start = &StringTable.
data()[NValue];
1697 return std::error_code();
1700 uint64_t MachOObjectFile::getSymbolValueImpl(
DataRefImpl Sym)
const {
1724 uint8_t n_type = Entry.
n_type;
1738 if (Sec->isData() || Sec->isBSS())
1748 uint8_t MachOType = Entry.
n_type;
1749 uint16_t MachOFlags = Entry.
n_desc;
1787 uint8_t index = Entry.
n_sect;
1792 DRI.
d.
a = index - 1;
1793 if (DRI.
d.
a >= Sections.
size()){
1814 return std::error_code();
1837 SectOffset = Sect.
offset;
1838 SectSize = Sect.
size;
1842 SectOffset = Sect.
offset;
1843 SectSize = Sect.
size;
1849 if (SectOffset > FileSize)
1851 if (FileSize - SectOffset < SectSize)
1852 return FileSize - SectOffset;
1872 return std::error_code();
1885 return uint64_t(1) <<
Align;
1926 return (SegmentName ==
"__LLVM" && SectName ==
"__bitcode");
1976 "Only implemented for MH_OBJECT && MH_KEXT_BUNDLE");
1993 unsigned SymbolTableEntrySize =
is64Bit() ?
1996 uint64_t
Offset = S.
symoff + SymbolIdx * SymbolTableEntrySize;
1998 Sym.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Offset));
2017 unsigned Arch = this->
getArch();
2021 static const char *
const Table[] = {
2022 "GENERIC_RELOC_VANILLA",
2023 "GENERIC_RELOC_PAIR",
2024 "GENERIC_RELOC_SECTDIFF",
2025 "GENERIC_RELOC_PB_LA_PTR",
2026 "GENERIC_RELOC_LOCAL_SECTDIFF",
2027 "GENERIC_RELOC_TLV" };
2036 static const char *
const Table[] = {
2037 "X86_64_RELOC_UNSIGNED",
2038 "X86_64_RELOC_SIGNED",
2039 "X86_64_RELOC_BRANCH",
2040 "X86_64_RELOC_GOT_LOAD",
2042 "X86_64_RELOC_SUBTRACTOR",
2043 "X86_64_RELOC_SIGNED_1",
2044 "X86_64_RELOC_SIGNED_2",
2045 "X86_64_RELOC_SIGNED_4",
2046 "X86_64_RELOC_TLV" };
2055 static const char *
const Table[] = {
2056 "ARM_RELOC_VANILLA",
2058 "ARM_RELOC_SECTDIFF",
2059 "ARM_RELOC_LOCAL_SECTDIFF",
2060 "ARM_RELOC_PB_LA_PTR",
2062 "ARM_THUMB_RELOC_BR22",
2063 "ARM_THUMB_32BIT_BRANCH",
2065 "ARM_RELOC_HALF_SECTDIFF" };
2074 static const char *
const Table[] = {
2075 "ARM64_RELOC_UNSIGNED",
"ARM64_RELOC_SUBTRACTOR",
2076 "ARM64_RELOC_BRANCH26",
"ARM64_RELOC_PAGE21",
2077 "ARM64_RELOC_PAGEOFF12",
"ARM64_RELOC_GOT_LOAD_PAGE21",
2078 "ARM64_RELOC_GOT_LOAD_PAGEOFF12",
"ARM64_RELOC_POINTER_TO_GOT",
2079 "ARM64_RELOC_TLVP_LOAD_PAGE21",
"ARM64_RELOC_TLVP_LOAD_PAGEOFF12",
2080 "ARM64_RELOC_ADDEND"
2090 static const char *
const Table[] = {
2091 "PPC_RELOC_VANILLA",
2099 "PPC_RELOC_SECTDIFF",
2100 "PPC_RELOC_PB_LA_PTR",
2101 "PPC_RELOC_HI16_SECTDIFF",
2102 "PPC_RELOC_LO16_SECTDIFF",
2103 "PPC_RELOC_HA16_SECTDIFF",
2105 "PPC_RELOC_LO14_SECTDIFF",
2106 "PPC_RELOC_LOCAL_SECTDIFF" };
2158 size_t a, b, c, d, Idx;
2160 isFramework =
false;
2164 a = Name.
rfind(
'/');
2165 if (a == Name.
npos || a == 0)
2170 Idx = Foo.
rfind(
'_');
2171 if (Idx != Foo.
npos && Foo.
size() >= 2) {
2173 Foo = Foo.
slice(0, Idx);
2177 b = Name.
rfind(
'/', a);
2183 DotFramework = Name.
slice(Idx + Foo.
size(),
2184 Idx + Foo.
size() +
sizeof(
".framework/")-1);
2185 if (F == Foo && DotFramework ==
".framework/") {
2193 c = Name.
rfind(
'/', b);
2194 if (c == Name.
npos || c == 0)
2199 d = Name.
rfind(
'/', c);
2205 DotFramework = Name.
slice(Idx + Foo.
size(),
2206 Idx + Foo.
size() +
sizeof(
".framework/")-1);
2207 if (F == Foo && DotFramework ==
".framework/") {
2214 a = Name.
rfind(
'.');
2215 if (a == Name.
npos || a == 0)
2218 if (Dylib !=
".dylib")
2223 Dot = Name.
slice(a-2, a-1);
2228 b = Name.
rfind(
'/', a);
2234 Idx = Name.
find(
'_', b);
2235 if (Idx != Name.
npos && Idx != b) {
2236 Lib = Name.
slice(b, Idx);
2237 Suffix = Name.
slice(Idx, a);
2240 Lib = Name.
slice(b, a);
2243 if (Lib.
size() >= 3) {
2254 b = Name.
rfind(
'/', a);
2256 Lib = Name.
slice(0, a);
2258 Lib = Name.
slice(b+1, a);
2260 if (Lib.
size() >= 3) {
2275 if (Index >= Libraries.
size())
2280 if (LibrariesShortNames.
size() == 0) {
2281 for (
unsigned i = 0; i < Libraries.
size(); i++) {
2283 getStruct<MachO::dylib_command>(*
this, Libraries[i]);
2286 const char *
P = (
const char *)(Libraries[i]) + D.
dylib.
name;
2293 if (shortName.
empty())
2296 LibrariesShortNames.
push_back(shortName);
2300 Res = LibrariesShortNames[Index];
2301 return std::error_code();
2305 return Libraries.
size();
2311 Sec.
d.
a = Rel->getRawDataRefImpl().d.a;
2318 if (!SymtabLoadCmd || Symtab.
nsyms == 0)
2327 if (!SymtabLoadCmd || Symtab.
nsyms == 0)
2330 unsigned SymbolTableEntrySize =
is64Bit() ?
2334 Symtab.
nsyms * SymbolTableEntrySize;
2335 DRI.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Offset));
2341 if (!SymtabLoadCmd || Index >= Symtab.
nsyms)
2343 unsigned SymbolTableEntrySize =
2346 DRI.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Symtab.
symoff));
2347 DRI.
p += Index * SymbolTableEntrySize;
2355 unsigned SymbolTableEntrySize =
2358 DRIstart.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Symtab.
symoff));
2359 uint64_t Index = (Symb.
p - DRIstart.
p) / SymbolTableEntrySize;
2370 DRI.
d.
a = Sections.
size();
2383 return "Mach-O 32-bit i386";
2385 return "Mach-O arm";
2387 return "Mach-O 32-bit ppc";
2389 return "Mach-O 32-bit unknown";
2395 return "Mach-O 64-bit x86-64";
2397 return "Mach-O arm64";
2399 return "Mach-O 64-bit ppc64";
2401 return "Mach-O 64-bit unknown";
2425 const char **McpuDefault,
2426 const char **ArchFlag) {
2428 *McpuDefault =
nullptr;
2430 *ArchFlag =
nullptr;
2438 return Triple(
"i386-apple-darwin");
2446 *ArchFlag =
"x86_64";
2447 return Triple(
"x86_64-apple-darwin");
2450 *ArchFlag =
"x86_64h";
2451 return Triple(
"x86_64h-apple-darwin");
2459 *ArchFlag =
"armv4t";
2460 return Triple(
"armv4t-apple-darwin");
2463 *ArchFlag =
"armv5e";
2464 return Triple(
"armv5e-apple-darwin");
2467 *ArchFlag =
"xscale";
2468 return Triple(
"xscale-apple-darwin");
2471 *ArchFlag =
"armv6";
2472 return Triple(
"armv6-apple-darwin");
2475 *McpuDefault =
"cortex-m0";
2477 *ArchFlag =
"armv6m";
2478 return Triple(
"armv6m-apple-darwin");
2481 *ArchFlag =
"armv7";
2482 return Triple(
"armv7-apple-darwin");
2485 *McpuDefault =
"cortex-m4";
2487 *ArchFlag =
"armv7em";
2488 return Triple(
"thumbv7em-apple-darwin");
2491 *McpuDefault =
"cortex-a7";
2493 *ArchFlag =
"armv7k";
2494 return Triple(
"armv7k-apple-darwin");
2497 *McpuDefault =
"cortex-m3";
2499 *ArchFlag =
"armv7m";
2500 return Triple(
"thumbv7m-apple-darwin");
2503 *McpuDefault =
"cortex-a7";
2505 *ArchFlag =
"armv7s";
2506 return Triple(
"armv7s-apple-darwin");
2514 *McpuDefault =
"cyclone";
2516 *ArchFlag =
"arm64";
2517 return Triple(
"arm64-apple-darwin");
2526 return Triple(
"ppc-apple-darwin");
2534 *ArchFlag =
"ppc64";
2535 return Triple(
"ppc64-apple-darwin");
2551 .
Case(
"x86_64",
true)
2552 .
Case(
"x86_64h",
true)
2553 .
Case(
"armv4t",
true)
2555 .
Case(
"armv5e",
true)
2556 .
Case(
"armv6",
true)
2557 .
Case(
"armv6m",
true)
2558 .
Case(
"armv7",
true)
2559 .
Case(
"armv7em",
true)
2560 .
Case(
"armv7k",
true)
2561 .
Case(
"armv7m",
true)
2562 .
Case(
"armv7s",
true)
2563 .
Case(
"arm64",
true)
2565 .
Case(
"ppc64",
true)
2591 if (!DataInCodeLoadCmd)
2595 DRI.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, DicLC.
dataoff));
2601 if (!DataInCodeLoadCmd)
2606 DRI.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Offset));
2612 void ExportEntry::moveToFirst() {
2614 pushDownUntilBottom();
2617 void ExportEntry::moveToEnd() {
2624 if (Done || Other.Done)
2625 return (Done == Other.Done);
2627 if (Stack.
size() != Other.Stack.
size())
2630 if (!CumulativeString.
equals(Other.CumulativeString))
2633 for (
unsigned i=0; i < Stack.
size(); ++i) {
2634 if (Stack[i].Start != Other.Stack[i].Start)
2644 if (Ptr > Trie.
end()) {
2652 return CumulativeString;
2656 return Stack.
back().Flags;
2660 return Stack.
back().Address;
2664 return Stack.
back().Other;
2675 return Stack.
back().Start - Trie.
begin();
2678 ExportEntry::NodeState::NodeState(
const uint8_t *Ptr)
2679 : Start(Ptr), Current(Ptr) {}
2681 void ExportEntry::pushNode(uint64_t offset) {
2682 const uint8_t *Ptr = Trie.
begin() + offset;
2683 NodeState State(Ptr);
2684 uint64_t ExportInfoSize =
readULEB128(State.Current);
2685 State.IsExportNode = (ExportInfoSize != 0);
2686 const uint8_t* Children = State.Current + ExportInfoSize;
2687 if (State.IsExportNode) {
2692 State.ImportName =
reinterpret_cast<const char*
>(State.Current);
2699 State.ChildCount = *Children;
2700 State.Current = Children + 1;
2701 State.NextChildIndex = 0;
2702 State.ParentStringLength = CumulativeString.
size();
2706 void ExportEntry::pushDownUntilBottom() {
2707 while (Stack.
back().NextChildIndex < Stack.
back().ChildCount) {
2708 NodeState &Top = Stack.
back();
2709 CumulativeString.
resize(Top.ParentStringLength);
2710 for (;*Top.Current != 0; Top.Current++) {
2711 char C = *Top.Current;
2715 uint64_t childNodeIndex =
readULEB128(Top.Current);
2716 Top.NextChildIndex += 1;
2717 pushNode(childNodeIndex);
2719 if (!Stack.
back().IsExportNode) {
2741 if (Stack.
empty() || !Stack.
back().IsExportNode) {
2748 while (!Stack.
empty()) {
2749 NodeState &Top = Stack.
back();
2750 if (Top.NextChildIndex < Top.ChildCount) {
2751 pushDownUntilBottom();
2755 if (Top.IsExportNode) {
2757 CumulativeString.
resize(Top.ParentStringLength);
2772 Start.moveToFirst();
2786 : E(E), O(O), Opcodes(Bytes), Ptr(Bytes.
begin()),
2787 PointerSize(is64Bit ? 8 : 4) {}
2789 void MachORebaseEntry::moveToFirst() {
2790 Ptr = Opcodes.
begin();
2794 void MachORebaseEntry::moveToEnd() {
2795 Ptr = Opcodes.
end();
2796 RemainingLoopCount = 0;
2804 if (RemainingLoopCount) {
2805 --RemainingLoopCount;
2811 if (Ptr == Opcodes.
end()) {
2818 const uint8_t *OpcodeStart =
Ptr;
2819 uint8_t Byte = *Ptr++;
2823 const char *
error =
nullptr;
2834 *E =
malformedError(
"for REBASE_OPCODE_SET_TYPE_IMM bad bind type: " +
2842 dbgs() <<
"REBASE_OPCODE_SET_TYPE_IMM: "
2843 <<
"RebaseType=" << (
int)
RebaseType <<
"\n");
2846 SegmentIndex = ImmValue;
2849 *E =
malformedError(
"for REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
2850 Twine(error) +
" for opcode at: 0x" +
2858 *E =
malformedError(
"for REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
2859 Twine(error) +
" for opcode at: 0x" +
2866 dbgs() <<
"REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: "
2867 <<
"SegmentIndex=" << SegmentIndex <<
", "
2875 Twine(error) +
" for opcode at: 0x" +
2884 Twine(error) +
" for opcode at: 0x" +
2890 dbgs() <<
"REBASE_OPCODE_ADD_ADDR_ULEB: "
2891 <<
format(
"SegmentOffset=0x%06X",
2899 Twine(error) +
" for opcode at: 0x" +
2909 " (after adding immediate times the pointer size) " +
2910 Twine(error) +
" for opcode at: 0x" +
2916 dbgs() <<
"REBASE_OPCODE_ADD_ADDR_IMM_SCALED: "
2917 <<
format(
"SegmentOffset=0x%06X",
2925 Twine(error) +
" for opcode at: 0x" +
2930 AdvanceAmount = PointerSize;
2934 RemainingLoopCount = ImmValue - 1;
2936 RemainingLoopCount = 0;
2941 +
Twine(error) +
" for opcode at: 0x" +
2948 dbgs() <<
"REBASE_OPCODE_DO_REBASE_IMM_TIMES: "
2950 <<
", AdvanceAmount=" << AdvanceAmount
2951 <<
", RemainingLoopCount=" << RemainingLoopCount
2959 Twine(error) +
" for opcode at: 0x" +
2964 AdvanceAmount = PointerSize;
2969 Twine(error) +
" for opcode at: 0x" +
2975 RemainingLoopCount = Count - 1;
2977 RemainingLoopCount = 0;
2982 +
Twine(error) +
" for opcode at: 0x" +
2989 dbgs() <<
"REBASE_OPCODE_DO_REBASE_ULEB_TIMES: "
2991 <<
", AdvanceAmount=" << AdvanceAmount
2992 <<
", RemainingLoopCount=" << RemainingLoopCount
2999 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB " +
3000 Twine(error) +
" for opcode at: 0x" +
3007 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB " +
3008 Twine(error) +
" for opcode at: 0x" +
3013 AdvanceAmount = Skip + PointerSize;
3015 RemainingLoopCount = 0;
3020 +
Twine(error) +
" for opcode at: 0x" +
3027 dbgs() <<
"REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB: "
3029 <<
", AdvanceAmount=" << AdvanceAmount
3030 <<
", RemainingLoopCount=" << RemainingLoopCount
3037 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_"
3038 "ULEB " +
Twine(error) +
" for opcode at: 0x" +
3045 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_"
3046 "ULEB " +
Twine(error) +
" for opcode at: 0x" +
3052 RemainingLoopCount = Count - 1;
3054 RemainingLoopCount = 0;
3057 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_"
3058 "ULEB " +
Twine(error) +
" for opcode at: 0x" +
3063 AdvanceAmount = Skip + PointerSize;
3068 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_"
3069 "ULEB " +
Twine(error) +
" for opcode at: 0x" +
3076 dbgs() <<
"REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB: "
3078 <<
", AdvanceAmount=" << AdvanceAmount
3079 <<
", RemainingLoopCount=" << RemainingLoopCount
3084 utohexstr(Opcode) +
" for opcode at: 0x" +
3096 if (Ptr > Opcodes.
end())
3097 Ptr = Opcodes.
end();
3110 return "text abs32";
3112 return "text rel32";
3136 #ifdef EXPENSIVE_CHECKS
3137 assert(Opcodes == Other.Opcodes &&
"compare iterators of different files");
3139 assert(Opcodes.
data() == Other.Opcodes.
data() &&
"compare iterators of different files");
3141 return (Ptr == Other.Ptr) &&
3142 (RemainingLoopCount == Other.RemainingLoopCount) &&
3143 (Done == Other.Done);
3149 if (O->BindRebaseSectionTable ==
nullptr)
3150 O->BindRebaseSectionTable = llvm::make_unique<BindRebaseSegInfo>(O);
3152 Start.moveToFirst();
3166 : E(E), O(O), Opcodes(Bytes), Ptr(Bytes.
begin()),
3167 PointerSize(is64Bit ? 8 : 4), TableKind(BK) {}
3169 void MachOBindEntry::moveToFirst() {
3170 Ptr = Opcodes.
begin();
3174 void MachOBindEntry::moveToEnd() {
3175 Ptr = Opcodes.
end();
3176 RemainingLoopCount = 0;
3184 if (RemainingLoopCount) {
3185 --RemainingLoopCount;
3191 if (Ptr == Opcodes.
end()) {
3198 const uint8_t *OpcodeStart =
Ptr;
3199 uint8_t Byte = *Ptr++;
3202 int8_t SignExtended;
3203 const uint8_t *SymStart;
3205 const char *error =
nullptr;
3211 bool NotLastEntry =
false;
3212 for (
const uint8_t *
P = Ptr;
P < Opcodes.
end(); ++
P) {
3214 NotLastEntry =
true;
3226 *E =
malformedError(
"BIND_OPCODE_SET_DYLIB_ORDINAL_IMM not allowed in "
3227 "weak bind table for opcode at: 0x" +
3233 LibraryOrdinalSet =
true;
3235 *E =
malformedError(
"for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad "
3236 "library ordinal: " +
Twine((
int)ImmValue) +
" (max " +
3244 dbgs() <<
"BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: "
3245 <<
"Ordinal=" << Ordinal <<
"\n");
3249 *E =
malformedError(
"BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB not allowed in "
3250 "weak bind table for opcode at: 0x" +
3256 LibraryOrdinalSet =
true;
3259 Twine(error) +
" for opcode at: 0x" +
3265 *E =
malformedError(
"for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad "
3266 "library ordinal: " +
Twine((
int)Ordinal) +
" (max " +
3274 dbgs() <<
"BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: "
3275 <<
"Ordinal=" << Ordinal <<
"\n");
3279 *E =
malformedError(
"BIND_OPCODE_SET_DYLIB_SPECIAL_IMM not allowed in "
3280 "weak bind table for opcode at: 0x" +
3286 SignExtended = MachO::BIND_OPCODE_MASK | ImmValue;
3287 Ordinal = SignExtended;
3289 *E =
malformedError(
"for BIND_OPCODE_SET_DYLIB_SPECIAL_IMM unknown "
3290 "special ordinal: " +
Twine((
int)Ordinal) +
" for opcode at: "
3297 LibraryOrdinalSet =
true;
3300 dbgs() <<
"BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: "
3301 <<
"Ordinal=" << Ordinal <<
"\n");
3306 while (*Ptr && (Ptr < Opcodes.
end())) {
3309 if (Ptr == Opcodes.
end()) {
3310 *E =
malformedError(
"for BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM "
3311 "symbol name extends past opcodes for opcode at: 0x" +
3316 SymbolName =
StringRef(reinterpret_cast<const char*>(SymStart),
3321 dbgs() <<
"BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: "
3322 <<
"SymbolName=" << SymbolName <<
"\n");
3331 *E =
malformedError(
"for BIND_OPCODE_SET_TYPE_IMM bad bind type: " +
3332 Twine((
int)ImmValue) +
" for opcode at: 0x" +
3339 dbgs() <<
"BIND_OPCODE_SET_TYPE_IMM: "
3340 <<
"BindType=" << (
int)
BindType <<
"\n");
3343 Addend = readSLEB128(&error);
3346 Twine(error) +
" for opcode at: 0x" +
3353 dbgs() <<
"BIND_OPCODE_SET_ADDEND_SLEB: "
3354 <<
"Addend=" << Addend <<
"\n");
3357 SegmentIndex = ImmValue;
3360 *E =
malformedError(
"for BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
3361 Twine(error) +
" for opcode at: 0x" +
3368 *E =
malformedError(
"for BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
3369 Twine(error) +
" for opcode at: 0x" +
3376 dbgs() <<
"BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: "
3377 <<
"SegmentIndex=" << SegmentIndex <<
", "
3385 Twine(error) +
" for opcode at: 0x" +
3393 Twine(error) +
" for opcode at: 0x" +
3399 dbgs() <<
"BIND_OPCODE_ADD_ADDR_ULEB: "
3400 <<
format(
"SegmentOffset=0x%06X",
3404 AdvanceAmount = PointerSize;
3405 RemainingLoopCount = 0;
3409 " for opcode at: 0x" +
utohexstr(OpcodeStart - Opcodes.
begin()));
3415 "BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for opcode at: 0x" +
3420 if (!LibraryOrdinalSet && TableKind !=
Kind::Weak) {
3422 "BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode at: 0x" +
3428 dbgs() <<
"BIND_OPCODE_DO_BIND: "
3429 <<
format(
"SegmentOffset=0x%06X",
3434 *E =
malformedError(
"BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB not allowed in "
3435 "lazy bind table for opcode at: 0x" +
3443 Twine(error) +
" for opcode at: 0x" +
3449 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB missing "
3450 "preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for opcode "
3455 if (!LibraryOrdinalSet && TableKind !=
Kind::Weak) {
3456 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB missing "
3457 "preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode at: 0x" +
3462 AdvanceAmount =
readULEB128(&error) + PointerSize;
3465 Twine(error) +
" for opcode at: 0x" +
3474 AdvanceAmount,
false);
3476 *E =
malformedError(
"for BIND_OPCODE_ADD_ADDR_ULEB (after adding "
3477 "ULEB) " +
Twine(error) +
" for opcode at: 0x" +
3482 RemainingLoopCount = 0;
3485 dbgs() <<
"BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: "
3487 <<
", AdvanceAmount=" << AdvanceAmount
3488 <<
", RemainingLoopCount=" << RemainingLoopCount
3493 *E =
malformedError(
"BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED not "
3494 "allowed in lazy bind table for opcode at: 0x" +
3501 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " +
3502 Twine(error) +
" for opcode at: 0x" +
3508 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED "
3509 "missing preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for "
3514 if (!LibraryOrdinalSet && TableKind !=
Kind::Weak) {
3515 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED "
3516 "missing preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode "
3521 AdvanceAmount = ImmValue * PointerSize + PointerSize;
3522 RemainingLoopCount = 0;
3524 AdvanceAmount,
false);
3526 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED "
3527 " (after adding immediate times the pointer size) " +
3528 Twine(error) +
" for opcode at: 0x" +
3535 <<
"BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: "
3540 *E =
malformedError(
"BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB not "
3541 "allowed in lazy bind table for opcode at: 0x" +
3548 RemainingLoopCount = Count - 1;
3550 RemainingLoopCount = 0;
3552 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
3553 " (count value) " +
Twine(error) +
" for opcode at"
3559 AdvanceAmount = Skip + PointerSize;
3561 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
3562 " (skip value) " +
Twine(error) +
" for opcode at"
3569 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
3570 +
Twine(error) +
" for opcode at: 0x" +
3576 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
3577 "missing preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for "
3582 if (!LibraryOrdinalSet && TableKind !=
Kind::Weak) {
3583 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
3584 "missing preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode "
3592 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB "
3593 +
Twine(error) +
" for opcode at: 0x" +
3600 dbgs() <<
"BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: "
3602 <<
", AdvanceAmount=" << AdvanceAmount
3603 <<
", RemainingLoopCount=" << RemainingLoopCount
3608 utohexstr(Opcode) +
" for opcode at: 0x" +
3620 if (Ptr > Opcodes.
end())
3621 Ptr = Opcodes.
end();
3625 int64_t MachOBindEntry::readSLEB128(
const char **error) {
3629 if (Ptr > Opcodes.
end())
3630 Ptr = Opcodes.
end();
3643 return "text abs32";
3645 return "text rel32";
3677 #ifdef EXPENSIVE_CHECKS
3678 assert(Opcodes == Other.Opcodes &&
"compare iterators of different files");
3680 assert(Opcodes.
data() == Other.Opcodes.
data() &&
"compare iterators of different files");
3682 return (Ptr == Other.Ptr) &&
3683 (RemainingLoopCount == Other.RemainingLoopCount) &&
3684 (Done == Other.Done);
3691 uint64_t CurSegAddress;
3694 Section.getName(Info.SectionName);
3695 Info.Address =
Section.getAddress();
3696 Info.Size =
Section.getSize();
3699 if (!Info.SegmentName.equals(CurSegName)) {
3701 CurSegName = Info.SegmentName;
3702 CurSegAddress = Info.Address;
3704 Info.SegmentIndex = CurSegIndex - 1;
3705 Info.OffsetInSegment = Info.Address - CurSegAddress;
3706 Info.SegmentStartAddress = CurSegAddress;
3709 MaxSegIndex = CurSegIndex;
3718 return "missing preceding *_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB";
3719 if (SegIndex >= MaxSegIndex)
3720 return "bad segIndex (too large)";
3721 for (
const SectionInfo &
SI : Sections) {
3722 if (
SI.SegmentIndex != SegIndex)
3724 if (
SI.OffsetInSegment > SegOffset)
3726 if (SegOffset > (
SI.OffsetInSegment +
SI.Size))
3728 if (endInvalid && SegOffset >= (
SI.OffsetInSegment +
SI.Size))
3732 return "bad segOffset, too large";
3741 uint8_t PointerSize,
3743 uint64_t SegOffset) {
3744 const SectionInfo &
SI = findSection(SegIndex, SegOffset);
3745 uint64_t addr = SI.SegmentStartAddress + SegOffset;
3746 if (addr >= SI.Address + SI.Size)
3747 return "bad segOffset, too large";
3750 i = (Skip + PointerSize) * (Count - 1);
3751 else if (Count == 1)
3752 i = Skip + PointerSize;
3753 if (addr + i >= SI.Address + SI.Size) {
3755 uint64_t TrailingSegOffset = (addr + i) - SI.SegmentStartAddress;
3758 return "bad count and skip, too large";
3766 for (
const SectionInfo &
SI : Sections) {
3767 if (
SI.SegmentIndex == SegIndex)
3768 return SI.SegmentName;
3775 const BindRebaseSegInfo::SectionInfo &BindRebaseSegInfo::findSection(
3776 int32_t SegIndex, uint64_t SegOffset) {
3777 for (
const SectionInfo &
SI : Sections) {
3778 if (
SI.SegmentIndex != SegIndex)
3780 if (
SI.OffsetInSegment > SegOffset)
3782 if (SegOffset >= (
SI.OffsetInSegment +
SI.Size))
3792 uint64_t SegOffset) {
3793 return findSection(SegIndex, SegOffset).SectionName;
3799 const SectionInfo &
SI = findSection(SegIndex, OffsetInSeg);
3800 return SI.SegmentStartAddress + OffsetInSeg;
3807 if (O->BindRebaseSectionTable ==
nullptr)
3808 O->BindRebaseSectionTable = llvm::make_unique<BindRebaseSegInfo>(O);
3810 Start.moveToFirst();
3835 return LoadCommands.
begin();
3840 return LoadCommands.
end();
3856 assert(Sec.
d.
a < Sections.size() &&
"Should have detected this earlier");
3857 const section_base *
Base =
3858 reinterpret_cast<const section_base *
>(Sections[Sec.
d.
a]);
3864 assert(Sec.
d.
a < Sections.size() &&
"Should have detected this earlier");
3865 const section_base *
Base =
3866 reinterpret_cast<const section_base *
>(Sections[Sec.
d.
a]);
3888 return (RE.
r_word1 >> 27) & 1;
3904 return (RE.
r_word0 >> 24) & 0xf;
3942 if (SecNum ==
MachO::R_ABS || SecNum > Sections.size())
3945 DRI.
d.
a = SecNum - 1;
3950 assert(DRI.
d.
a < Sections.size() &&
"Should have detected this earlier");
3951 return getStruct<MachO::section>(*
this, Sections[DRI.
d.
a]);
3955 assert(DRI.d.a < Sections.size() &&
"Should have detected this earlier");
3956 return getStruct<MachO::section_64>(*
this, Sections[DRI.d.a]);
3960 unsigned Index)
const {
3962 return getStruct<MachO::section>(*
this, Sec);
3966 unsigned Index)
const {
3968 return getStruct<MachO::section_64>(*
this, Sec);
3973 const char *
P =
reinterpret_cast<const char *
>(DRI.
p);
3974 return getStruct<MachO::nlist>(*
this,
P);
3979 const char *
P =
reinterpret_cast<const char *
>(DRI.
p);
3980 return getStruct<MachO::nlist_64>(*
this,
P);
3985 return getStruct<MachO::linkedit_data_command>(*
this, L.
Ptr);
3990 return getStruct<MachO::segment_command>(*
this, L.
Ptr);
3995 return getStruct<MachO::segment_command_64>(*
this, L.
Ptr);
4000 return getStruct<MachO::linker_option_command>(*
this, L.
Ptr);
4005 return getStruct<MachO::version_min_command>(*
this, L.
Ptr);
4010 return getStruct<MachO::note_command>(*
this, L.
Ptr);
4015 return getStruct<MachO::build_version_command>(*
this, L.
Ptr);
4020 return getStruct<MachO::build_tool_version>(*
this, BuildTools[index]);
4025 return getStruct<MachO::dylib_command>(*
this, L.
Ptr);
4030 return getStruct<MachO::dyld_info_command>(*
this, L.
Ptr);
4035 return getStruct<MachO::dylinker_command>(*
this, L.
Ptr);
4040 return getStruct<MachO::uuid_command>(*
this, L.
Ptr);
4045 return getStruct<MachO::rpath_command>(*
this, L.
Ptr);
4050 return getStruct<MachO::source_version_command>(*
this, L.
Ptr);
4055 return getStruct<MachO::entry_point_command>(*
this, L.
Ptr);
4060 return getStruct<MachO::encryption_info_command>(*
this, L.
Ptr);
4065 return getStruct<MachO::encryption_info_command_64>(*
this, L.
Ptr);
4070 return getStruct<MachO::sub_framework_command>(*
this, L.
Ptr);
4075 return getStruct<MachO::sub_umbrella_command>(*
this, L.
Ptr);
4080 return getStruct<MachO::sub_library_command>(*
this, L.
Ptr);
4085 return getStruct<MachO::sub_client_command>(*
this, L.
Ptr);
4090 return getStruct<MachO::routines_command>(*
this, L.
Ptr);
4095 return getStruct<MachO::routines_command_64>(*
this, L.
Ptr);
4100 return getStruct<MachO::thread_command>(*
this, L.
Ptr);
4123 return getStruct<MachO::any_relocation_info>(
4124 *
this, reinterpret_cast<const char *>(
P));
4129 const char *
P =
reinterpret_cast<const char *
>(Rel.
p);
4130 return getStruct<MachO::data_in_code_entry>(*
this,
P);
4144 unsigned Index)
const {
4146 return getStruct<uint32_t>(*
this,
getPtr(*
this, Offset));
4151 unsigned Index)
const {
4153 return getStruct<MachO::data_in_code_entry>(*
this,
getPtr(*
this, Offset));
4158 return getStruct<MachO::symtab_command>(*
this, SymtabLoadCmd);
4162 Cmd.
cmd = MachO::LC_SYMTAB;
4172 if (DysymtabLoadCmd)
4173 return getStruct<MachO::dysymtab_command>(*
this, DysymtabLoadCmd);
4177 Cmd.
cmd = MachO::LC_DYSYMTAB;
4189 Cmd.extrefsymoff = 0;
4190 Cmd.nextrefsyms = 0;
4191 Cmd.indirectsymoff = 0;
4192 Cmd.nindirectsyms = 0;
4202 if (DataInCodeLoadCmd)
4203 return getStruct<MachO::linkedit_data_command>(*
this, DataInCodeLoadCmd);
4207 Cmd.
cmd = MachO::LC_DATA_IN_CODE;
4216 if (LinkOptHintsLoadCmd)
4217 return getStruct<MachO::linkedit_data_command>(*
this, LinkOptHintsLoadCmd);
4222 Cmd.
cmd = MachO::LC_LINKER_OPTIMIZATION_HINT;
4230 if (!DyldInfoLoadCmd)
4234 getStruct<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4235 const uint8_t *Ptr =
4241 if (!DyldInfoLoadCmd)
4245 getStruct<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4246 const uint8_t *Ptr =
4247 reinterpret_cast<const uint8_t *
>(
getPtr(*
this, DyldInfo.
bind_off));
4252 if (!DyldInfoLoadCmd)
4256 getStruct<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4257 const uint8_t *Ptr =
4263 if (!DyldInfoLoadCmd)
4267 getStruct<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4268 const uint8_t *Ptr =
4274 if (!DyldInfoLoadCmd)
4278 getStruct<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4279 const uint8_t *Ptr =
4289 return makeArrayRef(reinterpret_cast<const uint8_t *>(Ptr), 16);
4308 while (uint64_t delta = extractor.
getULEB128(&offset)) {
4323 if (Magic ==
"\xFE\xED\xFA\xCE")
4325 UniversalCputype, UniversalIndex);
4326 if (Magic ==
"\xCE\xFA\xED\xFE")
4328 UniversalCputype, UniversalIndex);
4329 if (Magic ==
"\xFE\xED\xFA\xCF")
4331 UniversalCputype, UniversalIndex);
4332 if (Magic ==
"\xCF\xFA\xED\xFE")
4334 UniversalCputype, UniversalIndex);
4335 return make_error<GenericBinaryError>(
"Unrecognized MachO magic number",
4341 .Case(
"debug_str_offs",
"debug_str_offsets")
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
content_iterator< ExportEntry > export_iterator
static unsigned getScatteredRelocationLength(const MachO::any_relocation_info &RE)
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
void swapStruct(fat_header &mh)
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
iterator_range< export_iterator > exports() const
For use iterating over all exported symbols.
static unsigned int getMachOType(bool isLE, bool is64Bits)
static bool getScatteredRelocationPCRel(const MachO::any_relocation_info &RE)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static const char * getSectionPtr(const MachOObjectFile &O, MachOObjectFile::LoadCommandInfo L, unsigned Sec)
void swapByteOrder(T &Value)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
load_command_iterator end_load_commands() const
DataRefImpl getRawDataRefImpl() const
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const
relocation_iterator extrel_end() const
StringRef getStringTableData() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
StringRef getFileFormatName() const override
MachO::linkedit_data_command getLinkOptHintsLoadCommand() const
uint64_t getRelocationOffset(DataRefImpl Rel) const override
bool isSectionVirtual(DataRefImpl Sec) const override
ArrayRef< char > getSectionRawFinalSegmentName(DataRefImpl Sec) const
ArrayRef< char > getSectionRawName(DataRefImpl Sec) const
MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset, unsigned Index) const
std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const override
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
void moveRelocationNext(DataRefImpl &Rel) const override
ExportEntry encapsulates the current-state-of-the-walk used when doing a non-recursive walk of the tr...
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...
StringRef typeName() const
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
static Error checkOverlappingElement(std::list< MachOElement > &Elements, uint64_t Offset, uint64_t Size, const char *Name)
const char * RebaseEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset, bool endInvalid) const
For use with a SegIndex,SegOffset pair in MachORebaseEntry::moveNext() to validate a MachORebaseEntry...
symbol_iterator_range symbols() const
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
MachORebaseEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > opcodes, bool is64Bit)
static const char * getPtr(const MachOObjectFile &O, size_t Offset)
const char * checkCountAndSkip(uint32_t Count, uint32_t Skip, uint8_t PointerSize, int32_t SegIndex, uint64_t SegOffset)
StringRef segmentName() const
static Triple getHostArch()
uint32_t getScatteredRelocationType(const MachO::any_relocation_info &RE) const
uint8_t getRelocationLength(DataRefImpl Rel) const
This class is the base class for all object file types.
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
uint64_t getRelocationType(DataRefImpl Rel) const override
StringRef otherName() const
static StringRef parseSegmentOrSectionName(const char *P)
static uint32_t getSectionFlags(const MachOObjectFile &O, DataRefImpl Sec)
MachORebaseEntry encapsulates the current state in the decompression of rebasing opcodes.
uint64_t getSectionAlignment(DataRefImpl Sec) const override
ArrayRef< uint8_t > getDyldInfoLazyBindOpcodes() const
Error takeError()
Take ownership of the stored error.
load_command_iterator begin_load_commands() const
DataRefImpl getRawDataRefImpl() const
int32_t segmentIndex() const
static uint32_t getPlainRelocationAddress(const MachO::any_relocation_info &RE)
uint32_t getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
const char * BindEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset, bool endInvalid) const
For use with a SegIndex,SegOffset pair in MachOBindEntry::moveNext() to validate a MachOBindEntry...
bool operator==(const MachORebaseEntry &) const
bool isSectionBitcode(DataRefImpl Sec) const override
static unsigned getPlainRelocationLength(const MachOObjectFile &O, const MachO::any_relocation_info &RE)
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
uint64_t getSectionAddress(DataRefImpl Sec) const override
static Expected< MachOObjectFile::LoadCommandInfo > getNextLoadCommandInfo(const MachOObjectFile &Obj, uint32_t LoadCommandIndex, const MachOObjectFile::LoadCommandInfo &L)
basic_symbol_iterator symbol_begin() const override
bool operator==(const ExportEntry &) const
static Error checkRpathCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex)
const uint32_t ARM_THREAD_STATE_COUNT
ExportEntry(ArrayRef< uint8_t > Trie)
std::string str() const
Return the twine contents as a std::string.
bool isSectionText(DataRefImpl Sec) const override
const uint32_t x86_THREAD_STATE32_COUNT
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
MachO::segment_command_64 getSegment64LoadCommand(const LoadCommandInfo &L) const
StringRef sectionName() const
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.
StringRef getData() const
MachO::uuid_command getUuidCommand(const LoadCommandInfo &L) const
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
uint64_t segmentOffset() const
bool equals(StringRef RHS) const
Check for string equality.
uint64_t getSymbolIndex(DataRefImpl Symb) const
StringRef segmentName() const
Tagged union holding either a T or a Error.
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
static void parseHeader(const MachOObjectFile &Obj, T &Header, Error &Err)
void ReadULEB128s(uint64_t Index, SmallVectorImpl< uint64_t > &Out) const
MachOBindEntry encapsulates the current state in the decompression of binding opcodes.
MachO::linker_option_command getLinkerOptionLoadCommand(const LoadCommandInfo &L) const
static Error checkDyldInfoCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, const char *CmdName, std::list< MachOElement > &Elements)
uint32_t nodeOffset() const
MachO::encryption_info_command_64 getEncryptionInfoCommand64(const LoadCommandInfo &L) const
dice_iterator end_dices() const
LLVM_NODISCARD bool empty() const
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
MachO::dylib_command getDylibIDLoadCommand(const LoadCommandInfo &L) const
content_iterator< SectionRef > section_iterator
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
static const bool IsLittleEndianHost
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
unsigned getArch() const override
content_iterator< DiceRef > dice_iterator
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 ...
static unsigned getCPUType(const MachOObjectFile &O)
MachO::routines_command getRoutinesCommand(const LoadCommandInfo &L) const
iterator_range< rebase_iterator > rebaseTable(Error &Err)
For use iterating over all rebase table entries.
static Error checkDylibCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
static bool getPlainRelocationPCRel(const MachOObjectFile &O, const MachO::any_relocation_info &RE)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
MachO::dylinker_command getDylinkerCommand(const LoadCommandInfo &L) const
const MachO::mach_header & getHeader() const
bool getScatteredRelocationScattered(const MachO::any_relocation_info &RE) const
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
content_iterator< MachOBindEntry > bind_iterator
basic_symbol_iterator symbol_end() const override
const char * BindEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip, uint8_t PointerSize, int32_t SegIndex, uint64_t SegOffset) const
For use in MachOBindEntry::moveNext() to validate a MachOBindEntry for the BIND_OPCODE_DO_BIND_ULEB_T...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
MachO::section_64 getSection64(DataRefImpl DRI) const
relocation_iterator extrel_begin() const
MachO::entry_point_command getEntryPointCommand(const LoadCommandInfo &L) const
static bool isLoadCommandObsolete(uint32_t cmd)
StringRef symbolName() const
MachO::routines_command_64 getRoutinesCommand64(const LoadCommandInfo &L) const
static Error checkDylibIdCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd)
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
void moveSectionNext(DataRefImpl &Sec) const override
static uint8_t GET_COMM_ALIGN(uint16_t n_desc)
static Error checkDyldCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
A switch()-like statement whose cases are string literals.
bool isSectionCompressed(DataRefImpl Sec) const override
unsigned int getType() const
unsigned getSectionID(SectionRef Sec) const
const MachO::mach_header_64 & getHeader64() const
static Error checkSymtabCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **SymtabLoadCmd, std::list< MachOElement > &Elements)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
iterator_range< bind_iterator > weakBindTable(Error &Err)
For use iterating over all weak bind table entries.
S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 gigabytes).
unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const
static Constant * SegmentOffset(IRBuilder<> &IRB, unsigned Offset, unsigned AddressSpace)
ArrayRef< uint8_t > getUuid() const
iterator_range< load_command_iterator > load_commands() const
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
MachO::section getSection(DataRefImpl DRI) const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static bool is64Bit(const char *name)
MachO::segment_command getSegmentLoadCommand(const LoadCommandInfo &L) const
const uint32_t x86_THREAD_STATE64_COUNT
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)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static MachO::nlist_base getSymbolTableEntryBase(const MachOObjectFile &O, DataRefImpl DRI)
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
ArrayRef< uint8_t > getDyldInfoRebaseOpcodes() const
const char * RebaseEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip, uint8_t PointerSize, int32_t SegIndex, uint64_t SegOffset) const
For use in MachORebaseEntry::moveNext() to validate a MachORebaseEntry for the REBASE_OPCODE_DO_*_TIM...
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)
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.
MachO::source_version_command getSourceVersionCommand(const LoadCommandInfo &L) const
MachO::linkedit_data_command getDataInCodeLoadCommand() const
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
static T getStruct(const MachOObjectFile &O, const char *P)
DiceRef - This is a value type class that represents a single data in code entry in the table in a Ma...
MachO::sub_framework_command getSubFrameworkCommand(const LoadCommandInfo &L) const
bool empty() const
empty - Check if the array is empty.
bool operator==(const MachOBindEntry &) const
section_iterator_range sections() const
StringRef typeName() const
static Error malformedError(Twine Msg)
struct llvm::object::DataRefImpl::@230 d
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
MachO::thread_command getThreadCommand(const LoadCommandInfo &L) const
uint64_t getNValue(DataRefImpl Sym) const
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)
static uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc)
static Error checkThreadCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
Triple - Helper class for working with autoconf configuration names.
section_iterator getRelocationSection(DataRefImpl Rel) const
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
static const char *const Magic
std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const
Triple getArchTriple(const char **McpuDefault=nullptr) const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const
bool hasPageZeroSegment() const
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
void moveSymbolNext(DataRefImpl &Symb) const override
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...
static ErrorSuccess success()
Create a success value.
static uint64_t readULEB128(const uint8_t *&Ptr)
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
static Error checkTwoLevelHintsCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, std::list< MachOElement > &Elements)
friend class RelocationRef
unsigned getSymbolSectionID(SymbolRef Symb) const
bool isSectionData(DataRefImpl Sec) const override
static Expected< MachOObjectFile::LoadCommandInfo > getFirstLoadCommandInfo(const MachOObjectFile &Obj)
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)
static Expected< std::unique_ptr< MachOObjectFile > > createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0)
StringRef getBuffer() const
StringRef getSectionFinalSegmentName(DataRefImpl Sec) const
static Expected< T > getStructOrErr(const MachOObjectFile &O, const char *P)
std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override
MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const
MachO::build_version_command getBuildVersionLoadCommand(const LoadCommandInfo &L) const
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
ArrayRef< uint8_t > getDyldInfoExportsTrie() const
BindRebaseSegInfo(const MachOObjectFile *Obj)
uint64_t segmentOffset() const
MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
static Error checkLinkerOptCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex)
content_iterator< BasicSymbolRef > basic_symbol_iterator
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint32_t getSymbolFlags(DataRefImpl Symb) const override
MachO::sub_library_command getSubLibraryCommand(const LoadCommandInfo &L) const
SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const
A range adaptor for a pair of iterators.
MachO::build_tool_version getBuildToolVersion(unsigned index) const
MachO::encryption_info_command getEncryptionInfoCommand(const LoadCommandInfo &L) const
static unsigned getScatteredRelocationAddress(const MachO::any_relocation_info &RE)
iterator_range< bind_iterator > bindTable(Error &Err)
For use iterating over all bind table entries.
Helper for Errors used as out-parameters.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
const char * checkSegAndOffset(int32_t SegIndex, uint64_t SegOffset, bool endInvalid)
This is a value type class that represents a single symbol in the list of symbols in the object file...
static Error checkVersCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, const char *CmdName)
uint32_t getLibraryCount() const
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static Expected< std::unique_ptr< MachOObjectFile > > create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0)
llvm_unreachable("Unknown RegBank!")
MachO::note_command getNoteLoadCommand(const LoadCommandInfo &L) const
MachO::mach_header_64 Header64
static Error checkNoteCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, std::list< MachOElement > &Elements)
static std::vector< std::string > Flags
MachO::linkedit_data_command getLinkeditDataLoadCommand(const LoadCommandInfo &L) const
static Expected< MachOObjectFile::LoadCommandInfo > getLoadCommandInfo(const MachOObjectFile &Obj, const char *Ptr, uint32_t LoadCommandIndex)
MachO::version_min_command getVersionMinLoadCommand(const LoadCommandInfo &L) const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
static Error parseBuildVersionCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, SmallVectorImpl< const char * > &BuildTools, uint32_t LoadCommandIndex)
static StringRef guessLibraryShortName(StringRef Name, bool &isFramework, StringRef &Suffix)
uint64_t address(uint32_t SegIndex, uint64_t SegOffset)
static Error checkDysymtabCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **DysymtabLoadCmd, std::list< MachOElement > &Elements)
bool isSectionBSS(DataRefImpl Sec) const override
uint64_t getSectionIndex(DataRefImpl Sec) const override
StringRef segmentName(int32_t SegIndex)
MachO::symtab_command getSymtabLoadCommand() const
uint64_t getSymbolValue(DataRefImpl Symb) const
content_iterator< MachORebaseEntry > rebase_iterator
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
basic_symbol_iterator getSymbolByIndex(unsigned Index) const
bool isLittleEndian() const
dice_iterator begin_dices() const
section_iterator section_begin() const override
iterator_range< bind_iterator > lazyBindTable(Error &Err)
For use iterating over all lazy bind table entries.
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
static bool isValidArch(StringRef ArchFlag)
relocation_iterator section_rel_end(DataRefImpl Sec) const override
MachO::dysymtab_command getDysymtabLoadCommand() const
static std::string utohexstr(uint64_t X, bool LowerCase=false)
MachO::mach_header Header
MachO::rpath_command getRpathCommand(const LoadCommandInfo &L) const
MachO::data_in_code_entry getDice(DataRefImpl Rel) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachO::sub_umbrella_command getSubUmbrellaCommand(const LoadCommandInfo &L) const
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
LoadCommandList::const_iterator load_command_iterator
unsigned getSectionType(SectionRef Sec) const
int32_t segmentIndex() const
Lightweight error class with error context and mandatory checking.
const uint32_t ARM_THREAD_STATE64_COUNT
section_iterator section_end() const override
content_iterator< RelocationRef > relocation_iterator
MachOBindEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Opcodes, bool is64Bit, MachOBindEntry::Kind)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef sectionName() const
ArrayRef< uint8_t > getDyldInfoWeakBindOpcodes() const
StringRef - Represent a constant reference to a string, i.e.
S_ZEROFILL - Zero fill on demand section.
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
StringRef sectionName(int32_t SegIndex, uint64_t SegOffset)
unsigned getPlainRelocationSymbolNum(const MachO::any_relocation_info &RE) const
SectionType
These are the section type and attributes fields.
MachO::dyld_info_command getDyldInfoLoadCommand(const LoadCommandInfo &L) const
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
MachO::sub_client_command getSubClientCommand(const LoadCommandInfo &L) const
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Error checkSymbolTable() const
const uint32_t PPC_THREAD_STATE_COUNT
This is a value type class that represents a single section in the list of sections in the object fil...
static unsigned getPlainRelocationType(const MachOObjectFile &O, const MachO::any_relocation_info &RE)
uint64_t getSectionSize(DataRefImpl Sec) const override
ArrayRef< uint8_t > getDyldInfoBindOpcodes() const