blob: 2f4df6b9622095ec4bcfe7d91fa0948d0f353c26 [file] [log] [blame]
Jim Grosbache0934be2012-01-16 23:50:58 +00001//===-- RuntimeDyldMachO.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-=//
Danil Malyshevcf852dc2011-07-13 07:57:58 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Implementation of the MC-JIT runtime dynamic linker.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "dyld"
Eli Bendersky76463fd2012-01-22 07:05:02 +000015#include "RuntimeDyldMachO.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000016#include "llvm/ADT/OwningPtr.h"
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/StringRef.h"
Danil Malyshevcf852dc2011-07-13 07:57:58 +000019using namespace llvm;
20using namespace llvm::object;
21
22namespace llvm {
23
Rafael Espindolaa2e40fb2013-05-05 20:43:10 +000024static unsigned char *processFDE(unsigned char *P, intptr_t DeltaForText, intptr_t DeltaForEH) {
25 uint32_t Length = *((uint32_t*)P);
26 P += 4;
27 unsigned char *Ret = P + Length;
28 uint32_t Offset = *((uint32_t*)P);
29 if (Offset == 0) // is a CIE
30 return Ret;
31
32 P += 4;
33 intptr_t FDELocation = *((intptr_t*)P);
34 intptr_t NewLocation = FDELocation - DeltaForText;
35 *((intptr_t*)P) = NewLocation;
36 P += sizeof(intptr_t);
37
38 // Skip the FDE address range
39 P += sizeof(intptr_t);
40
41 uint8_t Augmentationsize = *P;
42 P += 1;
43 if (Augmentationsize != 0) {
44 intptr_t LSDA = *((intptr_t*)P);
45 intptr_t NewLSDA = LSDA - DeltaForEH;
46 *((intptr_t*)P) = NewLSDA;
47 }
48
49 return Ret;
50}
51
52static intptr_t computeDelta(SectionEntry *A, SectionEntry *B) {
53 intptr_t ObjDistance = A->ObjAddress - B->ObjAddress;
54 intptr_t MemDistance = A->LoadAddress - B->LoadAddress;
55 return ObjDistance - MemDistance;
56}
57
58StringRef RuntimeDyldMachO::getEHFrameSection() {
59 SectionEntry *Text = NULL;
60 SectionEntry *EHFrame = NULL;
61 SectionEntry *ExceptTab = NULL;
62 for (int i = 0, e = Sections.size(); i != e; ++i) {
63 if (Sections[i].Name == "__eh_frame")
64 EHFrame = &Sections[i];
65 else if (Sections[i].Name == "__text")
66 Text = &Sections[i];
67 else if (Sections[i].Name == "__gcc_except_tab")
68 ExceptTab = &Sections[i];
69 }
70 if (Text == NULL || EHFrame == NULL)
71 return StringRef();
72
73 intptr_t DeltaForText = computeDelta(Text, EHFrame);
74 intptr_t DeltaForEH = 0;
75 if (ExceptTab)
76 DeltaForEH = computeDelta(ExceptTab, EHFrame);
77
78 unsigned char *P = EHFrame->Address;
79 unsigned char *End = P + EHFrame->Size;
80 do {
81 P = processFDE(P, DeltaForText, DeltaForEH);
82 } while(P != End);
83
84 return StringRef((char*)EHFrame->Address, EHFrame->Size);
85}
86
Andrew Kaylor32bd10b2013-08-19 19:38:06 +000087// The target location for the relocation is described by RE.SectionID and
88// RE.Offset. RE.SectionID can be used to find the SectionEntry. Each
89// SectionEntry has three members describing its location.
90// SectionEntry::Address is the address at which the section has been loaded
91// into memory in the current (host) process. SectionEntry::LoadAddress is the
92// address that the section will have in the target process.
93// SectionEntry::ObjAddress is the address of the bits for this section in the
94// original emitted object image (also in the current address space).
95//
96// Relocations will be applied as if the section were loaded at
97// SectionEntry::LoadAddress, but they will be applied at an address based
98// on SectionEntry::Address. SectionEntry::ObjAddress will be used to refer to
99// Target memory contents if they are required for value calculations.
100//
101// The Value parameter here is the load address of the symbol for the
102// relocation to be applied. For relocations which refer to symbols in the
103// current object Value will be the LoadAddress of the section in which
104// the symbol resides (RE.Addend provides additional information about the
105// symbol location). For external symbols, Value will be the address of the
106// symbol in the target address space.
Rafael Espindola87b50172013-04-29 17:24:34 +0000107void RuntimeDyldMachO::resolveRelocation(const RelocationEntry &RE,
108 uint64_t Value) {
109 const SectionEntry &Section = Sections[RE.SectionID];
110 return resolveRelocation(Section, RE.Offset, Value, RE.RelType, RE.Addend,
111 RE.IsPCRel, RE.Size);
112}
113
Andrew Kaylora307a1c2012-11-02 19:45:23 +0000114void RuntimeDyldMachO::resolveRelocation(const SectionEntry &Section,
115 uint64_t Offset,
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000116 uint64_t Value,
117 uint32_t Type,
Rafael Espindola87b50172013-04-29 17:24:34 +0000118 int64_t Addend,
119 bool isPCRel,
120 unsigned LogSize) {
Andrew Kaylora307a1c2012-11-02 19:45:23 +0000121 uint8_t *LocalAddress = Section.Address + Offset;
122 uint64_t FinalAddress = Section.LoadAddress + Offset;
Rafael Espindola87b50172013-04-29 17:24:34 +0000123 unsigned MachoType = Type;
124 unsigned Size = 1 << LogSize;
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000125
Eli Bendersky6d15e872012-04-30 10:06:27 +0000126 DEBUG(dbgs() << "resolveRelocation LocalAddress: "
127 << format("%p", LocalAddress)
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000128 << " FinalAddress: " << format("%p", FinalAddress)
129 << " Value: " << format("%p", Value)
130 << " Addend: " << Addend
131 << " isPCRel: " << isPCRel
132 << " MachoType: " << MachoType
133 << " Size: " << Size
134 << "\n");
135
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000136 // This just dispatches to the proper target specific routine.
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000137 switch (Arch) {
Craig Topper85814382012-02-07 05:05:23 +0000138 default: llvm_unreachable("Unsupported CPU type!");
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000139 case Triple::x86_64:
140 resolveX86_64Relocation(LocalAddress,
141 FinalAddress,
142 (uintptr_t)Value,
143 isPCRel,
144 MachoType,
145 Size,
146 Addend);
147 break;
148 case Triple::x86:
149 resolveI386Relocation(LocalAddress,
Eli Bendersky6d15e872012-04-30 10:06:27 +0000150 FinalAddress,
151 (uintptr_t)Value,
152 isPCRel,
Jim Grosbachba9ba9f2012-09-13 01:24:32 +0000153 MachoType,
Eli Bendersky6d15e872012-04-30 10:06:27 +0000154 Size,
155 Addend);
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000156 break;
157 case Triple::arm: // Fall through.
158 case Triple::thumb:
159 resolveARMRelocation(LocalAddress,
160 FinalAddress,
161 (uintptr_t)Value,
162 isPCRel,
163 MachoType,
164 Size,
165 Addend);
166 break;
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000167 }
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000168}
169
Eli Bendersky6d15e872012-04-30 10:06:27 +0000170bool RuntimeDyldMachO::resolveI386Relocation(uint8_t *LocalAddress,
171 uint64_t FinalAddress,
172 uint64_t Value,
173 bool isPCRel,
174 unsigned Type,
175 unsigned Size,
176 int64_t Addend) {
Sean Callananb38aae42012-03-26 20:45:52 +0000177 if (isPCRel)
178 Value -= FinalAddress + 4; // see resolveX86_64Relocation
179
180 switch (Type) {
181 default:
182 llvm_unreachable("Invalid relocation type!");
183 case macho::RIT_Vanilla: {
184 uint8_t *p = LocalAddress;
185 uint64_t ValueToWrite = Value + Addend;
186 for (unsigned i = 0; i < Size; ++i) {
187 *p++ = (uint8_t)(ValueToWrite & 0xff);
188 ValueToWrite >>= 8;
189 }
Jim Grosbach6f6f1712013-01-31 19:46:28 +0000190 return false;
Sean Callananb38aae42012-03-26 20:45:52 +0000191 }
192 case macho::RIT_Difference:
193 case macho::RIT_Generic_LocalDifference:
194 case macho::RIT_Generic_PreboundLazyPointer:
195 return Error("Relocation type not implemented yet!");
196 }
197}
198
Eli Bendersky6d15e872012-04-30 10:06:27 +0000199bool RuntimeDyldMachO::resolveX86_64Relocation(uint8_t *LocalAddress,
200 uint64_t FinalAddress,
201 uint64_t Value,
202 bool isPCRel,
203 unsigned Type,
204 unsigned Size,
205 int64_t Addend) {
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000206 // If the relocation is PC-relative, the value to be encoded is the
207 // pointer difference.
208 if (isPCRel)
209 // FIXME: It seems this value needs to be adjusted by 4 for an effective PC
210 // address. Is that expected? Only for branches, perhaps?
Sean Callanan61dfa772012-03-07 23:05:25 +0000211 Value -= FinalAddress + 4;
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000212
213 switch(Type) {
214 default:
215 llvm_unreachable("Invalid relocation type!");
Jim Grosbach652ca2f2012-01-16 23:50:49 +0000216 case macho::RIT_X86_64_Signed1:
217 case macho::RIT_X86_64_Signed2:
218 case macho::RIT_X86_64_Signed4:
219 case macho::RIT_X86_64_Signed:
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000220 case macho::RIT_X86_64_Unsigned:
221 case macho::RIT_X86_64_Branch: {
Jim Grosbach652ca2f2012-01-16 23:50:49 +0000222 Value += Addend;
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000223 // Mask in the target value a byte at a time (we don't have an alignment
224 // guarantee for the target address, so this is safest).
Sean Callanan61dfa772012-03-07 23:05:25 +0000225 uint8_t *p = (uint8_t*)LocalAddress;
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000226 for (unsigned i = 0; i < Size; ++i) {
227 *p++ = (uint8_t)Value;
228 Value >>= 8;
229 }
230 return false;
231 }
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000232 case macho::RIT_X86_64_GOTLoad:
233 case macho::RIT_X86_64_GOT:
234 case macho::RIT_X86_64_Subtractor:
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000235 case macho::RIT_X86_64_TLV:
236 return Error("Relocation type not implemented yet!");
237 }
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000238}
239
Eli Bendersky6d15e872012-04-30 10:06:27 +0000240bool RuntimeDyldMachO::resolveARMRelocation(uint8_t *LocalAddress,
241 uint64_t FinalAddress,
242 uint64_t Value,
243 bool isPCRel,
244 unsigned Type,
245 unsigned Size,
246 int64_t Addend) {
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000247 // If the relocation is PC-relative, the value to be encoded is the
248 // pointer difference.
249 if (isPCRel) {
Sean Callanan61dfa772012-03-07 23:05:25 +0000250 Value -= FinalAddress;
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000251 // ARM PCRel relocations have an effective-PC offset of two instructions
252 // (four bytes in Thumb mode, 8 bytes in ARM mode).
253 // FIXME: For now, assume ARM mode.
254 Value -= 8;
255 }
256
257 switch(Type) {
258 default:
259 llvm_unreachable("Invalid relocation type!");
260 case macho::RIT_Vanilla: {
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000261 // Mask in the target value a byte at a time (we don't have an alignment
262 // guarantee for the target address, so this is safest).
Sean Callanan61dfa772012-03-07 23:05:25 +0000263 uint8_t *p = (uint8_t*)LocalAddress;
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000264 for (unsigned i = 0; i < Size; ++i) {
265 *p++ = (uint8_t)Value;
266 Value >>= 8;
267 }
268 break;
269 }
270 case macho::RIT_ARM_Branch24Bit: {
271 // Mask the value into the target address. We know instructions are
272 // 32-bit aligned, so we can do it all at once.
Sean Callanan61dfa772012-03-07 23:05:25 +0000273 uint32_t *p = (uint32_t*)LocalAddress;
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000274 // The low two bits of the value are not encoded.
275 Value >>= 2;
276 // Mask the value to 24 bits.
277 Value &= 0xffffff;
278 // FIXME: If the destination is a Thumb function (and the instruction
279 // is a non-predicated BL instruction), we need to change it to a BLX
280 // instruction instead.
281
282 // Insert the value into the instruction.
283 *p = (*p & ~0xffffff) | Value;
284 break;
285 }
286 case macho::RIT_ARM_ThumbBranch22Bit:
287 case macho::RIT_ARM_ThumbBranch32Bit:
288 case macho::RIT_ARM_Half:
289 case macho::RIT_ARM_HalfDifference:
290 case macho::RIT_Pair:
291 case macho::RIT_Difference:
292 case macho::RIT_ARM_LocalDifference:
293 case macho::RIT_ARM_PreboundLazyPointer:
294 return Error("Relocation type not implemented yet!");
295 }
296 return false;
297}
298
Rafael Espindolaefa91f62013-04-29 14:44:23 +0000299void RuntimeDyldMachO::processRelocationRef(unsigned SectionID,
Rafael Espindolaca0e7362013-04-29 19:03:21 +0000300 RelocationRef RelI,
Preston Gurd689ff9c2012-04-16 22:12:58 +0000301 ObjectImage &Obj,
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000302 ObjSectionToIDMap &ObjSectionToID,
Eli Benderskyd98c9e92012-05-01 06:58:59 +0000303 const SymbolTableMap &Symbols,
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000304 StubMap &Stubs) {
Rafael Espindolaefa91f62013-04-29 14:44:23 +0000305 const ObjectFile *OF = Obj.getObjectFile();
306 const MachOObjectFile *MachO = static_cast<const MachOObjectFile*>(OF);
Rafael Espindolaca0e7362013-04-29 19:03:21 +0000307 macho::RelocationEntry RE = MachO->getRelocation(RelI.getRawDataRefImpl());
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000308
Rafael Espindolaefa91f62013-04-29 14:44:23 +0000309 uint32_t RelType = MachO->getAnyRelocationType(RE);
Lang Hames623f2022013-08-09 00:57:01 +0000310
311 // FIXME: Properly handle scattered relocations.
312 // For now, optimistically skip these: they can often be ignored, as
313 // the static linker will already have applied the relocation, and it
314 // only needs to be reapplied if symbols move relative to one another.
315 // Note: This will fail horribly where the relocations *do* need to be
316 // applied, but that was already the case.
317 if (MachO->isRelocationScattered(RE))
318 return;
319
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000320 RelocationValueRef Value;
Rafael Espindolaefa91f62013-04-29 14:44:23 +0000321 SectionEntry &Section = Sections[SectionID];
Jim Grosbach61425c02012-01-16 22:26:39 +0000322
Rafael Espindolaefa91f62013-04-29 14:44:23 +0000323 bool isExtern = MachO->getPlainRelocationExternal(RE);
Rafael Espindola87b50172013-04-29 17:24:34 +0000324 bool IsPCRel = MachO->getAnyRelocationPCRel(RE);
325 unsigned Size = MachO->getAnyRelocationLength(RE);
Rafael Espindola8e6e02a2013-04-30 01:29:57 +0000326 uint64_t Offset;
327 RelI.getOffset(Offset);
Rafael Espindolae87dadc2013-04-30 15:40:54 +0000328 uint8_t *LocalAddress = Section.Address + Offset;
329 unsigned NumBytes = 1 << Size;
330 uint64_t Addend = 0;
331 memcpy(&Addend, LocalAddress, NumBytes);
Rafael Espindola8e6e02a2013-04-30 01:29:57 +0000332
Rafael Espindolae87dadc2013-04-30 15:40:54 +0000333 if (isExtern) {
Eli Benderskyc201e6e2012-05-01 10:41:12 +0000334 // Obtain the symbol name which is referenced in the relocation
Rafael Espindola6c1202c2013-06-05 01:33:53 +0000335 symbol_iterator Symbol = RelI.getSymbol();
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000336 StringRef TargetName;
Rafael Espindola6c1202c2013-06-05 01:33:53 +0000337 Symbol->getName(TargetName);
Eli Benderskyc201e6e2012-05-01 10:41:12 +0000338 // First search for the symbol in the local symbol table
Eli Benderskyd98c9e92012-05-01 06:58:59 +0000339 SymbolTableMap::const_iterator lsi = Symbols.find(TargetName.data());
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000340 if (lsi != Symbols.end()) {
341 Value.SectionID = lsi->second.first;
Rafael Espindola8e6e02a2013-04-30 01:29:57 +0000342 Value.Addend = lsi->second.second + Addend;
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000343 } else {
Eli Benderskyc201e6e2012-05-01 10:41:12 +0000344 // Search for the symbol in the global symbol table
Eli Benderskyd98c9e92012-05-01 06:58:59 +0000345 SymbolTableMap::const_iterator gsi = GlobalSymbolTable.find(TargetName.data());
346 if (gsi != GlobalSymbolTable.end()) {
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000347 Value.SectionID = gsi->second.first;
Rafael Espindola8e6e02a2013-04-30 01:29:57 +0000348 Value.Addend = gsi->second.second + Addend;
349 } else {
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000350 Value.SymbolName = TargetName.data();
Rafael Espindola8e6e02a2013-04-30 01:29:57 +0000351 Value.Addend = Addend;
352 }
Danil Malyshev4b0b8ef2012-03-29 21:46:18 +0000353 }
Bill Wendling288967d2012-03-29 23:23:59 +0000354 } else {
Rafael Espindolae87dadc2013-04-30 15:40:54 +0000355 SectionRef Sec = MachO->getRelocationSection(RE);
356 Value.SectionID = findOrEmitSection(Obj, Sec, true, ObjSectionToID);
357 uint64_t Addr;
358 Sec.getAddress(Addr);
359 Value.Addend = Addend - Addr;
Bill Wendling288967d2012-03-29 23:23:59 +0000360 }
361
Lang Hamesae7ac392013-08-15 22:31:40 +0000362 if (Arch == Triple::x86_64 && (RelType == macho::RIT_X86_64_GOT ||
363 RelType == macho::RIT_X86_64_GOTLoad)) {
Rafael Espindolaa2e40fb2013-05-05 20:43:10 +0000364 assert(IsPCRel);
365 assert(Size == 2);
366 StubMap::const_iterator i = Stubs.find(Value);
367 uint8_t *Addr;
368 if (i != Stubs.end()) {
369 Addr = Section.Address + i->second;
370 } else {
371 Stubs[Value] = Section.StubOffset;
372 uint8_t *GOTEntry = Section.Address + Section.StubOffset;
373 RelocationEntry RE(SectionID, Section.StubOffset,
Lang Hamesae7ac392013-08-15 22:31:40 +0000374 macho::RIT_X86_64_Unsigned, 0, false, 3);
Rafael Espindolaa2e40fb2013-05-05 20:43:10 +0000375 if (Value.SymbolName)
376 addRelocationForSymbol(RE, Value.SymbolName);
377 else
378 addRelocationForSection(RE, Value.SectionID);
379 Section.StubOffset += 8;
380 Addr = GOTEntry;
381 }
382 resolveRelocation(Section, Offset, (uint64_t)Addr,
Lang Hamesae7ac392013-08-15 22:31:40 +0000383 macho::RIT_X86_64_Unsigned, Value.Addend, true, 2);
Rafael Espindolaa2e40fb2013-05-05 20:43:10 +0000384 } else if (Arch == Triple::arm &&
385 (RelType & 0xf) == macho::RIT_ARM_Branch24Bit) {
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000386 // This is an ARM branch relocation, need to use a stub function.
Bill Wendling288967d2012-03-29 23:23:59 +0000387
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000388 // Look up for existing stub.
389 StubMap::const_iterator i = Stubs.find(Value);
390 if (i != Stubs.end())
Rafael Espindolaefa91f62013-04-29 14:44:23 +0000391 resolveRelocation(Section, Offset,
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000392 (uint64_t)Section.Address + i->second,
Rafael Espindola87b50172013-04-29 17:24:34 +0000393 RelType, 0, IsPCRel, Size);
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000394 else {
395 // Create a new stub function.
396 Stubs[Value] = Section.StubOffset;
397 uint8_t *StubTargetAddr = createStubFunction(Section.Address +
398 Section.StubOffset);
Rafael Espindolaefa91f62013-04-29 14:44:23 +0000399 RelocationEntry RE(SectionID, StubTargetAddr - Section.Address,
Eli Benderskyc201e6e2012-05-01 10:41:12 +0000400 macho::RIT_Vanilla, Value.Addend);
401 if (Value.SymbolName)
402 addRelocationForSymbol(RE, Value.SymbolName);
403 else
404 addRelocationForSection(RE, Value.SectionID);
Rafael Espindolaefa91f62013-04-29 14:44:23 +0000405 resolveRelocation(Section, Offset,
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000406 (uint64_t)Section.Address + Section.StubOffset,
Rafael Espindola87b50172013-04-29 17:24:34 +0000407 RelType, 0, IsPCRel, Size);
Danil Malyshev0e4fa5f2012-03-30 16:45:19 +0000408 Section.StubOffset += getMaxStubSize();
409 }
Eli Benderskyc201e6e2012-05-01 10:41:12 +0000410 } else {
Rafael Espindola87b50172013-04-29 17:24:34 +0000411 RelocationEntry RE(SectionID, Offset, RelType, Value.Addend,
412 IsPCRel, Size);
Eli Benderskyc201e6e2012-05-01 10:41:12 +0000413 if (Value.SymbolName)
414 addRelocationForSymbol(RE, Value.SymbolName);
415 else
416 addRelocationForSection(RE, Value.SectionID);
417 }
Bill Wendling288967d2012-03-29 23:23:59 +0000418}
419
Bill Wendling288967d2012-03-29 23:23:59 +0000420
Eli Bendersky6d15e872012-04-30 10:06:27 +0000421bool RuntimeDyldMachO::isCompatibleFormat(
Andrew Kaylor3f23cef2012-10-02 21:18:39 +0000422 const ObjectBuffer *InputBuffer) const {
423 if (InputBuffer->getBufferSize() < 4)
424 return false;
425 StringRef Magic(InputBuffer->getBufferStart(), 4);
Danil Malyshevcf852dc2011-07-13 07:57:58 +0000426 if (Magic == "\xFE\xED\xFA\xCE") return true;
427 if (Magic == "\xCE\xFA\xED\xFE") return true;
428 if (Magic == "\xFE\xED\xFA\xCF") return true;
429 if (Magic == "\xCF\xFA\xED\xFE") return true;
430 return false;
431}
432
433} // end namespace llvm