1 //===- MachOObjectFile.cpp - Mach-O object file binding ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the MachOObjectFile class, which binds the MachOObject
11 // class to the generic ObjectFile wrapper.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/Object/MachO.h"
17 #include "llvm/Object/MachOFormat.h"
18 #include "llvm/Support/MemoryBuffer.h"
25 using namespace object;
30 MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO,
32 : ObjectFile(Binary::isMachO, Object, ec),
34 RegisteredStringTable(std::numeric_limits<uint32_t>::max()) {
36 DRI.d.a = DRI.d.b = 0;
37 moveToNextSection(DRI);
38 uint32_t LoadCommandCount = MachOObj->getHeader().NumLoadCommands;
39 while (DRI.d.a < LoadCommandCount) {
40 Sections.push_back(DRI);
42 moveToNextSection(DRI);
47 ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
50 MachOObject *MachOObj = MachOObject::LoadFromBuffer(Buffer, &Err);
53 return new MachOObjectFile(Buffer, MachOObj, ec);
56 /*===-- Symbols -----------------------------------------------------------===*/
58 void MachOObjectFile::moveToNextSymbol(DataRefImpl &DRI) const {
59 uint32_t LoadCommandCount = MachOObj->getHeader().NumLoadCommands;
60 while (DRI.d.a < LoadCommandCount) {
61 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
62 if (LCI.Command.Type == macho::LCT_Symtab) {
63 InMemoryStruct<macho::SymtabLoadCommand> SymtabLoadCmd;
64 MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd);
65 if (DRI.d.b < SymtabLoadCmd->NumSymbolTableEntries)
74 void MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI,
75 InMemoryStruct<macho::SymbolTableEntry> &Res) const {
76 InMemoryStruct<macho::SymtabLoadCommand> SymtabLoadCmd;
77 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
78 MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd);
80 if (RegisteredStringTable != DRI.d.a) {
81 MachOObj->RegisterStringTable(*SymtabLoadCmd);
82 RegisteredStringTable = DRI.d.a;
85 MachOObj->ReadSymbolTableEntry(SymtabLoadCmd->SymbolTableOffset, DRI.d.b,
89 void MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI,
90 InMemoryStruct<macho::Symbol64TableEntry> &Res) const {
91 InMemoryStruct<macho::SymtabLoadCommand> SymtabLoadCmd;
92 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
93 MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd);
95 if (RegisteredStringTable != DRI.d.a) {
96 MachOObj->RegisterStringTable(*SymtabLoadCmd);
97 RegisteredStringTable = DRI.d.a;
100 MachOObj->ReadSymbol64TableEntry(SymtabLoadCmd->SymbolTableOffset, DRI.d.b,
105 error_code MachOObjectFile::getSymbolNext(DataRefImpl DRI,
106 SymbolRef &Result) const {
108 moveToNextSymbol(DRI);
109 Result = SymbolRef(DRI, this);
110 return object_error::success;
113 error_code MachOObjectFile::getSymbolName(DataRefImpl DRI,
114 StringRef &Result) const {
115 if (MachOObj->is64Bit()) {
116 InMemoryStruct<macho::Symbol64TableEntry> Entry;
117 getSymbol64TableEntry(DRI, Entry);
118 Result = MachOObj->getStringAtIndex(Entry->StringIndex);
120 InMemoryStruct<macho::SymbolTableEntry> Entry;
121 getSymbolTableEntry(DRI, Entry);
122 Result = MachOObj->getStringAtIndex(Entry->StringIndex);
124 return object_error::success;
127 error_code MachOObjectFile::getSymbolOffset(DataRefImpl DRI,
128 uint64_t &Result) const {
129 uint64_t SectionOffset;
130 uint8_t SectionIndex;
131 if (MachOObj->is64Bit()) {
132 InMemoryStruct<macho::Symbol64TableEntry> Entry;
133 getSymbol64TableEntry(DRI, Entry);
134 Result = Entry->Value;
135 SectionIndex = Entry->SectionIndex;
137 InMemoryStruct<macho::SymbolTableEntry> Entry;
138 getSymbolTableEntry(DRI, Entry);
139 Result = Entry->Value;
140 SectionIndex = Entry->SectionIndex;
142 getSectionAddress(Sections[SectionIndex-1], SectionOffset);
143 Result -= SectionOffset;
145 return object_error::success;
148 error_code MachOObjectFile::getSymbolAddress(DataRefImpl DRI,
149 uint64_t &Result) const {
150 if (MachOObj->is64Bit()) {
151 InMemoryStruct<macho::Symbol64TableEntry> Entry;
152 getSymbol64TableEntry(DRI, Entry);
153 Result = Entry->Value;
155 InMemoryStruct<macho::SymbolTableEntry> Entry;
156 getSymbolTableEntry(DRI, Entry);
157 Result = Entry->Value;
159 return object_error::success;
162 error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI,
163 uint64_t &Result) const {
164 Result = UnknownAddressOrSize;
165 return object_error::success;
168 error_code MachOObjectFile::getSymbolNMTypeChar(DataRefImpl DRI,
169 char &Result) const {
171 if (MachOObj->is64Bit()) {
172 InMemoryStruct<macho::Symbol64TableEntry> Entry;
173 getSymbol64TableEntry(DRI, Entry);
175 Flags = Entry->Flags;
177 InMemoryStruct<macho::SymbolTableEntry> Entry;
178 getSymbolTableEntry(DRI, Entry);
180 Flags = Entry->Flags;
184 switch (Type & macho::STF_TypeMask) {
185 case macho::STT_Undefined:
188 case macho::STT_Absolute:
189 case macho::STT_Section:
197 if (Flags & (macho::STF_External | macho::STF_PrivateExtern))
198 Char = toupper(Char);
200 return object_error::success;
203 error_code MachOObjectFile::isSymbolInternal(DataRefImpl DRI,
204 bool &Result) const {
205 if (MachOObj->is64Bit()) {
206 InMemoryStruct<macho::Symbol64TableEntry> Entry;
207 getSymbol64TableEntry(DRI, Entry);
208 Result = Entry->Flags & macho::STF_StabsEntryMask;
210 InMemoryStruct<macho::SymbolTableEntry> Entry;
211 getSymbolTableEntry(DRI, Entry);
212 Result = Entry->Flags & macho::STF_StabsEntryMask;
214 return object_error::success;
217 error_code MachOObjectFile::isSymbolGlobal(DataRefImpl Symb, bool &Res) const {
219 if (MachOObj->is64Bit()) {
220 InMemoryStruct<macho::Symbol64TableEntry> Entry;
221 getSymbol64TableEntry(Symb, Entry);
222 Res = Entry->Type & MachO::NlistMaskExternal;
224 InMemoryStruct<macho::SymbolTableEntry> Entry;
225 getSymbolTableEntry(Symb, Entry);
226 Res = Entry->Type & MachO::NlistMaskExternal;
228 return object_error::success;
231 error_code MachOObjectFile::isSymbolWeak(DataRefImpl Symb, bool &Res) const {
233 if (MachOObj->is64Bit()) {
234 InMemoryStruct<macho::Symbol64TableEntry> Entry;
235 getSymbol64TableEntry(Symb, Entry);
236 Res = Entry->Flags & (MachO::NListDescWeakRef | MachO::NListDescWeakDef);
238 InMemoryStruct<macho::SymbolTableEntry> Entry;
239 getSymbolTableEntry(Symb, Entry);
240 Res = Entry->Flags & (MachO::NListDescWeakRef | MachO::NListDescWeakDef);
242 return object_error::success;
245 error_code MachOObjectFile::isSymbolAbsolute(DataRefImpl Symb, bool &Res) const{
247 if (MachOObj->is64Bit()) {
248 InMemoryStruct<macho::Symbol64TableEntry> Entry;
249 getSymbol64TableEntry(Symb, Entry);
250 n_type = Entry->Type;
252 InMemoryStruct<macho::SymbolTableEntry> Entry;
253 getSymbolTableEntry(Symb, Entry);
254 n_type = Entry->Type;
257 Res = (n_type & MachO::NlistMaskType) == MachO::NListTypeAbsolute;
258 return object_error::success;
261 error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb,
262 section_iterator &Res) const {
264 if (MachOObj->is64Bit()) {
265 InMemoryStruct<macho::Symbol64TableEntry> Entry;
266 getSymbol64TableEntry(Symb, Entry);
267 index = Entry->SectionIndex;
269 InMemoryStruct<macho::SymbolTableEntry> Entry;
270 getSymbolTableEntry(Symb, Entry);
271 index = Entry->SectionIndex;
275 Res = end_sections();
277 Res = section_iterator(SectionRef(Sections[index], this));
279 return object_error::success;
282 error_code MachOObjectFile::getSymbolType(DataRefImpl Symb,
283 SymbolRef::Type &Res) const {
285 if (MachOObj->is64Bit()) {
286 InMemoryStruct<macho::Symbol64TableEntry> Entry;
287 getSymbol64TableEntry(Symb, Entry);
288 n_type = Entry->Type;
290 InMemoryStruct<macho::SymbolTableEntry> Entry;
291 getSymbolTableEntry(Symb, Entry);
292 n_type = Entry->Type;
294 Res = SymbolRef::ST_Other;
296 // If this is a STAB debugging symbol, we can do nothing more.
297 if (n_type & MachO::NlistMaskStab) {
298 Res = SymbolRef::ST_Debug;
299 return object_error::success;
302 switch (n_type & MachO::NlistMaskType) {
303 case MachO::NListTypeUndefined :
304 Res = SymbolRef::ST_External;
306 case MachO::NListTypeSection :
307 Res = SymbolRef::ST_Function;
310 return object_error::success;
314 symbol_iterator MachOObjectFile::begin_symbols() const {
315 // DRI.d.a = segment number; DRI.d.b = symbol index.
317 DRI.d.a = DRI.d.b = 0;
318 moveToNextSymbol(DRI);
319 return symbol_iterator(SymbolRef(DRI, this));
322 symbol_iterator MachOObjectFile::end_symbols() const {
324 DRI.d.a = MachOObj->getHeader().NumLoadCommands;
326 return symbol_iterator(SymbolRef(DRI, this));
330 /*===-- Sections ----------------------------------------------------------===*/
332 void MachOObjectFile::moveToNextSection(DataRefImpl &DRI) const {
333 uint32_t LoadCommandCount = MachOObj->getHeader().NumLoadCommands;
334 while (DRI.d.a < LoadCommandCount) {
335 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
336 if (LCI.Command.Type == macho::LCT_Segment) {
337 InMemoryStruct<macho::SegmentLoadCommand> SegmentLoadCmd;
338 MachOObj->ReadSegmentLoadCommand(LCI, SegmentLoadCmd);
339 if (DRI.d.b < SegmentLoadCmd->NumSections)
341 } else if (LCI.Command.Type == macho::LCT_Segment64) {
342 InMemoryStruct<macho::Segment64LoadCommand> Segment64LoadCmd;
343 MachOObj->ReadSegment64LoadCommand(LCI, Segment64LoadCmd);
344 if (DRI.d.b < Segment64LoadCmd->NumSections)
353 error_code MachOObjectFile::getSectionNext(DataRefImpl DRI,
354 SectionRef &Result) const {
356 moveToNextSection(DRI);
357 Result = SectionRef(DRI, this);
358 return object_error::success;
362 MachOObjectFile::getSection(DataRefImpl DRI,
363 InMemoryStruct<macho::Section> &Res) const {
364 InMemoryStruct<macho::SegmentLoadCommand> SLC;
365 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
366 MachOObj->ReadSegmentLoadCommand(LCI, SLC);
367 MachOObj->ReadSection(LCI, DRI.d.b, Res);
370 std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {
371 SectionList::const_iterator loc =
372 std::find(Sections.begin(), Sections.end(), Sec);
373 assert(loc != Sections.end() && "Sec is not a valid section!");
374 return std::distance(Sections.begin(), loc);
378 MachOObjectFile::getSection64(DataRefImpl DRI,
379 InMemoryStruct<macho::Section64> &Res) const {
380 InMemoryStruct<macho::Segment64LoadCommand> SLC;
381 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
382 MachOObj->ReadSegment64LoadCommand(LCI, SLC);
383 MachOObj->ReadSection64(LCI, DRI.d.b, Res);
386 static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) {
387 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
388 if (LCI.Command.Type == macho::LCT_Segment64)
390 assert(LCI.Command.Type == macho::LCT_Segment && "Unexpected Type.");
394 error_code MachOObjectFile::getSectionName(DataRefImpl DRI,
395 StringRef &Result) const {
396 // FIXME: thread safety.
397 static char result[34];
398 if (is64BitLoadCommand(MachOObj, DRI)) {
399 InMemoryStruct<macho::Segment64LoadCommand> SLC;
400 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
401 MachOObj->ReadSegment64LoadCommand(LCI, SLC);
402 InMemoryStruct<macho::Section64> Sect;
403 MachOObj->ReadSection64(LCI, DRI.d.b, Sect);
405 strcpy(result, Sect->SegmentName);
407 strcat(result, Sect->Name);
409 InMemoryStruct<macho::SegmentLoadCommand> SLC;
410 LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
411 MachOObj->ReadSegmentLoadCommand(LCI, SLC);
412 InMemoryStruct<macho::Section> Sect;
413 MachOObj->ReadSection(LCI, DRI.d.b, Sect);
415 strcpy(result, Sect->SegmentName);
417 strcat(result, Sect->Name);
419 Result = StringRef(result);
420 return object_error::success;
423 error_code MachOObjectFile::getSectionAddress(DataRefImpl DRI,
424 uint64_t &Result) const {
425 if (is64BitLoadCommand(MachOObj, DRI)) {
426 InMemoryStruct<macho::Section64> Sect;
427 getSection64(DRI, Sect);
428 Result = Sect->Address;
430 InMemoryStruct<macho::Section> Sect;
431 getSection(DRI, Sect);
432 Result = Sect->Address;
434 return object_error::success;
437 error_code MachOObjectFile::getSectionSize(DataRefImpl DRI,
438 uint64_t &Result) const {
439 if (is64BitLoadCommand(MachOObj, DRI)) {
440 InMemoryStruct<macho::Section64> Sect;
441 getSection64(DRI, Sect);
444 InMemoryStruct<macho::Section> Sect;
445 getSection(DRI, Sect);
448 return object_error::success;
451 error_code MachOObjectFile::getSectionContents(DataRefImpl DRI,
452 StringRef &Result) const {
453 if (is64BitLoadCommand(MachOObj, DRI)) {
454 InMemoryStruct<macho::Section64> Sect;
455 getSection64(DRI, Sect);
456 Result = MachOObj->getData(Sect->Offset, Sect->Size);
458 InMemoryStruct<macho::Section> Sect;
459 getSection(DRI, Sect);
460 Result = MachOObj->getData(Sect->Offset, Sect->Size);
462 return object_error::success;
465 error_code MachOObjectFile::getSectionAlignment(DataRefImpl DRI,
466 uint64_t &Result) const {
467 if (is64BitLoadCommand(MachOObj, DRI)) {
468 InMemoryStruct<macho::Section64> Sect;
469 getSection64(DRI, Sect);
470 Result = uint64_t(1) << Sect->Align;
472 InMemoryStruct<macho::Section> Sect;
473 getSection(DRI, Sect);
474 Result = uint64_t(1) << Sect->Align;
476 return object_error::success;
479 error_code MachOObjectFile::isSectionText(DataRefImpl DRI,
480 bool &Result) const {
481 if (is64BitLoadCommand(MachOObj, DRI)) {
482 InMemoryStruct<macho::Section64> Sect;
483 getSection64(DRI, Sect);
484 Result = !strcmp(Sect->Name, "__text");
486 InMemoryStruct<macho::Section> Sect;
487 getSection(DRI, Sect);
488 Result = !strcmp(Sect->Name, "__text");
490 return object_error::success;
493 error_code MachOObjectFile::isSectionData(DataRefImpl DRI,
494 bool &Result) const {
495 // FIXME: Unimplemented.
497 return object_error::success;
500 error_code MachOObjectFile::isSectionBSS(DataRefImpl DRI,
501 bool &Result) const {
502 // FIXME: Unimplemented.
504 return object_error::success;
507 error_code MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
509 bool &Result) const {
511 getSymbolType(Symb, ST);
512 if (ST == SymbolRef::ST_External) {
514 return object_error::success;
517 uint64_t SectBegin, SectEnd;
518 getSectionAddress(Sec, SectBegin);
519 getSectionSize(Sec, SectEnd);
520 SectEnd += SectBegin;
522 if (MachOObj->is64Bit()) {
523 InMemoryStruct<macho::Symbol64TableEntry> Entry;
524 getSymbol64TableEntry(Symb, Entry);
525 uint64_t SymAddr= Entry->Value;
526 Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
528 InMemoryStruct<macho::SymbolTableEntry> Entry;
529 getSymbolTableEntry(Symb, Entry);
530 uint64_t SymAddr= Entry->Value;
531 Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
534 return object_error::success;
537 relocation_iterator MachOObjectFile::getSectionRelBegin(DataRefImpl Sec) const {
540 ret.d.b = getSectionIndex(Sec);
541 return relocation_iterator(RelocationRef(ret, this));
543 relocation_iterator MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
545 if (is64BitLoadCommand(MachOObj, Sec)) {
546 InMemoryStruct<macho::Section64> Sect;
547 getSection64(Sec, Sect);
548 last_reloc = Sect->NumRelocationTableEntries;
550 InMemoryStruct<macho::Section> Sect;
551 getSection(Sec, Sect);
552 last_reloc = Sect->NumRelocationTableEntries;
555 ret.d.a = last_reloc;
556 ret.d.b = getSectionIndex(Sec);
557 return relocation_iterator(RelocationRef(ret, this));
560 section_iterator MachOObjectFile::begin_sections() const {
562 DRI.d.a = DRI.d.b = 0;
563 moveToNextSection(DRI);
564 return section_iterator(SectionRef(DRI, this));
567 section_iterator MachOObjectFile::end_sections() const {
569 DRI.d.a = MachOObj->getHeader().NumLoadCommands;
571 return section_iterator(SectionRef(DRI, this));
574 /*===-- Relocations -------------------------------------------------------===*/
576 void MachOObjectFile::
577 getRelocation(DataRefImpl Rel,
578 InMemoryStruct<macho::RelocationEntry> &Res) const {
580 if (MachOObj->is64Bit()) {
581 InMemoryStruct<macho::Section64> Sect;
582 getSection64(Sections[Rel.d.b], Sect);
583 relOffset = Sect->RelocationTableOffset;
585 InMemoryStruct<macho::Section> Sect;
586 getSection(Sections[Rel.d.b], Sect);
587 relOffset = Sect->RelocationTableOffset;
589 MachOObj->ReadRelocationEntry(relOffset, Rel.d.a, Res);
591 error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel,
592 RelocationRef &Res) const {
594 Res = RelocationRef(Rel, this);
595 return object_error::success;
597 error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
598 uint64_t &Res) const {
599 const uint8_t* sectAddress = base();
600 if (MachOObj->is64Bit()) {
601 InMemoryStruct<macho::Section64> Sect;
602 getSection64(Sections[Rel.d.b], Sect);
603 sectAddress += Sect->Offset;
605 InMemoryStruct<macho::Section> Sect;
606 getSection(Sections[Rel.d.b], Sect);
607 sectAddress += Sect->Offset;
609 InMemoryStruct<macho::RelocationEntry> RE;
610 getRelocation(Rel, RE);
611 Res = reinterpret_cast<uintptr_t>(sectAddress + RE->Word0);
612 return object_error::success;
614 error_code MachOObjectFile::getRelocationSymbol(DataRefImpl Rel,
615 SymbolRef &Res) const {
616 InMemoryStruct<macho::RelocationEntry> RE;
617 getRelocation(Rel, RE);
618 uint32_t SymbolIdx = RE->Word1 & 0xffffff;
619 bool isExtern = (RE->Word1 >> 27) & 1;
622 Sym.d.a = Sym.d.b = 0;
623 moveToNextSymbol(Sym);
625 for (unsigned i = 0; i < SymbolIdx; i++) {
627 moveToNextSymbol(Sym);
628 assert(Sym.d.a < MachOObj->getHeader().NumLoadCommands &&
629 "Relocation symbol index out of range!");
632 Res = SymbolRef(Sym, this);
633 return object_error::success;
635 error_code MachOObjectFile::getRelocationType(DataRefImpl Rel,
636 uint32_t &Res) const {
637 InMemoryStruct<macho::RelocationEntry> RE;
638 getRelocation(Rel, RE);
640 return object_error::success;
642 error_code MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
643 SmallVectorImpl<char> &Result) const {
644 StringRef res = "Unknown";
645 Result.append(res.begin(), res.end());
646 return object_error::success;
648 error_code MachOObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
649 int64_t &Res) const {
650 InMemoryStruct<macho::RelocationEntry> RE;
651 getRelocation(Rel, RE);
652 bool isExtern = (RE->Word1 >> 27) & 1;
655 const uint8_t* sectAddress = base();
656 if (MachOObj->is64Bit()) {
657 InMemoryStruct<macho::Section64> Sect;
658 getSection64(Sections[Rel.d.b], Sect);
659 sectAddress += Sect->Offset;
661 InMemoryStruct<macho::Section> Sect;
662 getSection(Sections[Rel.d.b], Sect);
663 sectAddress += Sect->Offset;
665 Res = reinterpret_cast<uintptr_t>(sectAddress);
667 return object_error::success;
669 error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
670 SmallVectorImpl<char> &Result) const {
671 StringRef res = "Unknown";
672 Result.append(res.begin(), res.end());
673 return object_error::success;
676 /*===-- Miscellaneous -----------------------------------------------------===*/
678 uint8_t MachOObjectFile::getBytesInAddress() const {
679 return MachOObj->is64Bit() ? 8 : 4;
682 StringRef MachOObjectFile::getFileFormatName() const {
683 if (!MachOObj->is64Bit()) {
684 switch (MachOObj->getHeader().CPUType) {
685 case llvm::MachO::CPUTypeI386:
686 return "Mach-O 32-bit i386";
687 case llvm::MachO::CPUTypeARM:
689 case llvm::MachO::CPUTypePowerPC:
690 return "Mach-O 32-bit ppc";
692 assert((MachOObj->getHeader().CPUType & llvm::MachO::CPUArchABI64) == 0 &&
693 "64-bit object file when we're not 64-bit?");
694 return "Mach-O 32-bit unknown";
698 switch (MachOObj->getHeader().CPUType) {
699 case llvm::MachO::CPUTypeX86_64:
700 return "Mach-O 64-bit x86-64";
701 case llvm::MachO::CPUTypePowerPC64:
702 return "Mach-O 64-bit ppc64";
704 assert((MachOObj->getHeader().CPUType & llvm::MachO::CPUArchABI64) == 1 &&
705 "32-bit object file when we're 64-bit?");
706 return "Mach-O 64-bit unknown";
710 unsigned MachOObjectFile::getArch() const {
711 switch (MachOObj->getHeader().CPUType) {
712 case llvm::MachO::CPUTypeI386:
714 case llvm::MachO::CPUTypeX86_64:
715 return Triple::x86_64;
716 case llvm::MachO::CPUTypeARM:
718 case llvm::MachO::CPUTypePowerPC:
720 case llvm::MachO::CPUTypePowerPC64:
721 return Triple::ppc64;
723 return Triple::UnknownArch;
727 } // end namespace object
728 } // end namespace llvm