46 #include <system_error> 61 return make_error<GenericBinaryError>(
"truncated or malformed object (" +
70 if (P < O.getData().begin() || P +
sizeof(
T) > O.getData().end())
74 memcpy(&Cmd, P,
sizeof(
T));
83 if (P < O.getData().begin() || P +
sizeof(
T) > O.getData().end())
87 memcpy(&Cmd, P,
sizeof(
T));
96 uintptr_t CommandAddr =
reinterpret_cast<uintptr_t
>(L.Ptr);
98 bool Is64 = O.is64Bit();
104 uintptr_t SectionAddr = CommandAddr + SegmentLoadSize + Sec *
SectionSize;
105 return reinterpret_cast<const char*
>(SectionAddr);
109 assert(Offset <= O.getData().size());
110 return O.getData().data() +
Offset;
115 const char *
P =
reinterpret_cast<const char *
>(DRI.p);
116 return getStruct<MachO::nlist_base>(
O,
P);
128 return O.getHeader().cputype;
132 return O.getHeader().cpusubtype;
147 if (O.isLittleEndian())
159 if (O.isLittleEndian())
171 if (O.isLittleEndian())
189 if (
auto CmdOrErr = getStructOrErr<MachO::load_command>(Obj, Ptr)) {
190 if (CmdOrErr->cmdsize + Ptr > Obj.getData().end())
192 " extends past end of file");
193 if (CmdOrErr->cmdsize < 8)
195 " with size less than 8 bytes");
196 return MachOObjectFile::LoadCommandInfo({Ptr, *CmdOrErr});
198 return CmdOrErr.takeError();
206 return malformedError(
"load command 0 extends past the end all load " 207 "commands in the file");
213 const MachOObjectFile::LoadCommandInfo &L) {
217 Obj.getData().data() + HeaderSize + Obj.getHeader().sizeofcmds)
219 " extends past the end all load commands in the file");
223 template <
typename T>
226 if (
sizeof(
T) > Obj.getData().size()) {
227 Err =
malformedError(
"the mach header extends past the end of the " 231 if (
auto HeaderOrErr = getStructOrErr<T>(Obj,
getPtr(Obj, 0)))
232 Header = *HeaderOrErr;
234 Err = HeaderOrErr.takeError();
250 for (
auto it=Elements.begin() ; it != Elements.end(); ++it) {
252 if ((Offset >=
E.Offset && Offset <
E.Offset +
E.Size) ||
253 (Offset + Size >
E.Offset && Offset + Size <
E.Offset +
E.Size) ||
254 (Offset <= E.Offset && Offset + Size >=
E.Offset +
E.Size))
256 " with a size of " +
Twine(Size) +
", overlaps " +
257 E.Name +
" at offset " +
Twine(
E.Offset) +
" with " 258 "a size of " +
Twine(
E.Size));
261 if (nt != Elements.end()) {
263 if (Offset + Size <=
N.Offset) {
276 template <
typename Segment,
typename Section>
278 const MachOObjectFile &Obj,
const MachOObjectFile::LoadCommandInfo &
Load,
280 uint32_t LoadCommandIndex,
const char *CmdName, uint64_t SizeOfHeaders,
281 std::list<MachOElement> &Elements) {
282 const unsigned SegmentLoadSize =
sizeof(Segment);
283 if (Load.C.cmdsize < SegmentLoadSize)
285 " " + CmdName +
" cmdsize too small");
286 if (
auto SegOrErr = getStructOrErr<Segment>(Obj, Load.Ptr)) {
287 Segment S = SegOrErr.get();
289 uint64_t FileSize = Obj.getData().size();
291 S.nsects * SectionSize > Load.C.cmdsize - SegmentLoadSize)
293 " inconsistent cmdsize in " + CmdName +
294 " for the number of sections");
295 for (
unsigned J = 0; J < S.nsects; ++J) {
298 auto SectionOrErr = getStructOrErr<Section>(Obj, Sec);
300 return SectionOrErr.takeError();
301 Section s = SectionOrErr.get();
308 CmdName +
" command " +
Twine(LoadCommandIndex) +
309 " extends past the end of the file");
314 s.offset < SizeOfHeaders && s.size != 0)
316 CmdName +
" command " +
Twine(LoadCommandIndex) +
317 " not past the headers of the file");
318 uint64_t BigSize = s.offset;
325 return malformedError(
"offset field plus size field of section " +
326 Twine(J) +
" in " + CmdName +
" command " +
327 Twine(LoadCommandIndex) +
328 " extends past the end of the file");
335 Twine(J) +
" in " + CmdName +
" command " +
336 Twine(LoadCommandIndex) +
337 " greater than the segment");
342 CmdName +
" command " +
Twine(LoadCommandIndex) +
343 " less than the segment's vmaddr");
346 uint64_t BigEnd = S.vmaddr;
348 if (S.vmsize != 0 && s.size != 0 && BigSize > BigEnd)
350 " in " + CmdName +
" command " +
351 Twine(LoadCommandIndex) +
352 " greater than than " 353 "the segment's vmaddr plus vmsize");
361 if (s.reloff > FileSize)
363 CmdName +
" command " +
Twine(LoadCommandIndex) +
364 " extends past the end of the file");
368 if (BigSize > FileSize)
369 return malformedError(
"reloff field plus nreloc field times sizeof(" 370 "struct relocation_info) of section " +
371 Twine(J) +
" in " + CmdName +
" command " +
372 Twine(LoadCommandIndex) +
373 " extends past the end of the file");
377 "section relocation entries"))
380 if (S.fileoff > FileSize)
382 " fileoff field in " + CmdName +
383 " extends past the end of the file");
384 uint64_t BigSize = S.fileoff;
385 BigSize += S.filesize;
386 if (BigSize > FileSize)
388 " fileoff field plus filesize field in " +
389 CmdName +
" extends past the end of the file");
390 if (S.vmsize != 0 && S.filesize > S.vmsize)
392 " filesize field in " + CmdName +
393 " greater than vmsize field");
396 return SegOrErr.takeError();
402 const MachOObjectFile::LoadCommandInfo &
Load,
404 const char **SymtabLoadCmd,
405 std::list<MachOElement> &Elements) {
408 " LC_SYMTAB cmdsize too small");
409 if (*SymtabLoadCmd !=
nullptr)
411 auto SymtabOrErr = getStructOrErr<MachO::symtab_command>(Obj, Load.Ptr);
413 return SymtabOrErr.takeError();
417 " has incorrect cmdsize");
418 uint64_t FileSize = Obj.getData().size();
419 if (Symtab.
symoff > FileSize)
421 Twine(LoadCommandIndex) +
" extends past the end " 423 uint64_t SymtabSize = Symtab.
nsyms;
424 const char *struct_nlist_name;
427 struct_nlist_name =
"struct nlist_64";
430 struct_nlist_name =
"struct nlist";
432 uint64_t BigSize = SymtabSize;
434 if (BigSize > FileSize)
435 return malformedError(
"symoff field plus nsyms field times sizeof(" +
436 Twine(struct_nlist_name) +
") of LC_SYMTAB command " +
437 Twine(LoadCommandIndex) +
" extends past the end " 442 if (Symtab.
stroff > FileSize)
444 Twine(LoadCommandIndex) +
" extends past the end " 448 if (BigSize > FileSize)
449 return malformedError(
"stroff field plus strsize field of LC_SYMTAB " 450 "command " +
Twine(LoadCommandIndex) +
" extends " 451 "past the end of the file");
453 Symtab.
strsize,
"string table"))
455 *SymtabLoadCmd = Load.Ptr;
460 const MachOObjectFile::LoadCommandInfo &
Load,
462 const char **DysymtabLoadCmd,
463 std::list<MachOElement> &Elements) {
466 " LC_DYSYMTAB cmdsize too small");
467 if (*DysymtabLoadCmd !=
nullptr)
470 getStructOrErr<MachO::dysymtab_command>(Obj, Load.Ptr);
472 return DysymtabOrErr.takeError();
476 " has incorrect cmdsize");
477 uint64_t FileSize = Obj.getData().size();
478 if (Dysymtab.
tocoff > FileSize)
480 Twine(LoadCommandIndex) +
" extends past the end of " 482 uint64_t BigSize = Dysymtab.
ntoc;
484 BigSize += Dysymtab.
tocoff;
485 if (BigSize > FileSize)
486 return malformedError(
"tocoff field plus ntoc field times sizeof(struct " 487 "dylib_table_of_contents) of LC_DYSYMTAB command " +
488 Twine(LoadCommandIndex) +
" extends past the end of " 491 Dysymtab.
ntoc *
sizeof(
struct 493 "table of contents"))
497 Twine(LoadCommandIndex) +
" extends past the end of " 500 const char *struct_dylib_module_name;
501 uint64_t sizeof_modtab;
504 struct_dylib_module_name =
"struct dylib_module_64";
507 struct_dylib_module_name =
"struct dylib_module";
509 BigSize *= sizeof_modtab;
511 if (BigSize > FileSize)
512 return malformedError(
"modtaboff field plus nmodtab field times sizeof(" +
513 Twine(struct_dylib_module_name) +
") of LC_DYSYMTAB " 514 "command " +
Twine(LoadCommandIndex) +
" extends " 515 "past the end of the file");
517 Dysymtab.
nmodtab * sizeof_modtab,
521 return malformedError(
"extrefsymoff field of LC_DYSYMTAB command " +
522 Twine(LoadCommandIndex) +
" extends past the end of " 527 if (BigSize > FileSize)
528 return malformedError(
"extrefsymoff field plus nextrefsyms field times " 529 "sizeof(struct dylib_reference) of LC_DYSYMTAB " 530 "command " +
Twine(LoadCommandIndex) +
" extends " 531 "past the end of the file");
538 return malformedError(
"indirectsymoff field of LC_DYSYMTAB command " +
539 Twine(LoadCommandIndex) +
" extends past the end of " 544 if (BigSize > FileSize)
545 return malformedError(
"indirectsymoff field plus nindirectsyms field times " 546 "sizeof(uint32_t) of LC_DYSYMTAB command " +
547 Twine(LoadCommandIndex) +
" extends past the end of " 556 Twine(LoadCommandIndex) +
" extends past the end of " 561 if (BigSize > FileSize)
562 return malformedError(
"extreloff field plus nextrel field times sizeof" 563 "(struct relocation_info) of LC_DYSYMTAB command " +
564 Twine(LoadCommandIndex) +
" extends past the end of " 569 "external relocation table"))
573 Twine(LoadCommandIndex) +
" extends past the end of " 578 if (BigSize > FileSize)
579 return malformedError(
"locreloff field plus nlocrel field times sizeof" 580 "(struct relocation_info) of LC_DYSYMTAB command " +
581 Twine(LoadCommandIndex) +
" extends past the end of " 586 "local relocation table"))
588 *DysymtabLoadCmd = Load.Ptr;
593 const MachOObjectFile::LoadCommandInfo &
Load,
595 const char **LoadCmd,
const char *CmdName,
596 std::list<MachOElement> &Elements,
597 const char *ElementName) {
600 CmdName +
" cmdsize too small");
601 if (*LoadCmd !=
nullptr)
603 auto LinkDataOrError =
604 getStructOrErr<MachO::linkedit_data_command>(Obj, Load.Ptr);
605 if (!LinkDataOrError)
606 return LinkDataOrError.takeError();
610 Twine(LoadCommandIndex) +
" has incorrect cmdsize");
611 uint64_t FileSize = Obj.getData().size();
612 if (LinkData.
dataoff > FileSize)
614 Twine(LoadCommandIndex) +
" extends past the end of " 616 uint64_t BigSize = LinkData.
dataoff;
618 if (BigSize > FileSize)
620 Twine(CmdName) +
" command " +
621 Twine(LoadCommandIndex) +
" extends past the end of " 631 const MachOObjectFile::LoadCommandInfo &
Load,
633 const char **LoadCmd,
const char *CmdName,
634 std::list<MachOElement> &Elements) {
637 CmdName +
" cmdsize too small");
638 if (*LoadCmd !=
nullptr)
639 return malformedError(
"more than one LC_DYLD_INFO and or LC_DYLD_INFO_ONLY " 642 getStructOrErr<MachO::dyld_info_command>(Obj, Load.Ptr);
644 return DyldInfoOrErr.takeError();
648 Twine(LoadCommandIndex) +
" has incorrect cmdsize");
649 uint64_t FileSize = Obj.getData().size();
652 " command " +
Twine(LoadCommandIndex) +
" extends " 653 "past the end of the file");
656 if (BigSize > FileSize)
657 return malformedError(
"rebase_off field plus rebase_size field of " +
658 Twine(CmdName) +
" command " +
659 Twine(LoadCommandIndex) +
" extends past the end of " 667 " command " +
Twine(LoadCommandIndex) +
" extends " 668 "past the end of the file");
671 if (BigSize > FileSize)
673 Twine(CmdName) +
" command " +
674 Twine(LoadCommandIndex) +
" extends past the end of " 682 " command " +
Twine(LoadCommandIndex) +
" extends " 683 "past the end of the file");
686 if (BigSize > FileSize)
687 return malformedError(
"weak_bind_off field plus weak_bind_size field of " +
688 Twine(CmdName) +
" command " +
689 Twine(LoadCommandIndex) +
" extends past the end of " 693 "dyld weak bind info"))
697 " command " +
Twine(LoadCommandIndex) +
" extends " 698 "past the end of the file");
701 if (BigSize > FileSize)
702 return malformedError(
"lazy_bind_off field plus lazy_bind_size field of " +
703 Twine(CmdName) +
" command " +
704 Twine(LoadCommandIndex) +
" extends past the end of " 708 "dyld lazy bind info"))
712 " command " +
Twine(LoadCommandIndex) +
" extends " 713 "past the end of the file");
716 if (BigSize > FileSize)
717 return malformedError(
"export_off field plus export_size field of " +
718 Twine(CmdName) +
" command " +
719 Twine(LoadCommandIndex) +
" extends past the end of " 730 const MachOObjectFile::LoadCommandInfo &
Load,
731 uint32_t LoadCommandIndex,
const char *CmdName) {
734 CmdName +
" cmdsize too small");
735 auto CommandOrErr = getStructOrErr<MachO::dylib_command>(Obj, Load.Ptr);
737 return CommandOrErr.takeError();
741 CmdName +
" name.offset field too small, not past " 742 "the end of the dylib_command struct");
745 CmdName +
" name.offset field extends past the end " 746 "of the load command");
750 const char *
P = (
const char *)Load.Ptr;
756 CmdName +
" library name extends past the end of the " 762 const MachOObjectFile::LoadCommandInfo &
Load,
764 const char **LoadCmd) {
768 if (*LoadCmd !=
nullptr)
772 return malformedError(
"LC_ID_DYLIB load command in non-dynamic library " 779 const MachOObjectFile::LoadCommandInfo &
Load,
780 uint32_t LoadCommandIndex,
const char *CmdName) {
783 CmdName +
" cmdsize too small");
784 auto CommandOrErr = getStructOrErr<MachO::dylinker_command>(Obj, Load.Ptr);
786 return CommandOrErr.takeError();
790 CmdName +
" name.offset field too small, not past " 791 "the end of the dylinker_command struct");
794 CmdName +
" name.offset field extends past the end " 795 "of the load command");
799 const char *
P = (
const char *)Load.Ptr;
805 CmdName +
" dyld name extends past the end of the " 811 const MachOObjectFile::LoadCommandInfo &
Load,
813 const char **LoadCmd,
const char *CmdName) {
816 CmdName +
" has incorrect cmdsize");
817 if (*LoadCmd !=
nullptr)
819 "LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_TVOS or " 820 "LC_VERSION_MIN_WATCHOS command");
826 const MachOObjectFile::LoadCommandInfo &
Load,
828 std::list<MachOElement> &Elements) {
831 " LC_NOTE has incorrect cmdsize");
832 auto NoteCmdOrErr = getStructOrErr<MachO::note_command>(Obj, Load.Ptr);
834 return NoteCmdOrErr.takeError();
836 uint64_t FileSize = Obj.getData().
size();
839 Twine(LoadCommandIndex) +
" extends " 840 "past the end of the file");
841 uint64_t BigSize = Nt.
offset;
843 if (BigSize > FileSize)
844 return malformedError(
"size field plus offset field of LC_NOTE command " +
845 Twine(LoadCommandIndex) +
" extends past the end of " 855 const MachOObjectFile::LoadCommandInfo &
Load,
859 getStructOrErr<MachO::build_version_command>(Obj, Load.Ptr);
861 return BVCOrErr.takeError();
863 if (Load.C.cmdsize !=
867 " LC_BUILD_VERSION_COMMAND has incorrect cmdsize");
871 for (
unsigned i = 0; i < BVC.
ntools; ++i)
878 const MachOObjectFile::LoadCommandInfo &
Load,
882 " LC_RPATH cmdsize too small");
883 auto ROrErr = getStructOrErr<MachO::rpath_command>(Obj, Load.Ptr);
885 return ROrErr.takeError();
889 " LC_RPATH path.offset field too small, not past " 890 "the end of the rpath_command struct");
893 " LC_RPATH path.offset field extends past the end " 894 "of the load command");
898 const char *
P = (
const char *)Load.Ptr;
904 " LC_RPATH library name extends past the end of the " 910 const MachOObjectFile::LoadCommandInfo &
Load,
912 uint64_t cryptoff, uint64_t cryptsize,
913 const char **LoadCmd,
const char *CmdName) {
914 if (*LoadCmd !=
nullptr)
916 "LC_ENCRYPTION_INFO_64 command");
917 uint64_t FileSize = Obj.getData().size();
918 if (cryptoff > FileSize)
920 " command " +
Twine(LoadCommandIndex) +
" extends " 921 "past the end of the file");
922 uint64_t BigSize = cryptoff;
923 BigSize += cryptsize;
924 if (BigSize > FileSize)
926 Twine(CmdName) +
" command " +
927 Twine(LoadCommandIndex) +
" extends past the end of " 934 const MachOObjectFile::LoadCommandInfo &
Load,
938 " LC_LINKER_OPTION cmdsize too small");
939 auto LinkOptionOrErr =
940 getStructOrErr<MachO::linker_option_command>(Obj, Load.Ptr);
941 if (!LinkOptionOrErr)
942 return LinkOptionOrErr.takeError();
945 const char *
string = (
const char *)Load.Ptr +
950 while (*
string ==
'\0' && left > 0) {
957 if (0xffffffff == NullPos)
959 " LC_LINKER_OPTION string #" +
Twine(i) +
960 " is not NULL terminated");
961 uint32_t len = std::min(NullPos, left) + 1;
968 " LC_LINKER_OPTION string count " +
Twine(L.
count) +
969 " does not match number of strings");
974 const MachOObjectFile::LoadCommandInfo &
Load,
975 uint32_t LoadCommandIndex,
const char *CmdName,
976 size_t SizeOfCmd,
const char *CmdStructName,
977 uint32_t PathOffset,
const char *PathFieldName) {
978 if (PathOffset < SizeOfCmd)
980 CmdName +
" " + PathFieldName +
".offset field too " 981 "small, not past the end of the " + CmdStructName);
982 if (PathOffset >= Load.C.cmdsize)
984 CmdName +
" " + PathFieldName +
".offset field " 985 "extends past the end of the load command");
989 const char *
P = (
const char *)Load.Ptr;
990 for (i = PathOffset; i < Load.C.cmdsize; i++)
993 if (i >= Load.C.cmdsize)
995 CmdName +
" " + PathFieldName +
" name extends past " 996 "the end of the load command");
1001 const MachOObjectFile::LoadCommandInfo &
Load,
1003 const char *CmdName) {
1006 CmdName +
" cmdsize too small");
1007 auto ThreadCommandOrErr =
1008 getStructOrErr<MachO::thread_command>(Obj, Load.Ptr);
1009 if (!ThreadCommandOrErr)
1010 return ThreadCommandOrErr.takeError();
1016 while (state < end) {
1019 "flavor in " + CmdName +
" extends past end of " 1022 memcpy(&flavor, state,
sizeof(
uint32_t));
1029 " count in " + CmdName +
" extends past end of " 1032 memcpy(&count, state,
sizeof(
uint32_t));
1041 " count not x86_THREAD_STATE32_COUNT for " 1042 "flavor number " +
Twine(nflavor) +
" which is " 1043 "a x86_THREAD_STATE32 flavor in " + CmdName +
1047 " x86_THREAD_STATE32 extends past end of " 1048 "command in " + CmdName +
" command");
1052 " unknown flavor (" +
Twine(flavor) +
") for " 1053 "flavor number " +
Twine(nflavor) +
" in " +
1054 CmdName +
" command");
1060 " count not x86_THREAD_STATE_COUNT for " 1061 "flavor number " +
Twine(nflavor) +
" which is " 1062 "a x86_THREAD_STATE flavor in " + CmdName +
1066 " x86_THREAD_STATE extends past end of " 1067 "command in " + CmdName +
" command");
1072 " count not x86_FLOAT_STATE_COUNT for " 1073 "flavor number " +
Twine(nflavor) +
" which is " 1074 "a x86_FLOAT_STATE flavor in " + CmdName +
1078 " x86_FLOAT_STATE extends past end of " 1079 "command in " + CmdName +
" command");
1084 " count not x86_EXCEPTION_STATE_COUNT for " 1085 "flavor number " +
Twine(nflavor) +
" which is " 1086 "a x86_EXCEPTION_STATE flavor in " + CmdName +
1090 " x86_EXCEPTION_STATE extends past end of " 1091 "command in " + CmdName +
" command");
1096 " count not x86_THREAD_STATE64_COUNT for " 1097 "flavor number " +
Twine(nflavor) +
" which is " 1098 "a x86_THREAD_STATE64 flavor in " + CmdName +
1102 " x86_THREAD_STATE64 extends past end of " 1103 "command in " + CmdName +
" command");
1108 " count not x86_EXCEPTION_STATE64_COUNT for " 1109 "flavor number " +
Twine(nflavor) +
" which is " 1110 "a x86_EXCEPTION_STATE64 flavor in " + CmdName +
1114 " x86_EXCEPTION_STATE64 extends past end of " 1115 "command in " + CmdName +
" command");
1119 " unknown flavor (" +
Twine(flavor) +
") for " 1120 "flavor number " +
Twine(nflavor) +
" in " +
1121 CmdName +
" command");
1127 " count not ARM_THREAD_STATE_COUNT for " 1128 "flavor number " +
Twine(nflavor) +
" which is " 1129 "a ARM_THREAD_STATE flavor in " + CmdName +
1133 " ARM_THREAD_STATE extends past end of " 1134 "command in " + CmdName +
" command");
1138 " unknown flavor (" +
Twine(flavor) +
") for " 1139 "flavor number " +
Twine(nflavor) +
" in " +
1140 CmdName +
" command");
1147 " count not ARM_THREAD_STATE64_COUNT for " 1148 "flavor number " +
Twine(nflavor) +
" which is " 1149 "a ARM_THREAD_STATE64 flavor in " + CmdName +
1153 " ARM_THREAD_STATE64 extends past end of " 1154 "command in " + CmdName +
" command");
1158 " unknown flavor (" +
Twine(flavor) +
") for " 1159 "flavor number " +
Twine(nflavor) +
" in " +
1160 CmdName +
" command");
1166 " count not PPC_THREAD_STATE_COUNT for " 1167 "flavor number " +
Twine(nflavor) +
" which is " 1168 "a PPC_THREAD_STATE flavor in " + CmdName +
1172 " PPC_THREAD_STATE extends past end of " 1173 "command in " + CmdName +
" command");
1177 " unknown flavor (" +
Twine(flavor) +
") for " 1178 "flavor number " +
Twine(nflavor) +
" in " +
1179 CmdName +
" command");
1183 "command " +
Twine(LoadCommandIndex) +
" for " +
1184 CmdName +
" command can't be checked");
1192 const MachOObjectFile::LoadCommandInfo
1195 const char **LoadCmd,
1196 std::list<MachOElement> &Elements) {
1199 " LC_TWOLEVEL_HINTS has incorrect cmdsize");
1200 if (*LoadCmd !=
nullptr)
1201 return malformedError(
"more than one LC_TWOLEVEL_HINTS command");
1202 auto HintsOrErr = getStructOrErr<MachO::twolevel_hints_command>(Obj, Load.Ptr);
1204 return HintsOrErr.takeError();
1206 uint64_t FileSize = Obj.getData().size();
1207 if (Hints.
offset > FileSize)
1208 return malformedError(
"offset field of LC_TWOLEVEL_HINTS command " +
1209 Twine(LoadCommandIndex) +
" extends past the end of " 1211 uint64_t BigSize = Hints.
nhints;
1214 if (BigSize > FileSize)
1215 return malformedError(
"offset field plus nhints times sizeof(struct " 1216 "twolevel_hint) field of LC_TWOLEVEL_HINTS command " +
1217 Twine(LoadCommandIndex) +
" extends past the end of " 1223 *LoadCmd = Load.Ptr;
1231 if (cmd == MachO::LC_SYMSEG ||
1232 cmd == MachO::LC_LOADFVMLIB ||
1233 cmd == MachO::LC_IDFVMLIB ||
1234 cmd == MachO::LC_IDENT ||
1235 cmd == MachO::LC_FVMFILE ||
1236 cmd == MachO::LC_PREPAGE ||
1237 cmd == MachO::LC_PREBOUND_DYLIB ||
1238 cmd == MachO::LC_TWOLEVEL_HINTS ||
1239 cmd == MachO::LC_PREBIND_CKSUM)
1246 bool Is64Bits,
uint32_t UniversalCputype,
1249 std::unique_ptr<MachOObjectFile> Obj(
1251 Is64Bits, Err, UniversalCputype,
1254 return std::move(Err);
1255 return std::move(Obj);
1258 MachOObjectFile::MachOObjectFile(
MemoryBufferRef Object,
bool IsLittleEndian,
1259 bool Is64bits,
Error &Err,
1262 :
ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object) {
1264 uint64_t SizeOfHeaders;
1269 cputype = Header64.cputype;
1273 cputype = Header.cputype;
1277 SizeOfHeaders += getHeader().sizeofcmds;
1278 if (getData().data() + SizeOfHeaders > getData().
end()) {
1279 Err =
malformedError(
"load commands extend past the end of the file");
1282 if (UniversalCputype != 0 && cputype != UniversalCputype) {
1284 Twine(UniversalIndex) +
"'s cputype does not match " 1285 "object file's mach header");
1288 std::list<MachOElement> Elements;
1289 Elements.push_back({0, SizeOfHeaders,
"Mach-O headers"});
1291 uint32_t LoadCommandCount = getHeader().ncmds;
1293 if (LoadCommandCount != 0) {
1297 Err = LoadOrErr.takeError();
1302 const char *DyldIdLoadCmd =
nullptr;
1303 const char *FuncStartsLoadCmd =
nullptr;
1304 const char *SplitInfoLoadCmd =
nullptr;
1305 const char *CodeSignDrsLoadCmd =
nullptr;
1306 const char *CodeSignLoadCmd =
nullptr;
1307 const char *VersLoadCmd =
nullptr;
1308 const char *SourceLoadCmd =
nullptr;
1309 const char *EntryPointLoadCmd =
nullptr;
1310 const char *EncryptLoadCmd =
nullptr;
1311 const char *RoutinesLoadCmd =
nullptr;
1312 const char *UnixThreadLoadCmd =
nullptr;
1313 const char *TwoLevelHintsLoadCmd =
nullptr;
1314 for (
unsigned I = 0;
I < LoadCommandCount; ++
I) {
1321 Load.
C.
cmd != MachO::LC_THREAD || Load.
C.
cmdsize % 4) {
1334 LoadCommands.push_back(Load);
1335 if (Load.
C.
cmd == MachO::LC_SYMTAB) {
1338 }
else if (Load.
C.
cmd == MachO::LC_DYSYMTAB) {
1342 }
else if (Load.
C.
cmd == MachO::LC_DATA_IN_CODE) {
1344 "LC_DATA_IN_CODE", Elements,
1345 "data in code info")))
1347 }
else if (Load.
C.
cmd == MachO::LC_LINKER_OPTIMIZATION_HINT) {
1349 "LC_LINKER_OPTIMIZATION_HINT",
1350 Elements,
"linker optimization " 1353 }
else if (Load.
C.
cmd == MachO::LC_FUNCTION_STARTS) {
1355 "LC_FUNCTION_STARTS", Elements,
1356 "function starts data")))
1358 }
else if (Load.
C.
cmd == MachO::LC_SEGMENT_SPLIT_INFO) {
1360 "LC_SEGMENT_SPLIT_INFO", Elements,
1361 "split info data")))
1363 }
else if (Load.
C.
cmd == MachO::LC_DYLIB_CODE_SIGN_DRS) {
1365 "LC_DYLIB_CODE_SIGN_DRS", Elements,
1366 "code signing RDs data")))
1368 }
else if (Load.
C.
cmd == MachO::LC_CODE_SIGNATURE) {
1370 "LC_CODE_SIGNATURE", Elements,
1371 "code signature data")))
1373 }
else if (Load.
C.
cmd == MachO::LC_DYLD_INFO) {
1375 "LC_DYLD_INFO", Elements)))
1377 }
else if (Load.
C.
cmd == MachO::LC_DYLD_INFO_ONLY) {
1379 "LC_DYLD_INFO_ONLY", Elements)))
1381 }
else if (Load.
C.
cmd == MachO::LC_UUID) {
1391 UuidLoadCmd = Load.
Ptr;
1392 }
else if (Load.
C.
cmd == MachO::LC_SEGMENT_64) {
1395 *
this, Load, Sections, HasPageZeroSegment,
I,
1396 "LC_SEGMENT_64", SizeOfHeaders, Elements)))
1398 }
else if (Load.
C.
cmd == MachO::LC_SEGMENT) {
1401 *
this, Load, Sections, HasPageZeroSegment,
I,
1402 "LC_SEGMENT", SizeOfHeaders, Elements)))
1404 }
else if (Load.
C.
cmd == MachO::LC_ID_DYLIB) {
1407 }
else if (Load.
C.
cmd == MachO::LC_LOAD_DYLIB) {
1410 Libraries.push_back(Load.
Ptr);
1411 }
else if (Load.
C.
cmd == MachO::LC_LOAD_WEAK_DYLIB) {
1414 Libraries.push_back(Load.
Ptr);
1415 }
else if (Load.
C.
cmd == MachO::LC_LAZY_LOAD_DYLIB) {
1418 Libraries.push_back(Load.
Ptr);
1419 }
else if (Load.
C.
cmd == MachO::LC_REEXPORT_DYLIB) {
1422 Libraries.push_back(Load.
Ptr);
1423 }
else if (Load.
C.
cmd == MachO::LC_LOAD_UPWARD_DYLIB) {
1426 Libraries.push_back(Load.
Ptr);
1427 }
else if (Load.
C.
cmd == MachO::LC_ID_DYLINKER) {
1430 }
else if (Load.
C.
cmd == MachO::LC_LOAD_DYLINKER) {
1433 }
else if (Load.
C.
cmd == MachO::LC_DYLD_ENVIRONMENT) {
1436 }
else if (Load.
C.
cmd == MachO::LC_VERSION_MIN_MACOSX) {
1438 "LC_VERSION_MIN_MACOSX")))
1440 }
else if (Load.
C.
cmd == MachO::LC_VERSION_MIN_IPHONEOS) {
1442 "LC_VERSION_MIN_IPHONEOS")))
1444 }
else if (Load.
C.
cmd == MachO::LC_VERSION_MIN_TVOS) {
1446 "LC_VERSION_MIN_TVOS")))
1448 }
else if (Load.
C.
cmd == MachO::LC_VERSION_MIN_WATCHOS) {
1450 "LC_VERSION_MIN_WATCHOS")))
1452 }
else if (Load.
C.
cmd == MachO::LC_NOTE) {
1455 }
else if (Load.
C.
cmd == MachO::LC_BUILD_VERSION) {
1458 }
else if (Load.
C.
cmd == MachO::LC_RPATH) {
1461 }
else if (Load.
C.
cmd == MachO::LC_SOURCE_VERSION) {
1464 " has incorrect cmdsize");
1467 if (SourceLoadCmd) {
1471 SourceLoadCmd = Load.
Ptr;
1472 }
else if (Load.
C.
cmd == MachO::LC_MAIN) {
1475 " has incorrect cmdsize");
1478 if (EntryPointLoadCmd) {
1482 EntryPointLoadCmd = Load.
Ptr;
1483 }
else if (Load.
C.
cmd == MachO::LC_ENCRYPTION_INFO) {
1486 " has incorrect cmdsize");
1490 getStruct<MachO::encryption_info_command>(*
this, Load.
Ptr);
1492 &EncryptLoadCmd,
"LC_ENCRYPTION_INFO")))
1494 }
else if (Load.
C.
cmd == MachO::LC_ENCRYPTION_INFO_64) {
1497 " has incorrect cmdsize");
1501 getStruct<MachO::encryption_info_command_64>(*
this, Load.
Ptr);
1503 &EncryptLoadCmd,
"LC_ENCRYPTION_INFO_64")))
1505 }
else if (Load.
C.
cmd == MachO::LC_LINKER_OPTION) {
1508 }
else if (Load.
C.
cmd == MachO::LC_SUB_FRAMEWORK) {
1511 " LC_SUB_FRAMEWORK cmdsize too small");
1515 getStruct<MachO::sub_framework_command>(*
this, Load.
Ptr);
1518 "sub_framework_command", S.
umbrella,
1521 }
else if (Load.
C.
cmd == MachO::LC_SUB_UMBRELLA) {
1524 " LC_SUB_UMBRELLA cmdsize too small");
1528 getStruct<MachO::sub_umbrella_command>(*
this, Load.
Ptr);
1534 }
else if (Load.
C.
cmd == MachO::LC_SUB_LIBRARY) {
1537 " LC_SUB_LIBRARY cmdsize too small");
1541 getStruct<MachO::sub_library_command>(*
this, Load.
Ptr);
1547 }
else if (Load.
C.
cmd == MachO::LC_SUB_CLIENT) {
1550 " LC_SUB_CLIENT cmdsize too small");
1554 getStruct<MachO::sub_client_command>(*
this, Load.
Ptr);
1557 "sub_client_command", S.
client,
"client")))
1559 }
else if (Load.
C.
cmd == MachO::LC_ROUTINES) {
1562 " has incorrect cmdsize");
1565 if (RoutinesLoadCmd) {
1566 Err =
malformedError(
"more than one LC_ROUTINES and or LC_ROUTINES_64 " 1570 RoutinesLoadCmd = Load.
Ptr;
1571 }
else if (Load.
C.
cmd == MachO::LC_ROUTINES_64) {
1574 " has incorrect cmdsize");
1577 if (RoutinesLoadCmd) {
1578 Err =
malformedError(
"more than one LC_ROUTINES_64 and or LC_ROUTINES " 1582 RoutinesLoadCmd = Load.
Ptr;
1583 }
else if (Load.
C.
cmd == MachO::LC_UNIXTHREAD) {
1586 if (UnixThreadLoadCmd) {
1590 UnixThreadLoadCmd = Load.
Ptr;
1591 }
else if (Load.
C.
cmd == MachO::LC_THREAD) {
1595 }
else if (Load.
C.
cmd == MachO::LC_TWOLEVEL_HINTS) {
1597 &TwoLevelHintsLoadCmd, Elements)))
1601 Twine(Load.
C.
cmd) +
" is obsolete and not " 1608 if (
I < LoadCommandCount - 1) {
1612 Err = LoadOrErr.takeError();
1617 if (!SymtabLoadCmd) {
1618 if (DysymtabLoadCmd) {
1619 Err =
malformedError(
"contains LC_DYSYMTAB load command without a " 1620 "LC_SYMTAB load command");
1623 }
else if (DysymtabLoadCmd) {
1625 getStruct<MachO::symtab_command>(*
this, SymtabLoadCmd);
1627 getStruct<MachO::dysymtab_command>(*
this, DysymtabLoadCmd);
1628 if (Dysymtab.nlocalsym != 0 && Dysymtab.ilocalsym > Symtab.
nsyms) {
1630 "extends past the end of the symbol table");
1633 uint64_t BigSize = Dysymtab.ilocalsym;
1634 BigSize += Dysymtab.nlocalsym;
1635 if (Dysymtab.nlocalsym != 0 && BigSize > Symtab.
nsyms) {
1636 Err =
malformedError(
"ilocalsym plus nlocalsym in LC_DYSYMTAB load " 1637 "command extends past the end of the symbol table");
1640 if (Dysymtab.nextdefsym != 0 && Dysymtab.iextdefsym > Symtab.
nsyms) {
1642 "extends past the end of the symbol table");
1645 BigSize = Dysymtab.iextdefsym;
1646 BigSize += Dysymtab.nextdefsym;
1647 if (Dysymtab.nextdefsym != 0 && BigSize > Symtab.
nsyms) {
1648 Err =
malformedError(
"iextdefsym plus nextdefsym in LC_DYSYMTAB " 1649 "load command extends past the end of the symbol " 1653 if (Dysymtab.nundefsym != 0 && Dysymtab.iundefsym > Symtab.
nsyms) {
1655 "extends past the end of the symbol table");
1658 BigSize = Dysymtab.iundefsym;
1659 BigSize += Dysymtab.nundefsym;
1660 if (Dysymtab.nundefsym != 0 && BigSize > Symtab.
nsyms) {
1661 Err =
malformedError(
"iundefsym plus nundefsym in LC_DYSYMTAB load " 1662 " command extends past the end of the symbol table");
1668 DyldIdLoadCmd ==
nullptr) {
1669 Err =
malformedError(
"no LC_ID_DYLIB load command in dynamic library " 1673 assert(LoadCommands.size() == LoadCommandCount);
1691 uint64_t NValue = 0;
1713 if (NSect == 0 || NSect > Sections.size())
1715 " for symbol at index " +
Twine(SymbolIndex));
1720 "the end of string table, for N_INDR symbol at " 1721 "index " +
Twine(SymbolIndex));
1724 (((NType & MachO::N_TYPE) ==
MachO::N_UNDF && NValue == 0) ||
1727 if (LibraryOrdinal != 0 &&
1730 LibraryOrdinal - 1 >= Libraries.size() ) {
1732 " for symbol at index " +
Twine(SymbolIndex));
1738 " past the end of string table, for symbol at " 1739 "index " +
Twine(SymbolIndex));
1753 StringRef StringTable = getStringTableData();
1759 const char *Start = &StringTable.
data()[Entry.
n_strx];
1760 if (Start < getData().
begin() || Start >= getData().
end()) {
1762 " for symbol at index " +
Twine(getSymbolIndex(Symb)));
1786 StringRef StringTable = getStringTableData();
1790 uint64_t NValue = getNValue(Symb);
1791 if (NValue >= StringTable.
size())
1793 const char *Start = &StringTable.
data()[NValue];
1795 return std::error_code();
1798 uint64_t MachOObjectFile::getSymbolValueImpl(
DataRefImpl Sym)
const {
1799 return getNValue(Sym);
1807 uint32_t flags = getSymbolFlags(DRI);
1816 return getNValue(DRI);
1822 uint8_t n_type = Entry.
n_type;
1836 if (Sec->isData() || Sec->isBSS())
1846 uint8_t MachOType = Entry.
n_type;
1885 uint8_t index = Entry.
n_sect;
1888 return section_end();
1890 DRI.
d.
a = index - 1;
1891 if (DRI.
d.
a >= Sections.size()){
1893 " for symbol at index " +
Twine(getSymbolIndex(Symb)));
1915 return getSection64(Sec).addr;
1933 SectOffset = Sect.
offset;
1934 SectSize = Sect.
size;
1938 SectOffset = Sect.
offset;
1939 SectSize = Sect.
size;
1944 uint64_t FileSize = getData().size();
1945 if (SectOffset > FileSize)
1947 if (FileSize - SectOffset < SectSize)
1948 return FileSize - SectOffset;
1953 uint64_t
Size)
const {
1972 return getSectionContents(Offset, Size);
1985 return uint64_t(1) <<
Align;
1989 if (SectionIndex < 1 || SectionIndex > Sections.size())
1993 DRI.
d.
a = SectionIndex - 1;
1999 auto NameOrErr =
Section.getName();
2001 return NameOrErr.takeError();
2002 if (*NameOrErr == SectionName)
2045 StringRef SegmentName = getSectionFinalSegmentName(Sec);
2047 return (SegmentName ==
"__LLVM" && *NameOrErr ==
"__bitcode");
2053 return getSection64(Sec).offset == 0;
2122 "Only implemented for MH_OBJECT && MH_KEXT_BUNDLE");
2124 return getAnyRelocationAddress(RE);
2130 if (isRelocationScattered(RE))
2131 return symbol_end();
2133 uint32_t SymbolIdx = getPlainRelocationSymbolNum(RE);
2134 bool isExtern = getPlainRelocationExternal(RE);
2136 return symbol_end();
2144 Sym.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Offset));
2155 return getAnyRelocationType(RE);
2161 uint64_t RType = getRelocationType(Rel);
2163 unsigned Arch = this->getArch();
2167 static const char *
const Table[] = {
2168 "GENERIC_RELOC_VANILLA",
2169 "GENERIC_RELOC_PAIR",
2170 "GENERIC_RELOC_SECTDIFF",
2171 "GENERIC_RELOC_PB_LA_PTR",
2172 "GENERIC_RELOC_LOCAL_SECTDIFF",
2173 "GENERIC_RELOC_TLV" };
2182 static const char *
const Table[] = {
2183 "X86_64_RELOC_UNSIGNED",
2184 "X86_64_RELOC_SIGNED",
2185 "X86_64_RELOC_BRANCH",
2186 "X86_64_RELOC_GOT_LOAD",
2188 "X86_64_RELOC_SUBTRACTOR",
2189 "X86_64_RELOC_SIGNED_1",
2190 "X86_64_RELOC_SIGNED_2",
2191 "X86_64_RELOC_SIGNED_4",
2192 "X86_64_RELOC_TLV" };
2201 static const char *
const Table[] = {
2202 "ARM_RELOC_VANILLA",
2204 "ARM_RELOC_SECTDIFF",
2205 "ARM_RELOC_LOCAL_SECTDIFF",
2206 "ARM_RELOC_PB_LA_PTR",
2208 "ARM_THUMB_RELOC_BR22",
2209 "ARM_THUMB_32BIT_BRANCH",
2211 "ARM_RELOC_HALF_SECTDIFF" };
2221 static const char *
const Table[] = {
2222 "ARM64_RELOC_UNSIGNED",
"ARM64_RELOC_SUBTRACTOR",
2223 "ARM64_RELOC_BRANCH26",
"ARM64_RELOC_PAGE21",
2224 "ARM64_RELOC_PAGEOFF12",
"ARM64_RELOC_GOT_LOAD_PAGE21",
2225 "ARM64_RELOC_GOT_LOAD_PAGEOFF12",
"ARM64_RELOC_POINTER_TO_GOT",
2226 "ARM64_RELOC_TLVP_LOAD_PAGE21",
"ARM64_RELOC_TLVP_LOAD_PAGEOFF12",
2227 "ARM64_RELOC_ADDEND" 2237 static const char *
const Table[] = {
2238 "PPC_RELOC_VANILLA",
2246 "PPC_RELOC_SECTDIFF",
2247 "PPC_RELOC_PB_LA_PTR",
2248 "PPC_RELOC_HI16_SECTDIFF",
2249 "PPC_RELOC_LO16_SECTDIFF",
2250 "PPC_RELOC_HA16_SECTDIFF",
2252 "PPC_RELOC_LO14_SECTDIFF",
2253 "PPC_RELOC_LOCAL_SECTDIFF" };
2270 return getAnyRelocationLength(RE);
2312 StringRef Foo,
F, DotFramework, V, Dylib, Lib, Dot, Qtx;
2313 size_t a, b, c, d, Idx;
2315 isFramework =
false;
2319 a = Name.
rfind(
'/');
2320 if (a == Name.
npos || a == 0)
2325 Idx = Foo.
rfind(
'_');
2326 if (Idx != Foo.
npos && Foo.
size() >= 2) {
2328 if (Suffix !=
"_debug" && Suffix !=
"_profile")
2331 Foo = Foo.
slice(0, Idx);
2335 b = Name.
rfind(
'/', a);
2341 DotFramework = Name.
slice(Idx + Foo.
size(),
2342 Idx + Foo.
size() +
sizeof(
".framework/")-1);
2343 if (F == Foo && DotFramework ==
".framework/") {
2351 c = Name.
rfind(
'/', b);
2352 if (c == Name.
npos || c == 0)
2357 d = Name.
rfind(
'/', c);
2363 DotFramework = Name.
slice(Idx + Foo.
size(),
2364 Idx + Foo.
size() +
sizeof(
".framework/")-1);
2365 if (F == Foo && DotFramework ==
".framework/") {
2372 a = Name.
rfind(
'.');
2373 if (a == Name.
npos || a == 0)
2376 if (Dylib !=
".dylib")
2381 Dot = Name.
slice(a-2, a-1);
2386 b = Name.
rfind(
'/', a);
2392 Idx = Name.
rfind(
'_');
2393 if (Idx != Name.
npos && Idx != b) {
2394 Lib = Name.
slice(b, Idx);
2395 Suffix = Name.
slice(Idx, a);
2396 if (Suffix !=
"_debug" && Suffix !=
"_profile") {
2398 Lib = Name.
slice(b, a);
2402 Lib = Name.
slice(b, a);
2405 if (Lib.
size() >= 3) {
2416 b = Name.
rfind(
'/', a);
2418 Lib = Name.
slice(0, a);
2420 Lib = Name.
slice(b+1, a);
2422 if (Lib.
size() >= 3) {
2437 if (Index >= Libraries.size())
2442 if (LibrariesShortNames.size() == 0) {
2443 for (
unsigned i = 0; i < Libraries.size(); i++) {
2445 getStructOrErr<MachO::dylib_command>(*
this, Libraries[i]);
2451 const char *
P = (
const char *)(Libraries[i]) + D.
dylib.
name;
2457 StringRef shortName = guessLibraryShortName(Name, isFramework, Suffix);
2458 if (shortName.
empty())
2459 LibrariesShortNames.push_back(Name);
2461 LibrariesShortNames.push_back(shortName);
2465 Res = LibrariesShortNames[
Index];
2466 return std::error_code();
2470 return Libraries.size();
2476 Sec.
d.
a = Rel->getRawDataRefImpl().d.a;
2483 if (!SymtabLoadCmd || Symtab.
nsyms == 0)
2486 return getSymbolByIndex(0);
2492 if (!SymtabLoadCmd || Symtab.
nsyms == 0)
2500 DRI.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Offset));
2506 if (!SymtabLoadCmd || Index >= Symtab.
nsyms)
2511 DRI.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Symtab.
symoff));
2523 DRIstart.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Symtab.
symoff));
2524 uint64_t
Index = (Symb.
p - DRIstart.
p) / SymbolTableEntrySize;
2535 DRI.
d.
a = Sections.size();
2548 return "Mach-O 32-bit i386";
2550 return "Mach-O arm";
2552 return "Mach-O arm64 (ILP32)";
2554 return "Mach-O 32-bit ppc";
2556 return "Mach-O 32-bit unknown";
2562 return "Mach-O 64-bit x86-64";
2564 return "Mach-O arm64";
2566 return "Mach-O 64-bit ppc64";
2568 return "Mach-O 64-bit unknown";
2594 const char **McpuDefault,
2595 const char **ArchFlag) {
2597 *McpuDefault =
nullptr;
2599 *ArchFlag =
nullptr;
2607 return Triple(
"i386-apple-darwin");
2615 *ArchFlag =
"x86_64";
2616 return Triple(
"x86_64-apple-darwin");
2619 *ArchFlag =
"x86_64h";
2620 return Triple(
"x86_64h-apple-darwin");
2628 *ArchFlag =
"armv4t";
2629 return Triple(
"armv4t-apple-darwin");
2632 *ArchFlag =
"armv5e";
2633 return Triple(
"armv5e-apple-darwin");
2636 *ArchFlag =
"xscale";
2637 return Triple(
"xscale-apple-darwin");
2640 *ArchFlag =
"armv6";
2641 return Triple(
"armv6-apple-darwin");
2644 *McpuDefault =
"cortex-m0";
2646 *ArchFlag =
"armv6m";
2647 return Triple(
"armv6m-apple-darwin");
2650 *ArchFlag =
"armv7";
2651 return Triple(
"armv7-apple-darwin");
2654 *McpuDefault =
"cortex-m4";
2656 *ArchFlag =
"armv7em";
2657 return Triple(
"thumbv7em-apple-darwin");
2660 *McpuDefault =
"cortex-a7";
2662 *ArchFlag =
"armv7k";
2663 return Triple(
"armv7k-apple-darwin");
2666 *McpuDefault =
"cortex-m3";
2668 *ArchFlag =
"armv7m";
2669 return Triple(
"thumbv7m-apple-darwin");
2672 *McpuDefault =
"cortex-a7";
2674 *ArchFlag =
"armv7s";
2675 return Triple(
"armv7s-apple-darwin");
2683 *McpuDefault =
"cyclone";
2685 *ArchFlag =
"arm64";
2686 return Triple(
"arm64-apple-darwin");
2694 *McpuDefault =
"cyclone";
2696 *ArchFlag =
"arm64_32";
2697 return Triple(
"arm64_32-apple-darwin");
2706 return Triple(
"ppc-apple-darwin");
2714 *ArchFlag =
"ppc64";
2715 return Triple(
"ppc64-apple-darwin");
2729 auto validArchs = getValidArchs();
2730 return llvm::find(validArchs, ArchFlag) != validArchs.end();
2734 static const std::array<StringRef, 17> validArchs = {{
2735 "i386",
"x86_64",
"x86_64h",
"armv4t",
"arm",
"armv5e",
2736 "armv6",
"armv6m",
"armv7",
"armv7em",
"armv7k",
"armv7m",
2737 "armv7s",
"arm64",
"arm64_32",
"ppc",
"ppc64",
2748 return getArchTriple(Header.cputype, Header.cpusubtype, McpuDefault);
2754 return section_rel_begin(DRI);
2760 return section_rel_end(DRI);
2765 if (!DataInCodeLoadCmd)
2769 DRI.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, DicLC.
dataoff));
2775 if (!DataInCodeLoadCmd)
2780 DRI.
p =
reinterpret_cast<uintptr_t
>(
getPtr(*
this, Offset));
2787 void ExportEntry::moveToFirst() {
2792 pushDownUntilBottom();
2795 void ExportEntry::moveToEnd() {
2802 if (Done || Other.Done)
2803 return (Done == Other.Done);
2805 if (Stack.
size() != Other.Stack.
size())
2808 if (!CumulativeString.
equals(Other.CumulativeString))
2811 for (
unsigned i=0; i < Stack.
size(); ++i) {
2812 if (Stack[i].Start != Other.Stack[i].Start)
2822 if (Ptr > Trie.
end())
2828 return CumulativeString;
2832 return Stack.
back().Flags;
2836 return Stack.
back().Address;
2840 return Stack.
back().Other;
2844 const char* ImportName = Stack.
back().ImportName;
2851 return Stack.
back().Start - Trie.
begin();
2854 ExportEntry::NodeState::NodeState(
const uint8_t *Ptr)
2855 : Start(Ptr), Current(Ptr) {}
2857 void ExportEntry::pushNode(uint64_t offset) {
2859 const uint8_t *Ptr = Trie.
begin() + offset;
2860 NodeState State(Ptr);
2862 uint64_t ExportInfoSize =
readULEB128(State.Current, &error);
2865 " in export trie data at node: 0x" +
2870 State.IsExportNode = (ExportInfoSize != 0);
2871 const uint8_t* Children = State.Current + ExportInfoSize;
2872 if (Children > Trie.
end()) {
2876 " too big and extends past end of trie data");
2880 if (State.IsExportNode) {
2881 const uint8_t *ExportStart = State.Current;
2885 " in export trie data at node: 0x" +
2891 if (State.Flags != 0 &&
2896 "unsupported exported symbol kind: " +
Twine((
int)Kind) +
2907 " in export trie data at node: 0x" +
2913 if (State.Other >
O->getLibraryCount()) {
2915 "bad library ordinal: " +
Twine((
int)State.Other) +
" (max " +
2916 Twine((
int)
O->getLibraryCount()) +
2922 State.ImportName =
reinterpret_cast<const char*
>(State.Current);
2923 if (*State.ImportName ==
'\0') {
2926 const uint8_t *End = State.Current + 1;
2927 if (End >= Trie.
end()) {
2928 *
E =
malformedError(
"import name of re-export in export trie data at " 2931 " starts past end of trie data");
2935 while(*End !=
'\0' && End < Trie.
end())
2938 *
E =
malformedError(
"import name of re-export in export trie data at " 2941 " extends past end of trie data");
2945 State.Current = End + 1;
2948 State.Address =
readULEB128(State.Current, &error);
2951 " in export trie data at node: 0x" +
2960 " in export trie data at node: 0x" +
2967 if(ExportStart + ExportInfoSize != State.Current) {
2969 "inconsistant export info size: 0x" +
2977 State.ChildCount = *Children;
2978 if (State.ChildCount != 0 && Children + 1 >= Trie.
end()) {
2979 *
E =
malformedError(
"byte for count of childern in export trie data at " 2982 " extends past end of trie data");
2986 State.Current = Children + 1;
2987 State.NextChildIndex = 0;
2988 State.ParentStringLength = CumulativeString.
size();
2992 void ExportEntry::pushDownUntilBottom() {
2995 while (Stack.
back().NextChildIndex < Stack.
back().ChildCount) {
2996 NodeState &Top = Stack.
back();
2997 CumulativeString.
resize(Top.ParentStringLength);
2998 for (;*Top.Current != 0 && Top.Current < Trie.
end(); Top.Current++) {
2999 char C = *Top.Current;
3002 if (Top.Current >= Trie.
end()) {
3003 *
E =
malformedError(
"edge sub-string in export trie data at node: 0x" +
3005 " for child #" +
Twine((
int)Top.NextChildIndex) +
3006 " extends past end of trie data");
3011 uint64_t childNodeIndex =
readULEB128(Top.Current, &error);
3014 " in export trie data at node: 0x" +
3019 for (
const NodeState &node :
nodes()) {
3020 if (node.Start == Trie.
begin() + childNodeIndex){
3021 *
E =
malformedError(
"loop in childern in export trie data at node: 0x" +
3023 " back to node: 0x" +
3029 Top.NextChildIndex += 1;
3030 pushNode(childNodeIndex);
3034 if (!Stack.
back().IsExportNode) {
3035 *
E =
malformedError(
"node is not an export node in export trie data at " 3059 assert(!Stack.
empty() &&
"ExportEntry::moveNext() with empty node stack");
3060 if (!Stack.
back().IsExportNode) {
3061 *
E =
malformedError(
"node is not an export node in export trie data at " 3069 while (!Stack.
empty()) {
3070 NodeState &Top = Stack.
back();
3071 if (Top.NextChildIndex < Top.ChildCount) {
3072 pushDownUntilBottom();
3076 if (Top.IsExportNode) {
3078 CumulativeString.
resize(Top.ParentStringLength);
3094 Start.moveToFirst();
3103 return exports(Err, getDyldInfoExportsTrie(),
this);
3108 : E(E), O(O), Opcodes(Bytes), Ptr(Bytes.
begin()),
3109 PointerSize(is64Bit ? 8 : 4) {}
3111 void MachORebaseEntry::moveToFirst() {
3112 Ptr = Opcodes.
begin();
3116 void MachORebaseEntry::moveToEnd() {
3117 Ptr = Opcodes.
end();
3118 RemainingLoopCount = 0;
3126 if (RemainingLoopCount) {
3127 --RemainingLoopCount;
3133 if (Ptr == Opcodes.
end()) {
3140 const uint8_t *OpcodeStart = Ptr;
3141 uint8_t Byte = *Ptr++;
3145 const char *error =
nullptr;
3156 *E =
malformedError(
"for REBASE_OPCODE_SET_TYPE_IMM bad bind type: " +
3164 dbgs() <<
"REBASE_OPCODE_SET_TYPE_IMM: " 3165 <<
"RebaseType=" << (
int)
RebaseType <<
"\n");
3168 SegmentIndex = ImmValue;
3171 *E =
malformedError(
"for REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
3172 Twine(error) +
" for opcode at: 0x" +
3180 *E =
malformedError(
"for REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
3181 Twine(error) +
" for opcode at: 0x" +
3188 dbgs() <<
"REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: " 3189 <<
"SegmentIndex=" << SegmentIndex <<
", " 3197 " for opcode at: 0x" +
3206 " for opcode at: 0x" +
3212 dbgs() <<
"REBASE_OPCODE_ADD_ADDR_ULEB: " 3213 <<
format(
"SegmentOffset=0x%06X",
3221 Twine(error) +
" for opcode at: 0x" +
3232 " (after adding immediate times the pointer size) " +
3233 Twine(error) +
" for opcode at: 0x" +
3239 dbgs() <<
"REBASE_OPCODE_ADD_ADDR_IMM_SCALED: " 3240 <<
format(
"SegmentOffset=0x%06X",
3244 AdvanceAmount = PointerSize;
3248 RemainingLoopCount = ImmValue - 1;
3250 RemainingLoopCount = 0;
3252 PointerSize, Count, Skip);
3255 Twine(error) +
" for opcode at: 0x" +
3262 dbgs() <<
"REBASE_OPCODE_DO_REBASE_IMM_TIMES: " 3264 <<
", AdvanceAmount=" << AdvanceAmount
3265 <<
", RemainingLoopCount=" << RemainingLoopCount
3269 AdvanceAmount = PointerSize;
3274 Twine(error) +
" for opcode at: 0x" +
3280 RemainingLoopCount = Count - 1;
3282 RemainingLoopCount = 0;
3284 PointerSize, Count, Skip);
3287 Twine(error) +
" for opcode at: 0x" +
3294 dbgs() <<
"REBASE_OPCODE_DO_REBASE_ULEB_TIMES: " 3296 <<
", AdvanceAmount=" << AdvanceAmount
3297 <<
", RemainingLoopCount=" << RemainingLoopCount
3303 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB " +
3304 Twine(error) +
" for opcode at: 0x" +
3309 AdvanceAmount = Skip + PointerSize;
3311 RemainingLoopCount = 0;
3313 PointerSize, Count, Skip);
3315 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB " +
3316 Twine(error) +
" for opcode at: 0x" +
3323 dbgs() <<
"REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB: " 3325 <<
", AdvanceAmount=" << AdvanceAmount
3326 <<
", RemainingLoopCount=" << RemainingLoopCount
3332 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_" 3334 Twine(error) +
" for opcode at: 0x" +
3340 RemainingLoopCount = Count - 1;
3342 RemainingLoopCount = 0;
3345 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_" 3347 Twine(error) +
" for opcode at: 0x" +
3352 AdvanceAmount = Skip + PointerSize;
3355 PointerSize, Count, Skip);
3357 *E =
malformedError(
"for REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_" 3359 Twine(error) +
" for opcode at: 0x" +
3366 dbgs() <<
"REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB: " 3368 <<
", AdvanceAmount=" << AdvanceAmount
3369 <<
", RemainingLoopCount=" << RemainingLoopCount
3386 if (Ptr > Opcodes.
end())
3387 Ptr = Opcodes.
end();
3400 return "text abs32";
3402 return "text rel32";
3426 #ifdef EXPENSIVE_CHECKS 3427 assert(Opcodes == Other.Opcodes &&
"compare iterators of different files");
3429 assert(Opcodes.
data() == Other.Opcodes.
data() &&
"compare iterators of different files");
3431 return (Ptr == Other.Ptr) &&
3432 (RemainingLoopCount == Other.RemainingLoopCount) &&
3433 (Done == Other.Done);
3439 if (O->BindRebaseSectionTable ==
nullptr)
3440 O->BindRebaseSectionTable = std::make_unique<BindRebaseSegInfo>(
O);
3442 Start.moveToFirst();
3451 return rebaseTable(Err,
this, getDyldInfoRebaseOpcodes(),
is64Bit());
3456 : E(E), O(O), Opcodes(Bytes), Ptr(Bytes.
begin()),
3457 PointerSize(is64Bit ? 8 : 4), TableKind(BK) {}
3459 void MachOBindEntry::moveToFirst() {
3460 Ptr = Opcodes.
begin();
3464 void MachOBindEntry::moveToEnd() {
3465 Ptr = Opcodes.
end();
3466 RemainingLoopCount = 0;
3474 if (RemainingLoopCount) {
3475 --RemainingLoopCount;
3481 if (Ptr == Opcodes.
end()) {
3488 const uint8_t *OpcodeStart = Ptr;
3489 uint8_t Byte = *Ptr++;
3492 int8_t SignExtended;
3493 const uint8_t *SymStart;
3495 const char *error =
nullptr;
3501 bool NotLastEntry =
false;
3502 for (
const uint8_t *
P = Ptr;
P < Opcodes.
end(); ++
P) {
3504 NotLastEntry =
true;
3516 *E =
malformedError(
"BIND_OPCODE_SET_DYLIB_ORDINAL_IMM not allowed in " 3517 "weak bind table for opcode at: 0x" +
3523 LibraryOrdinalSet =
true;
3525 *E =
malformedError(
"for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad " 3526 "library ordinal: " +
3527 Twine((
int)ImmValue) +
" (max " +
3529 ") for opcode at: 0x" +
3536 dbgs() <<
"BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: " 3537 <<
"Ordinal=" << Ordinal <<
"\n");
3541 *E =
malformedError(
"BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB not allowed in " 3542 "weak bind table for opcode at: 0x" +
3548 LibraryOrdinalSet =
true;
3551 Twine(error) +
" for opcode at: 0x" +
3557 *E =
malformedError(
"for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad " 3558 "library ordinal: " +
3559 Twine((
int)Ordinal) +
" (max " +
3561 ") for opcode at: 0x" +
3568 dbgs() <<
"BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: " 3569 <<
"Ordinal=" << Ordinal <<
"\n");
3573 *E =
malformedError(
"BIND_OPCODE_SET_DYLIB_SPECIAL_IMM not allowed in " 3574 "weak bind table for opcode at: 0x" +
3580 SignExtended = MachO::BIND_OPCODE_MASK | ImmValue;
3581 Ordinal = SignExtended;
3583 *E =
malformedError(
"for BIND_OPCODE_SET_DYLIB_SPECIAL_IMM unknown " 3584 "special ordinal: " +
3585 Twine((
int)Ordinal) +
" for opcode at: 0x" +
3592 LibraryOrdinalSet =
true;
3595 dbgs() <<
"BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: " 3596 <<
"Ordinal=" << Ordinal <<
"\n");
3601 while (*Ptr && (Ptr < Opcodes.
end())) {
3604 if (Ptr == Opcodes.
end()) {
3606 "for BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM " 3607 "symbol name extends past opcodes for opcode at: 0x" +
3617 dbgs() <<
"BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: " 3627 *E =
malformedError(
"for BIND_OPCODE_SET_TYPE_IMM bad bind type: " +
3628 Twine((
int)ImmValue) +
" for opcode at: 0x" +
3635 dbgs() <<
"BIND_OPCODE_SET_TYPE_IMM: " 3636 <<
"BindType=" << (
int)
BindType <<
"\n");
3639 Addend = readSLEB128(&error);
3642 " for opcode at: 0x" +
3649 dbgs() <<
"BIND_OPCODE_SET_ADDEND_SLEB: " 3650 <<
"Addend=" << Addend <<
"\n");
3653 SegmentIndex = ImmValue;
3656 *E =
malformedError(
"for BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
3657 Twine(error) +
" for opcode at: 0x" +
3665 *E =
malformedError(
"for BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB " +
3666 Twine(error) +
" for opcode at: 0x" +
3673 dbgs() <<
"BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: " 3674 <<
"SegmentIndex=" << SegmentIndex <<
", " 3682 " for opcode at: 0x" +
3691 " for opcode at: 0x" +
3697 dbgs() <<
"BIND_OPCODE_ADD_ADDR_ULEB: " 3698 <<
format(
"SegmentOffset=0x%06X",
3702 AdvanceAmount = PointerSize;
3703 RemainingLoopCount = 0;
3708 " for opcode at: 0x" +
3715 "for BIND_OPCODE_DO_BIND missing preceding " 3716 "BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for opcode at: 0x" +
3721 if (!LibraryOrdinalSet && TableKind !=
Kind::Weak) {
3724 "BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode at: 0x" +
3730 dbgs() <<
"BIND_OPCODE_DO_BIND: " 3731 <<
format(
"SegmentOffset=0x%06X",
3736 *E =
malformedError(
"BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB not allowed in " 3737 "lazy bind table for opcode at: 0x" +
3746 Twine(error) +
" for opcode at: 0x" +
3753 "for BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB missing " 3754 "preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for opcode " 3760 if (!LibraryOrdinalSet && TableKind !=
Kind::Weak) {
3762 "for BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB missing " 3763 "preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode at: 0x" +
3768 AdvanceAmount =
readULEB128(&error) + PointerSize;
3771 Twine(error) +
" for opcode at: 0x" +
3780 AdvanceAmount, PointerSize);
3782 *E =
malformedError(
"for BIND_OPCODE_ADD_ADDR_ULEB (after adding " 3784 Twine(error) +
" for opcode at: 0x" +
3789 RemainingLoopCount = 0;
3792 dbgs() <<
"BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: " 3794 <<
", AdvanceAmount=" << AdvanceAmount
3795 <<
", RemainingLoopCount=" << RemainingLoopCount
3800 *E =
malformedError(
"BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED not " 3801 "allowed in lazy bind table for opcode at: 0x" +
3809 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " +
3810 Twine(error) +
" for opcode at: 0x" +
3817 "for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " 3818 "missing preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for " 3824 if (!LibraryOrdinalSet && TableKind !=
Kind::Weak) {
3826 "for BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED " 3827 "missing preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode " 3833 AdvanceAmount = ImmValue * PointerSize + PointerSize;
3834 RemainingLoopCount = 0;
3836 AdvanceAmount, PointerSize);
3840 " (after adding immediate times the pointer size) " +
3841 Twine(error) +
" for opcode at: 0x" +
3848 <<
"BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: " 3853 *E =
malformedError(
"BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB not " 3854 "allowed in lazy bind table for opcode at: 0x" +
3861 RemainingLoopCount = Count - 1;
3863 RemainingLoopCount = 0;
3865 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB " 3867 Twine(error) +
" for opcode at: 0x" +
3873 AdvanceAmount = Skip + PointerSize;
3875 *E =
malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB " 3877 Twine(error) +
" for opcode at: 0x" +
3884 "for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB " 3885 "missing preceding BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM for " 3891 if (!LibraryOrdinalSet && TableKind !=
Kind::Weak) {
3893 "for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB " 3894 "missing preceding BIND_OPCODE_SET_DYLIB_ORDINAL_* for opcode " 3901 PointerSize, Count, Skip);
3904 malformedError(
"for BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB " +
3905 Twine(error) +
" for opcode at: 0x" +
3912 dbgs() <<
"BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: " 3914 <<
", AdvanceAmount=" << AdvanceAmount
3915 <<
", RemainingLoopCount=" << RemainingLoopCount
3932 if (Ptr > Opcodes.
end())
3933 Ptr = Opcodes.
end();
3937 int64_t MachOBindEntry::readSLEB128(
const char **error) {
3941 if (Ptr > Opcodes.
end())
3942 Ptr = Opcodes.
end();
3955 return "text abs32";
3957 return "text rel32";
3989 #ifdef EXPENSIVE_CHECKS 3990 assert(Opcodes == Other.Opcodes &&
"compare iterators of different files");
3992 assert(Opcodes.
data() == Other.Opcodes.
data() &&
"compare iterators of different files");
3994 return (Ptr == Other.Ptr) &&
3995 (RemainingLoopCount == Other.RemainingLoopCount) &&
3996 (Done == Other.Done);
4003 uint64_t CurSegAddress;
4010 Info.SectionName = *NameOrErr;
4011 Info.Address =
Section.getAddress();
4012 Info.Size =
Section.getSize();
4015 if (!Info.SegmentName.equals(CurSegName)) {
4017 CurSegName = Info.SegmentName;
4018 CurSegAddress = Info.Address;
4020 Info.SegmentIndex = CurSegIndex - 1;
4021 Info.OffsetInSegment = Info.Address - CurSegAddress;
4022 Info.SegmentStartAddress = CurSegAddress;
4023 Sections.push_back(Info);
4025 MaxSegIndex = CurSegIndex;
4037 uint8_t PointerSize,
4041 return "missing preceding *_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB";
4042 if (SegIndex >= MaxSegIndex)
4043 return "bad segIndex (too large)";
4044 for (
uint32_t i = 0; i < Count; ++i) {
4045 uint32_t Start = SegOffset + i * (PointerSize + Skip);
4046 uint32_t End = Start + PointerSize;
4048 for (
const SectionInfo &
SI : Sections) {
4049 if (
SI.SegmentIndex != SegIndex)
4051 if ((
SI.OffsetInSegment<=Start) && (Start<(
SI.OffsetInSegment+
SI.Size))) {
4052 if (End <=
SI.OffsetInSegment +
SI.Size) {
4057 return "bad offset, extends beyond section boundary";
4061 return "bad offset, not in section";
4069 for (
const SectionInfo &
SI : Sections) {
4070 if (
SI.SegmentIndex == SegIndex)
4071 return SI.SegmentName;
4078 const BindRebaseSegInfo::SectionInfo &BindRebaseSegInfo::findSection(
4079 int32_t SegIndex, uint64_t SegOffset) {
4080 for (
const SectionInfo &
SI : Sections) {
4081 if (
SI.SegmentIndex != SegIndex)
4083 if (
SI.OffsetInSegment > SegOffset)
4085 if (SegOffset >= (
SI.OffsetInSegment +
SI.Size))
4095 uint64_t SegOffset) {
4096 return findSection(SegIndex, SegOffset).SectionName;
4102 const SectionInfo &
SI = findSection(SegIndex, OffsetInSeg);
4103 return SI.SegmentStartAddress + OffsetInSeg;
4110 if (O->BindRebaseSectionTable ==
nullptr)
4111 O->BindRebaseSectionTable = std::make_unique<BindRebaseSegInfo>(
O);
4113 Start.moveToFirst();
4122 return bindTable(Err,
this, getDyldInfoBindOpcodes(),
is64Bit(),
4127 return bindTable(Err,
this, getDyldInfoLazyBindOpcodes(),
is64Bit(),
4132 return bindTable(Err,
this, getDyldInfoWeakBindOpcodes(),
is64Bit(),
4138 return LoadCommands.begin();
4143 return LoadCommands.end();
4148 return make_range(begin_load_commands(), end_load_commands());
4159 assert(Sec.
d.
a < Sections.size() &&
"Should have detected this earlier");
4160 const section_base *
Base =
4161 reinterpret_cast<const section_base *
>(Sections[Sec.
d.
a]);
4167 assert(Sec.
d.
a < Sections.size() &&
"Should have detected this earlier");
4168 const section_base *
Base =
4169 reinterpret_cast<const section_base *
>(Sections[Sec.
d.
a]);
4183 if (isLittleEndian())
4190 if (isLittleEndian())
4191 return (RE.
r_word1 >> 27) & 1;
4207 return (RE.
r_word0 >> 24) & 0xf;
4212 if (isRelocationScattered(RE))
4219 if (isRelocationScattered(RE))
4226 if (isRelocationScattered(RE))
4234 if (isRelocationScattered(RE))
4235 return getScatteredRelocationType(RE);
4242 if (isRelocationScattered(RE) || getPlainRelocationExternal(RE))
4243 return *section_end();
4244 unsigned SecNum = getPlainRelocationSymbolNum(RE);
4245 if (SecNum ==
MachO::R_ABS || SecNum > Sections.size())
4246 return *section_end();
4248 DRI.
d.
a = SecNum - 1;
4253 assert(DRI.
d.
a < Sections.size() &&
"Should have detected this earlier");
4254 return getStruct<MachO::section>(*
this, Sections[DRI.
d.
a]);
4258 assert(DRI.
d.
a < Sections.size() &&
"Should have detected this earlier");
4259 return getStruct<MachO::section_64>(*
this, Sections[DRI.
d.
a]);
4263 unsigned Index)
const {
4265 return getStruct<MachO::section>(*
this, Sec);
4269 unsigned Index)
const {
4271 return getStruct<MachO::section_64>(*
this, Sec);
4276 const char *
P =
reinterpret_cast<const char *
>(DRI.
p);
4277 return getStruct<MachO::nlist>(*
this,
P);
4282 const char *
P =
reinterpret_cast<const char *
>(DRI.
p);
4283 return getStruct<MachO::nlist_64>(*
this,
P);
4288 return getStruct<MachO::linkedit_data_command>(*
this, L.
Ptr);
4293 return getStruct<MachO::segment_command>(*
this, L.
Ptr);
4298 return getStruct<MachO::segment_command_64>(*
this, L.
Ptr);
4303 return getStruct<MachO::linker_option_command>(*
this, L.
Ptr);
4308 return getStruct<MachO::version_min_command>(*
this, L.
Ptr);
4313 return getStruct<MachO::note_command>(*
this, L.
Ptr);
4318 return getStruct<MachO::build_version_command>(*
this, L.
Ptr);
4323 return getStruct<MachO::build_tool_version>(*
this, BuildTools[index]);
4328 return getStruct<MachO::dylib_command>(*
this, L.
Ptr);
4333 return getStruct<MachO::dyld_info_command>(*
this, L.
Ptr);
4338 return getStruct<MachO::dylinker_command>(*
this, L.
Ptr);
4343 return getStruct<MachO::uuid_command>(*
this, L.
Ptr);
4348 return getStruct<MachO::rpath_command>(*
this, L.
Ptr);
4353 return getStruct<MachO::source_version_command>(*
this, L.
Ptr);
4358 return getStruct<MachO::entry_point_command>(*
this, L.
Ptr);
4363 return getStruct<MachO::encryption_info_command>(*
this, L.
Ptr);
4368 return getStruct<MachO::encryption_info_command_64>(*
this, L.
Ptr);
4373 return getStruct<MachO::sub_framework_command>(*
this, L.
Ptr);
4378 return getStruct<MachO::sub_umbrella_command>(*
this, L.
Ptr);
4383 return getStruct<MachO::sub_library_command>(*
this, L.
Ptr);
4388 return getStruct<MachO::sub_client_command>(*
this, L.
Ptr);
4393 return getStruct<MachO::routines_command>(*
this, L.
Ptr);
4398 return getStruct<MachO::routines_command_64>(*
this, L.
Ptr);
4403 return getStruct<MachO::thread_command>(*
this, L.
Ptr);
4429 return getStruct<MachO::any_relocation_info>(
4430 *
this, reinterpret_cast<const char *>(
P));
4435 const char *
P =
reinterpret_cast<const char *
>(Rel.
p);
4436 return getStruct<MachO::data_in_code_entry>(*
this,
P);
4450 unsigned Index)
const {
4452 return getStruct<uint32_t>(*
this,
getPtr(*
this, Offset));
4457 unsigned Index)
const {
4459 return getStruct<MachO::data_in_code_entry>(*
this,
getPtr(*
this, Offset));
4464 return getStruct<MachO::symtab_command>(*
this, SymtabLoadCmd);
4468 Cmd.
cmd = MachO::LC_SYMTAB;
4478 if (DysymtabLoadCmd)
4479 return getStruct<MachO::dysymtab_command>(*
this, DysymtabLoadCmd);
4483 Cmd.
cmd = MachO::LC_DYSYMTAB;
4495 Cmd.extrefsymoff = 0;
4496 Cmd.nextrefsyms = 0;
4497 Cmd.indirectsymoff = 0;
4498 Cmd.nindirectsyms = 0;
4508 if (DataInCodeLoadCmd)
4509 return getStruct<MachO::linkedit_data_command>(*
this, DataInCodeLoadCmd);
4513 Cmd.
cmd = MachO::LC_DATA_IN_CODE;
4522 if (LinkOptHintsLoadCmd)
4523 return getStruct<MachO::linkedit_data_command>(*
this, LinkOptHintsLoadCmd);
4528 Cmd.
cmd = MachO::LC_LINKER_OPTIMIZATION_HINT;
4536 if (!DyldInfoLoadCmd)
4539 auto DyldInfoOrErr =
4540 getStructOrErr<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4544 const uint8_t *Ptr =
4550 if (!DyldInfoLoadCmd)
4553 auto DyldInfoOrErr =
4554 getStructOrErr<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4558 const uint8_t *Ptr =
4559 reinterpret_cast<const uint8_t *
>(
getPtr(*
this, DyldInfo.
bind_off));
4564 if (!DyldInfoLoadCmd)
4567 auto DyldInfoOrErr =
4568 getStructOrErr<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4572 const uint8_t *Ptr =
4578 if (!DyldInfoLoadCmd)
4581 auto DyldInfoOrErr =
4582 getStructOrErr<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4586 const uint8_t *Ptr =
4592 if (!DyldInfoLoadCmd)
4595 auto DyldInfoOrErr =
4596 getStructOrErr<MachO::dyld_info_command>(*
this, DyldInfoLoadCmd);
4600 const uint8_t *Ptr =
4610 return makeArrayRef(reinterpret_cast<const uint8_t *>(Ptr), 16);
4619 return getType() == getMachOType(
false,
true) ||
4620 getType() == getMachOType(
true,
true);
4627 uint64_t offset =
Index;
4629 while (uint64_t delta = extractor.
getULEB128(&offset)) {
4644 if (Magic ==
"\xFE\xED\xFA\xCE")
4646 UniversalCputype, UniversalIndex);
4647 if (Magic ==
"\xCE\xFA\xED\xFE")
4649 UniversalCputype, UniversalIndex);
4650 if (Magic ==
"\xFE\xED\xFA\xCF")
4652 UniversalCputype, UniversalIndex);
4653 if (Magic ==
"\xCF\xFA\xED\xFE")
4655 UniversalCputype, UniversalIndex);
4656 return make_error<GenericBinaryError>(
"Unrecognized MachO magic number",
4662 .Case(
"debug_str_offs",
"debug_str_offsets")
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
content_iterator< ExportEntry > export_iterator
relocation_iterator locrel_end() const
static unsigned getScatteredRelocationLength(const MachO::any_relocation_info &RE)
MachO::linkedit_data_command getLinkeditDataLoadCommand(const LoadCommandInfo &L) const
MachO::segment_command getSegmentLoadCommand(const LoadCommandInfo &L) const
const_iterator end(StringRef path)
Get end iterator over path.
void swapStruct(fat_header &mh)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const uint32_t x86_FLOAT_STATE_COUNT
static uint64_t getSymbolValue(const MCSymbol &Symbol, const MCAsmLayout &Layout)
static bool getScatteredRelocationPCRel(const MachO::any_relocation_info &RE)
MachO::symtab_command getSymtabLoadCommand() const
unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const
static const char * getSectionPtr(const MachOObjectFile &O, MachOObjectFile::LoadCommandInfo L, unsigned Sec)
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
void swapByteOrder(T &Value)
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...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
const uint32_t x86_EXCEPTION_STATE64_COUNT
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 Error parseBuildVersionCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, SmallVectorImpl< const char *> &BuildTools, uint32_t LoadCommandIndex)
StringRef sectionName() const
int32_t segmentIndex() const
MachO::encryption_info_command getEncryptionInfoCommand(const LoadCommandInfo &L) const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
StringRef getFileFormatName() const override
uint64_t getRelocationOffset(DataRefImpl Rel) const override
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
bool isSectionVirtual(DataRefImpl Sec) const override
const MachO::mach_header_64 & getHeader64() const
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void moveRelocationNext(DataRefImpl &Rel) const override
ExportEntry encapsulates the current-state-of-the-walk used when doing a non-recursive walk of the tr...
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
void push_back(const T &Elt)
static unsigned getCPUSubType(const MachOObjectFile &O)
static Error checkOverlappingElement(std::list< MachOElement > &Elements, uint64_t Offset, uint64_t Size, const char *Name)
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)
uint32_t getLibraryCount() const
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Optional< std::vector< StOtherPiece > > Other
static const char * getPtr(const MachOObjectFile &O, size_t Offset)
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
bool hasPageZeroSegment() const
Expected< SectionRef > getSection(unsigned SectionIndex) const
static Triple getHostArch()
This class is the base class for all object file types.
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const
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
ArrayRef< uint8_t > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
static StringRef parseSegmentOrSectionName(const char *P)
unsigned getSectionType(SectionRef Sec) const
static uint32_t getSectionFlags(const MachOObjectFile &O, DataRefImpl Sec)
uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc)
MachORebaseEntry encapsulates the current state in the decompression of rebasing opcodes.
uint64_t getSectionAlignment(DataRefImpl Sec) const override
MachO::linkedit_data_command getLinkOptHintsLoadCommand() const
StringRef getSectionFinalSegmentName(DataRefImpl Sec) const
Error takeError()
Take ownership of the stored error.
MachO::dylinker_command getDylinkerCommand(const LoadCommandInfo &L) const
MachO::uuid_command getUuidCommand(const LoadCommandInfo &L) const
bool operator==(const MachOBindEntry &) const
static uint32_t getPlainRelocationAddress(const MachO::any_relocation_info &RE)
uint8_t GET_COMM_ALIGN(uint16_t n_desc)
dice_iterator begin_dices() const
static ArrayRef< StringRef > getValidArchs()
bool isSectionBitcode(DataRefImpl Sec) const override
static unsigned getPlainRelocationLength(const MachOObjectFile &O, const MachO::any_relocation_info &RE)
MachO::thread_command getThreadCommand(const LoadCommandInfo &L) const
#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
StringRef segmentName() const
static Expected< MachOObjectFile::LoadCommandInfo > getNextLoadCommandInfo(const MachOObjectFile &Obj, uint32_t LoadCommandIndex, const MachOObjectFile::LoadCommandInfo &L)
basic_symbol_iterator symbol_begin() const override
static Error checkRpathCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex)
const uint32_t ARM_THREAD_STATE_COUNT
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
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.
DataRefImpl getRawDataRefImpl() const
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
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 getBuffer() const
MachO::sub_library_command getSubLibraryCommand(const LoadCommandInfo &L) const
This is a value type class that represents a single relocation in the list of relocations in the obje...
LLVM_NODISCARD R Default(T Value)
int32_t segmentIndex() const
MachO::linker_option_command getLinkerOptionLoadCommand(const LoadCommandInfo &L) const
Error checkSymbolTable() const
LLVM_NODISCARD StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
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)
MachOBindEntry encapsulates the current state in the decompression of binding opcodes.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
MachO::dyld_info_command getDyldInfoLoadCommand(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)
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Triple::ArchType getArch() const override
static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx)
load_command_iterator begin_load_commands() const
content_iterator< SectionRef > section_iterator
static const bool IsLittleEndianHost
StringRef getStringTableData() const
MachO::build_version_command getBuildVersionLoadCommand(const LoadCommandInfo &L) const
content_iterator< DiceRef > dice_iterator
SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const
static unsigned getCPUType(const MachOObjectFile &O)
symbol_iterator getSymbolByIndex(unsigned Index) 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)
unsigned getSectionID(SectionRef Sec) const
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)...
iterator_range< export_iterator > exports(Error &Err) const
For use iterating over all exported symbols.
LLVM_NODISCARD size_t size() const
size - Get the string size.
section_iterator_range sections() const
MachO::encryption_info_command_64 getEncryptionInfoCommand64(const LoadCommandInfo &L) const
content_iterator< MachOBindEntry > bind_iterator
MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const
basic_symbol_iterator symbol_end() const override
uint64_t segmentOffset() const
Analysis containing CSE Info
section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const
const char * BindEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint32_t Count=1, uint32_t Skip=0) const
static bool isLoadCommandObsolete(uint32_t cmd)
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
MachO::sub_framework_command getSubFrameworkCommand(const LoadCommandInfo &L) const
static Error checkDylibIdCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd)
void moveSectionNext(DataRefImpl &Sec) const override
struct llvm::object::DataRefImpl::@292 d
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
MachO::rpath_command getRpathCommand(const LoadCommandInfo &L) const
StringRef otherName() const
MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const
const char * checkSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint32_t Count=1, uint32_t Skip=0)
static Error checkDyldCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
StringRef typeName() const
A switch()-like statement whose cases are string literals.
bool isSectionCompressed(DataRefImpl Sec) const override
Unify divergent function exit nodes
static Error checkSymtabCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **SymtabLoadCmd, std::list< MachOElement > &Elements)
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).
static Constant * SegmentOffset(IRBuilder<> &IRB, unsigned Offset, unsigned AddressSpace)
relocation_iterator locrel_begin() const
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...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
ArrayRef< uint8_t > getDyldInfoRebaseOpcodes() const
const uint32_t x86_THREAD_STATE64_COUNT
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
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)
static MachO::nlist_base getSymbolTableEntryBase(const MachOObjectFile &O, DataRefImpl DRI)
#define offsetof(TYPE, MEMBER)
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
unsigned getSymbolSectionID(SymbolRef Symb) const
MachO::sub_client_command getSubClientCommand(const LoadCommandInfo &L) const
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.
static T getStruct(const MachOObjectFile &O, const char *P)
MachO::linkedit_data_command getDataInCodeLoadCommand() const
section_iterator getRelocationSection(DataRefImpl Rel) const
const char * RebaseEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint32_t Count=1, uint32_t Skip=0) const
DiceRef - This is a value type class that represents a single data in code entry in the table in a Ma...
DataRefImpl getRawDataRefImpl() const
void consumeError(Error Err)
Consume a Error without doing anything.
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
bool equals(StringRef RHS) const
Check for string equality.
static wasm::ValType getType(const TargetRegisterClass *RC)
MachO::dylib_command getDylibIDLoadCommand(const LoadCommandInfo &L) const
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
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)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Error checkThreadCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
Triple - Helper class for working with autoconf configuration names.
StringRef typeName() const
static const char *const Magic
relocation_iterator extrel_end() const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
MachO::version_min_command getVersionMinLoadCommand(const LoadCommandInfo &L) const
void moveSymbolNext(DataRefImpl &Symb) const override
static ErrorSuccess success()
Create a success value.
static Error checkTwoLevelHintsCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, std::list< MachOElement > &Elements)
bool isSectionData(DataRefImpl Sec) const override
uint32_t nodeOffset() const
static Expected< MachOObjectFile::LoadCommandInfo > getFirstLoadCommandInfo(const MachOObjectFile &Obj)
Align max(MaybeAlign Lhs, Align Rhs)
static Expected< std::unique_ptr< MachOObjectFile > > createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0)
static Expected< T > getStructOrErr(const MachOObjectFile &O, const char *P)
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
MachO::build_tool_version getBuildToolVersion(unsigned index) const
ArrayRef< uint8_t > getUuid() const
ArrayRef< uint8_t > getDyldInfoLazyBindOpcodes() const
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
BindRebaseSegInfo(const MachOObjectFile *Obj)
static Twine utohexstr(const uint64_t &Val)
uint64_t getNValue(DataRefImpl Sym) const
load_command_iterator end_load_commands() const
const uint32_t x86_THREAD_STATE_COUNT
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
MachO::data_in_code_entry getDice(DataRefImpl Rel) const
Triple getArchTriple(const char **McpuDefault=nullptr) 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
A range adaptor for a pair of iterators.
const uint32_t x86_EXCEPTION_STATE_COUNT
static unsigned getScatteredRelocationAddress(const MachO::any_relocation_info &RE)
bool operator==(const MachORebaseEntry &) const
uint64_t segmentOffset() const
iterator_range< bind_iterator > bindTable(Error &Err)
For use iterating over all bind table entries.
Helper for Errors used as out-parameters.
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)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static Expected< std::unique_ptr< MachOObjectFile > > create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0)
StringRef sectionName() const
static Error checkNoteCommand(const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, std::list< MachOElement > &Elements)
ArrayRef< uint8_t > getDyldInfoBindOpcodes() const
MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset, unsigned Index) const
LLVM_NODISCARD bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
MachO::source_version_command getSourceVersionCommand(const LoadCommandInfo &L) const
relocation_iterator extrel_begin() const
static Expected< MachOObjectFile::LoadCommandInfo > getLoadCommandInfo(const MachOObjectFile &Obj, const char *Ptr, uint32_t LoadCommandIndex)
ArrayRef< char > getSectionRawFinalSegmentName(DataRefImpl Sec) const
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
dice_iterator end_dices() const
uint8_t getRelocationLength(DataRefImpl Rel) const
MachO::section_64 getSection64(DataRefImpl DRI) const
static StringRef guessLibraryShortName(StringRef Name, bool &isFramework, StringRef &Suffix)
uint64_t address(uint32_t SegIndex, uint64_t SegOffset)
ArrayRef< uint8_t > getDyldInfoWeakBindOpcodes() const
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
void ReadULEB128s(uint64_t Index, SmallVectorImpl< uint64_t > &Out) const
LLVM_NODISCARD bool empty() const
MachO::entry_point_command getEntryPointCommand(const LoadCommandInfo &L) const
StringRef segmentName(int32_t SegIndex)
unsigned getPlainRelocationSymbolNum(const MachO::any_relocation_info &RE) const
content_iterator< MachORebaseEntry > rebase_iterator
const MachO::mach_header & getHeader() const
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 ...
MachO::note_command getNoteLoadCommand(const LoadCommandInfo &L) const
ExportEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Trie)
StringRef symbolName() const
MachO::routines_command getRoutinesCommand(const LoadCommandInfo &L) 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
iterator_range< load_command_iterator > load_commands() const
MachO::routines_command_64 getRoutinesCommand64(const LoadCommandInfo &L) const
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
ArrayRef< char > getSectionRawName(DataRefImpl Sec) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachO::segment_command_64 getSegment64LoadCommand(const LoadCommandInfo &L) const
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
MachO::sub_umbrella_command getSubUmbrellaCommand(const LoadCommandInfo &L) const
LoadCommandList::const_iterator load_command_iterator
bool isSectionStripped(DataRefImpl Sec) const override
When dsymutil generates the companion file, it strips all unnecessary sections (e.g.
Lightweight error class with error context and mandatory checking.
const uint32_t ARM_THREAD_STATE64_COUNT
std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const
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)
StringRef segmentName() const
StringRef - Represent a constant reference to a string, i.e.
uint64_t getSymbolIndex(DataRefImpl Symb) const
S_ZEROFILL - Zero fill on demand section.
bool getScatteredRelocationScattered(const MachO::any_relocation_info &RE) const
StringRef sectionName(int32_t SegIndex, uint64_t SegOffset)
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
SectionType
These are the section type and attributes fields.
ArrayRef< uint8_t > getDyldInfoExportsTrie() const
uint32_t getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
static Error malformedError(const Twine &Msg)
StringRef getData() const
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
ArrayRef< uint8_t > getSectionContents(uint32_t Offset, uint64_t Size) const
static bool is64Bit(const char *name)
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
const uint32_t PPC_THREAD_STATE_COUNT
bool operator==(const ExportEntry &) const
bool empty() const
empty - Check if the array is empty.
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)
MachO::dysymtab_command getDysymtabLoadCommand() const
uint64_t getSectionSize(DataRefImpl Sec) const override
uint32_t getScatteredRelocationType(const MachO::any_relocation_info &RE) const