1 //===-- RuntimeDyldMachO.cpp - Run-time dynamic linker for MC-JIT -*- 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 // Implementation of the MC-JIT runtime dynamic linker.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "dyld"
15 #include "llvm/ADT/OwningPtr.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "RuntimeDyldMachO.h"
20 using namespace llvm::object;
24 bool RuntimeDyldMachO::
25 resolveRelocation(uint8_t *LocalAddress,
26 uint64_t FinalAddress,
32 // This just dispatches to the proper target specific routine.
34 default: llvm_unreachable("Unsupported CPU type!");
35 case mach::CTM_x86_64:
36 return resolveX86_64Relocation(LocalAddress,
44 return resolveARMRelocation(LocalAddress,
54 bool RuntimeDyldMachO::
55 resolveX86_64Relocation(uint8_t *LocalAddress,
56 uint64_t FinalAddress,
62 // If the relocation is PC-relative, the value to be encoded is the
63 // pointer difference.
65 // FIXME: It seems this value needs to be adjusted by 4 for an effective PC
66 // address. Is that expected? Only for branches, perhaps?
67 Value -= FinalAddress + 4;
71 llvm_unreachable("Invalid relocation type!");
72 case macho::RIT_X86_64_Signed1:
73 case macho::RIT_X86_64_Signed2:
74 case macho::RIT_X86_64_Signed4:
75 case macho::RIT_X86_64_Signed:
76 case macho::RIT_X86_64_Unsigned:
77 case macho::RIT_X86_64_Branch: {
79 // Mask in the target value a byte at a time (we don't have an alignment
80 // guarantee for the target address, so this is safest).
81 uint8_t *p = (uint8_t*)LocalAddress;
82 for (unsigned i = 0; i < Size; ++i) {
83 *p++ = (uint8_t)Value;
88 case macho::RIT_X86_64_GOTLoad:
89 case macho::RIT_X86_64_GOT:
90 case macho::RIT_X86_64_Subtractor:
91 case macho::RIT_X86_64_TLV:
92 return Error("Relocation type not implemented yet!");
96 bool RuntimeDyldMachO::
97 resolveARMRelocation(uint8_t *LocalAddress,
98 uint64_t FinalAddress,
104 // If the relocation is PC-relative, the value to be encoded is the
105 // pointer difference.
107 Value -= FinalAddress;
108 // ARM PCRel relocations have an effective-PC offset of two instructions
109 // (four bytes in Thumb mode, 8 bytes in ARM mode).
110 // FIXME: For now, assume ARM mode.
116 llvm_unreachable("Invalid relocation type!");
117 case macho::RIT_Vanilla: {
118 // Mask in the target value a byte at a time (we don't have an alignment
119 // guarantee for the target address, so this is safest).
120 uint8_t *p = (uint8_t*)LocalAddress;
121 for (unsigned i = 0; i < Size; ++i) {
122 *p++ = (uint8_t)Value;
127 case macho::RIT_ARM_Branch24Bit: {
128 // Mask the value into the target address. We know instructions are
129 // 32-bit aligned, so we can do it all at once.
130 uint32_t *p = (uint32_t*)LocalAddress;
131 // The low two bits of the value are not encoded.
133 // Mask the value to 24 bits.
135 // FIXME: If the destination is a Thumb function (and the instruction
136 // is a non-predicated BL instruction), we need to change it to a BLX
137 // instruction instead.
139 // Insert the value into the instruction.
140 *p = (*p & ~0xffffff) | Value;
143 case macho::RIT_ARM_ThumbBranch22Bit:
144 case macho::RIT_ARM_ThumbBranch32Bit:
145 case macho::RIT_ARM_Half:
146 case macho::RIT_ARM_HalfDifference:
147 case macho::RIT_Pair:
148 case macho::RIT_Difference:
149 case macho::RIT_ARM_LocalDifference:
150 case macho::RIT_ARM_PreboundLazyPointer:
151 return Error("Relocation type not implemented yet!");
156 bool RuntimeDyldMachO::
157 loadSegment32(const MachOObject *Obj,
158 const MachOObject::LoadCommandInfo *SegmentLCI,
159 const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC) {
160 // FIXME: This should really be combined w/ loadSegment64. Templatized
161 // function on the 32/64 datatypes maybe?
162 InMemoryStruct<macho::SegmentLoadCommand> SegmentLC;
163 Obj->ReadSegmentLoadCommand(*SegmentLCI, SegmentLC);
165 return Error("unable to load segment load command");
168 SmallVector<unsigned, 16> SectionMap;
169 for (unsigned SectNum = 0; SectNum != SegmentLC->NumSections; ++SectNum) {
170 InMemoryStruct<macho::Section> Sect;
171 Obj->ReadSection(*SegmentLCI, SectNum, Sect);
173 return Error("unable to load section: '" + Twine(SectNum) + "'");
175 // Allocate memory via the MM for the section.
177 uint32_t SectionID = Sections.size();
178 if (Sect->Flags == 0x80000400)
179 Buffer = MemMgr->allocateCodeSection(Sect->Size, Sect->Align, SectionID);
181 Buffer = MemMgr->allocateDataSection(Sect->Size, Sect->Align, SectionID);
183 DEBUG(dbgs() << "Loading "
184 << ((Sect->Flags == 0x80000400) ? "text" : "data")
185 << " (ID #" << SectionID << ")"
186 << " '" << Sect->SegmentName << ","
187 << Sect->Name << "' of size " << Sect->Size
188 << " to address " << Buffer << ".\n");
190 // Copy the payload from the object file into the allocated buffer.
191 uint8_t *Base = (uint8_t*)Obj->getData(SegmentLC->FileOffset,
192 SegmentLC->FileSize).data();
193 memcpy(Buffer, Base + Sect->Address, Sect->Size);
195 // Remember what got allocated for this SectionID.
196 Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
197 SectionLocalMemToID[Buffer] = SectionID;
199 // By default, the load address of a section is its memory buffer.
200 SectionLoadAddress.push_back((uint64_t)Buffer);
202 // Keep a map of object file section numbers to corresponding SectionIDs
203 // while processing the file.
204 SectionMap.push_back(SectionID);
207 // Process the symbol table.
208 SmallVector<StringRef, 64> SymbolNames;
209 processSymbols32(Obj, SectionMap, SymbolNames, SymtabLC);
211 // Process the relocations for each section we're loading.
212 Relocations.grow(Relocations.size() + SegmentLC->NumSections);
213 Referrers.grow(Referrers.size() + SegmentLC->NumSections);
214 for (unsigned SectNum = 0; SectNum != SegmentLC->NumSections; ++SectNum) {
215 InMemoryStruct<macho::Section> Sect;
216 Obj->ReadSection(*SegmentLCI, SectNum, Sect);
218 return Error("unable to load section: '" + Twine(SectNum) + "'");
219 for (unsigned j = 0; j != Sect->NumRelocationTableEntries; ++j) {
220 InMemoryStruct<macho::RelocationEntry> RE;
221 Obj->ReadRelocationEntry(Sect->RelocationTableOffset, j, RE);
222 if (RE->Word0 & macho::RF_Scattered)
223 return Error("NOT YET IMPLEMENTED: scattered relocations.");
224 // Word0 of the relocation is the offset into the section where the
225 // relocation should be applied. We need to translate that into an
226 // offset into a function since that's our atom.
227 uint32_t Offset = RE->Word0;
228 bool isExtern = (RE->Word1 >> 27) & 1;
230 // FIXME: Get the relocation addend from the target address.
231 // FIXME: VERY imporant for internal relocations.
233 // Figure out the source symbol of the relocation. If isExtern is true,
234 // this relocation references the symbol table, otherwise it references
235 // a section in the same object, numbered from 1 through NumSections
236 // (SectionBases is [0, NumSections-1]).
237 uint32_t SourceNum = RE->Word1 & 0xffffff; // 24-bit value
239 assert(SourceNum > 0 && "Invalid relocation section number!");
240 unsigned SectionID = SectionMap[SourceNum - 1];
241 unsigned TargetID = SectionMap[SectNum];
242 DEBUG(dbgs() << "Internal relocation at Section #"
243 << TargetID << " + " << Offset
245 << SectionID << " (Word1: "
246 << format("0x%x", RE->Word1) << ")\n");
248 // Store the relocation information. It will get resolved when
249 // the section addresses are assigned.
250 uint32_t RelocationIndex = Relocations[SectionID].size();
251 Relocations[SectionID].push_back(RelocationEntry(TargetID,
255 Referrers[TargetID].push_back(Referrer(SectionID, RelocationIndex));
257 StringRef SourceName = SymbolNames[SourceNum];
259 // Now store the relocation information. Associate it with the source
260 // symbol. Just add it to the unresolved list and let the general
261 // path post-load resolve it if we know where the symbol is.
262 UnresolvedRelocations[SourceName].push_back(RelocationEntry(SectNum,
266 DEBUG(dbgs() << "Relocation at Section #" << SectNum << " + " << Offset
267 << " from '" << SourceName << "(Word1: "
268 << format("0x%x", RE->Word1) << ")\n");
273 // Resolve the addresses of any symbols that were defined in this segment.
274 for (int i = 0, e = SymbolNames.size(); i != e; ++i)
275 resolveSymbol(SymbolNames[i]);
281 bool RuntimeDyldMachO::
282 loadSegment64(const MachOObject *Obj,
283 const MachOObject::LoadCommandInfo *SegmentLCI,
284 const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC) {
285 InMemoryStruct<macho::Segment64LoadCommand> Segment64LC;
286 Obj->ReadSegment64LoadCommand(*SegmentLCI, Segment64LC);
288 return Error("unable to load segment load command");
291 SmallVector<unsigned, 16> SectionMap;
292 for (unsigned SectNum = 0; SectNum != Segment64LC->NumSections; ++SectNum) {
293 InMemoryStruct<macho::Section64> Sect;
294 Obj->ReadSection64(*SegmentLCI, SectNum, Sect);
296 return Error("unable to load section: '" + Twine(SectNum) + "'");
298 // Allocate memory via the MM for the section.
300 uint32_t SectionID = Sections.size();
301 unsigned Align = 1 << Sect->Align; // .o file has log2 alignment.
302 if (Sect->Flags == 0x80000400)
303 Buffer = MemMgr->allocateCodeSection(Sect->Size, Align, SectionID);
305 Buffer = MemMgr->allocateDataSection(Sect->Size, Align, SectionID);
307 DEBUG(dbgs() << "Loading "
308 << ((Sect->Flags == 0x80000400) ? "text" : "data")
309 << " (ID #" << SectionID << ")"
310 << " '" << Sect->SegmentName << ","
311 << Sect->Name << "' of size " << Sect->Size
312 << " (align " << Align << ")"
313 << " to address " << Buffer << ".\n");
315 // Copy the payload from the object file into the allocated buffer.
316 uint8_t *Base = (uint8_t*)Obj->getData(Segment64LC->FileOffset,
317 Segment64LC->FileSize).data();
318 memcpy(Buffer, Base + Sect->Address, Sect->Size);
320 // Remember what got allocated for this SectionID.
321 Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
322 SectionLocalMemToID[Buffer] = SectionID;
324 // By default, the load address of a section is its memory buffer.
325 SectionLoadAddress.push_back((uint64_t)Buffer);
327 // Keep a map of object file section numbers to corresponding SectionIDs
328 // while processing the file.
329 SectionMap.push_back(SectionID);
332 // Process the symbol table.
333 SmallVector<StringRef, 64> SymbolNames;
334 processSymbols64(Obj, SectionMap, SymbolNames, SymtabLC);
336 // Process the relocations for each section we're loading.
337 Relocations.grow(Relocations.size() + Segment64LC->NumSections);
338 Referrers.grow(Referrers.size() + Segment64LC->NumSections);
339 for (unsigned SectNum = 0; SectNum != Segment64LC->NumSections; ++SectNum) {
340 InMemoryStruct<macho::Section64> Sect;
341 Obj->ReadSection64(*SegmentLCI, SectNum, Sect);
343 return Error("unable to load section: '" + Twine(SectNum) + "'");
344 for (unsigned j = 0; j != Sect->NumRelocationTableEntries; ++j) {
345 InMemoryStruct<macho::RelocationEntry> RE;
346 Obj->ReadRelocationEntry(Sect->RelocationTableOffset, j, RE);
347 if (RE->Word0 & macho::RF_Scattered)
348 return Error("NOT YET IMPLEMENTED: scattered relocations.");
349 // Word0 of the relocation is the offset into the section where the
350 // relocation should be applied. We need to translate that into an
351 // offset into a function since that's our atom.
352 uint32_t Offset = RE->Word0;
353 bool isExtern = (RE->Word1 >> 27) & 1;
355 // FIXME: Get the relocation addend from the target address.
356 // FIXME: VERY imporant for internal relocations.
358 // Figure out the source symbol of the relocation. If isExtern is true,
359 // this relocation references the symbol table, otherwise it references
360 // a section in the same object, numbered from 1 through NumSections
361 // (SectionBases is [0, NumSections-1]).
362 uint32_t SourceNum = RE->Word1 & 0xffffff; // 24-bit value
364 assert(SourceNum > 0 && "Invalid relocation section number!");
365 unsigned SectionID = SectionMap[SourceNum - 1];
366 unsigned TargetID = SectionMap[SectNum];
367 DEBUG(dbgs() << "Internal relocation at Section #"
368 << TargetID << " + " << Offset
370 << SectionID << " (Word1: "
371 << format("0x%x", RE->Word1) << ")\n");
373 // Store the relocation information. It will get resolved when
374 // the section addresses are assigned.
375 uint32_t RelocationIndex = Relocations[SectionID].size();
376 Relocations[SectionID].push_back(RelocationEntry(TargetID,
380 Referrers[TargetID].push_back(Referrer(SectionID, RelocationIndex));
382 StringRef SourceName = SymbolNames[SourceNum];
384 // Now store the relocation information. Associate it with the source
385 // symbol. Just add it to the unresolved list and let the general
386 // path post-load resolve it if we know where the symbol is.
387 UnresolvedRelocations[SourceName].push_back(RelocationEntry(SectNum,
391 DEBUG(dbgs() << "Relocation at Section #" << SectNum << " + " << Offset
392 << " from '" << SourceName << "(Word1: "
393 << format("0x%x", RE->Word1) << ")\n");
398 // Resolve the addresses of any symbols that were defined in this segment.
399 for (int i = 0, e = SymbolNames.size(); i != e; ++i)
400 resolveSymbol(SymbolNames[i]);
405 bool RuntimeDyldMachO::
406 processSymbols32(const MachOObject *Obj,
407 SmallVectorImpl<unsigned> &SectionMap,
408 SmallVectorImpl<StringRef> &SymbolNames,
409 const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC) {
410 // FIXME: Combine w/ processSymbols64. Factor 64/32 datatype and such.
411 for (unsigned i = 0; i != SymtabLC->NumSymbolTableEntries; ++i) {
412 InMemoryStruct<macho::SymbolTableEntry> STE;
413 Obj->ReadSymbolTableEntry(SymtabLC->SymbolTableOffset, i, STE);
415 return Error("unable to read symbol: '" + Twine(i) + "'");
416 // Get the symbol name.
417 StringRef Name = Obj->getStringAtIndex(STE->StringIndex);
418 SymbolNames.push_back(Name);
420 // FIXME: Check the symbol type and flags.
421 if (STE->Type != 0xF) // external, defined in this segment.
423 // Flags in the upper nibble we don't care about.
424 if ((STE->Flags & 0xf) != 0x0)
427 // Remember the symbol.
428 uint32_t SectionID = SectionMap[STE->SectionIndex - 1];
429 SymbolTable[Name] = SymbolLoc(SectionID, STE->Value);
431 DEBUG(dbgs() << "Symbol: '" << Name << "' @ "
432 << (getSectionAddress(SectionID) + STE->Value)
438 bool RuntimeDyldMachO::
439 processSymbols64(const MachOObject *Obj,
440 SmallVectorImpl<unsigned> &SectionMap,
441 SmallVectorImpl<StringRef> &SymbolNames,
442 const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC) {
443 for (unsigned i = 0; i != SymtabLC->NumSymbolTableEntries; ++i) {
444 InMemoryStruct<macho::Symbol64TableEntry> STE;
445 Obj->ReadSymbol64TableEntry(SymtabLC->SymbolTableOffset, i, STE);
447 return Error("unable to read symbol: '" + Twine(i) + "'");
448 // Get the symbol name.
449 StringRef Name = Obj->getStringAtIndex(STE->StringIndex);
450 SymbolNames.push_back(Name);
452 // FIXME: Check the symbol type and flags.
453 if (STE->Type != 0xF) // external, defined in this segment.
455 // Flags in the upper nibble we don't care about.
456 if ((STE->Flags & 0xf) != 0x0)
459 // Remember the symbol.
460 uint32_t SectionID = SectionMap[STE->SectionIndex - 1];
461 SymbolTable[Name] = SymbolLoc(SectionID, STE->Value);
463 DEBUG(dbgs() << "Symbol: '" << Name << "' @ "
464 << (getSectionAddress(SectionID) + STE->Value)
470 // resolveSymbol - Resolve any relocations to the specified symbol if
471 // we know where it lives.
472 void RuntimeDyldMachO::resolveSymbol(StringRef Name) {
473 StringMap<SymbolLoc>::const_iterator Loc = SymbolTable.find(Name);
474 if (Loc == SymbolTable.end())
477 RelocationList &Relocs = UnresolvedRelocations[Name];
478 DEBUG(dbgs() << "Resolving symbol '" << Name << "'\n");
479 for (int i = 0, e = Relocs.size(); i != e; ++i) {
480 // Change the relocation to be section relative rather than symbol
481 // relative and move it to the resolved relocation list.
482 RelocationEntry Entry = Relocs[i];
483 Entry.Addend += Loc->second.second;
484 uint32_t RelocationIndex = Relocations[Loc->second.first].size();
485 Relocations[Loc->second.first].push_back(Entry);
486 Referrers[Entry.SectionID].push_back(Referrer(Loc->second.first, RelocationIndex));
488 // FIXME: Keep a worklist of the relocations we've added so that we can
489 // resolve more selectively later.
493 bool RuntimeDyldMachO::loadObject(MemoryBuffer *InputBuffer) {
494 // If the linker is in an error state, don't do anything.
497 // Load the Mach-O wrapper object.
498 std::string ErrorStr;
499 OwningPtr<MachOObject> Obj(
500 MachOObject::LoadFromBuffer(InputBuffer, &ErrorStr));
502 return Error("unable to load object: '" + ErrorStr + "'");
504 // Get the CPU type information from the header.
505 const macho::Header &Header = Obj->getHeader();
507 // FIXME: Error checking that the loaded object is compatible with
508 // the system we're running on.
509 CPUType = Header.CPUType;
510 CPUSubtype = Header.CPUSubtype;
512 // Validate that the load commands match what we expect.
513 const MachOObject::LoadCommandInfo *SegmentLCI = 0, *SymtabLCI = 0,
515 for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
516 const MachOObject::LoadCommandInfo &LCI = Obj->getLoadCommandInfo(i);
517 switch (LCI.Command.Type) {
518 case macho::LCT_Segment:
519 case macho::LCT_Segment64:
521 return Error("unexpected input object (multiple segments)");
524 case macho::LCT_Symtab:
526 return Error("unexpected input object (multiple symbol tables)");
529 case macho::LCT_Dysymtab:
531 return Error("unexpected input object (multiple symbol tables)");
535 return Error("unexpected input object (unexpected load command");
540 return Error("no symbol table found in object");
542 return Error("no segments found in object");
544 // Read and register the symbol table data.
545 InMemoryStruct<macho::SymtabLoadCommand> SymtabLC;
546 Obj->ReadSymtabLoadCommand(*SymtabLCI, SymtabLC);
548 return Error("unable to load symbol table load command");
549 Obj->RegisterStringTable(*SymtabLC);
551 // Read the dynamic link-edit information, if present (not present in static
554 InMemoryStruct<macho::DysymtabLoadCommand> DysymtabLC;
555 Obj->ReadDysymtabLoadCommand(*DysymtabLCI, DysymtabLC);
557 return Error("unable to load dynamic link-exit load command");
559 // FIXME: We don't support anything interesting yet.
560 // if (DysymtabLC->LocalSymbolsIndex != 0)
561 // return Error("NOT YET IMPLEMENTED: local symbol entries");
562 // if (DysymtabLC->ExternalSymbolsIndex != 0)
563 // return Error("NOT YET IMPLEMENTED: non-external symbol entries");
564 // if (DysymtabLC->UndefinedSymbolsIndex != SymtabLC->NumSymbolTableEntries)
565 // return Error("NOT YET IMPLEMENTED: undefined symbol entries");
568 // Load the segment load command.
569 if (SegmentLCI->Command.Type == macho::LCT_Segment) {
570 if (loadSegment32(Obj.get(), SegmentLCI, SymtabLC))
573 if (loadSegment64(Obj.get(), SegmentLCI, SymtabLC))
577 // Assign the addresses of the sections from the object so that any
578 // relocations to them get set properly.
579 // FIXME: This is done directly from the client at the moment. We should
580 // default the values to the local storage, at least when the target arch
581 // is the same as the host arch.
586 // Assign an address to a symbol name and resolve all the relocations
587 // associated with it.
588 void RuntimeDyldMachO::reassignSectionAddress(unsigned SectionID,
590 // The address to use for relocation resolution is not
591 // the address of the local section buffer. We must be doing
592 // a remote execution environment of some sort. Re-apply any
593 // relocations referencing this section with the given address.
595 // Addr is a uint64_t because we can't assume the pointer width
596 // of the target is the same as that of the host. Just use a generic
597 // "big enough" type.
599 SectionLoadAddress[SectionID] = Addr;
601 RelocationList &Relocs = Relocations[SectionID];
602 for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
603 RelocationEntry &RE = Relocs[i];
604 uint8_t *Target = (uint8_t*)Sections[RE.SectionID].base() + RE.Offset;
605 uint64_t FinalTarget = (uint64_t)SectionLoadAddress[RE.SectionID] + RE.Offset;
606 bool isPCRel = (RE.Data >> 24) & 1;
607 unsigned Type = (RE.Data >> 28) & 0xf;
608 unsigned Size = 1 << ((RE.Data >> 25) & 3);
610 DEBUG(dbgs() << "Resolving relocation at Section #" << RE.SectionID
611 << " + " << RE.Offset << " (" << format("%p", Target) << ")"
612 << " from Section #" << SectionID << " (" << format("%p", Addr) << ")"
613 << "(" << (isPCRel ? "pcrel" : "absolute")
614 << ", type: " << Type << ", Size: " << Size << ", Addend: "
615 << RE.Addend << ").\n");
617 resolveRelocation(Target,
625 ReferrerList &Refers = Referrers[SectionID];
626 for (unsigned i = 0, e = Refers.size(); i != e; ++i) {
627 Referrer &R = Refers[i];
628 RelocationEntry &RE = Relocations[R.SectionID][R.Index];
629 uint8_t *Target = (uint8_t*)Sections[RE.SectionID].base() + RE.Offset;
630 uint64_t FinalTarget = (uint64_t)SectionLoadAddress[RE.SectionID] + RE.Offset;
631 bool isPCRel = (RE.Data >> 24) & 1;
632 unsigned Type = (RE.Data >> 28) & 0xf;
633 unsigned Size = 1 << ((RE.Data >> 25) & 3);
635 DEBUG(dbgs() << "Resolving relocation at Section #" << RE.SectionID
636 << " + " << RE.Offset << " (" << format("%p", Target) << ")"
637 << " from Section #" << SectionID << " (" << format("%p", Addr) << ")"
638 << "(" << (isPCRel ? "pcrel" : "absolute")
639 << ", type: " << Type << ", Size: " << Size << ", Addend: "
640 << RE.Addend << ").\n");
642 resolveRelocation(Target,
652 bool RuntimeDyldMachO::isKnownFormat(const MemoryBuffer *InputBuffer) {
653 StringRef Magic = InputBuffer->getBuffer().slice(0, 4);
654 if (Magic == "\xFE\xED\xFA\xCE") return true;
655 if (Magic == "\xCE\xFA\xED\xFE") return true;
656 if (Magic == "\xFE\xED\xFA\xCF") return true;
657 if (Magic == "\xCF\xFA\xED\xFE") return true;
661 } // end namespace llvm