Jim Grosbach | e0934be | 2012-01-16 23:50:58 +0000 | [diff] [blame] | 1 | //===-- RuntimeDyldMachO.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-=// |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 2 | // |
| 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 Bendersky | 76463fd | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 15 | #include "RuntimeDyldMachO.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/OwningPtr.h" |
| 17 | #include "llvm/ADT/STLExtras.h" |
| 18 | #include "llvm/ADT/StringRef.h" |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | using namespace llvm::object; |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
Andrew Kaylor | a307a1c | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 24 | void RuntimeDyldMachO::resolveRelocation(const SectionEntry &Section, |
| 25 | uint64_t Offset, |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 26 | uint64_t Value, |
| 27 | uint32_t Type, |
| 28 | int64_t Addend) { |
Andrew Kaylor | a307a1c | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 29 | uint8_t *LocalAddress = Section.Address + Offset; |
| 30 | uint64_t FinalAddress = Section.LoadAddress + Offset; |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 31 | bool isPCRel = (Type >> 24) & 1; |
| 32 | unsigned MachoType = (Type >> 28) & 0xf; |
| 33 | unsigned Size = 1 << ((Type >> 25) & 3); |
| 34 | |
Eli Bendersky | 6d15e87 | 2012-04-30 10:06:27 +0000 | [diff] [blame] | 35 | DEBUG(dbgs() << "resolveRelocation LocalAddress: " |
| 36 | << format("%p", LocalAddress) |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 37 | << " FinalAddress: " << format("%p", FinalAddress) |
| 38 | << " Value: " << format("%p", Value) |
| 39 | << " Addend: " << Addend |
| 40 | << " isPCRel: " << isPCRel |
| 41 | << " MachoType: " << MachoType |
| 42 | << " Size: " << Size |
| 43 | << "\n"); |
| 44 | |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 45 | // This just dispatches to the proper target specific routine. |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 46 | switch (Arch) { |
Craig Topper | 8581438 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 47 | default: llvm_unreachable("Unsupported CPU type!"); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 48 | case Triple::x86_64: |
| 49 | resolveX86_64Relocation(LocalAddress, |
| 50 | FinalAddress, |
| 51 | (uintptr_t)Value, |
| 52 | isPCRel, |
| 53 | MachoType, |
| 54 | Size, |
| 55 | Addend); |
| 56 | break; |
| 57 | case Triple::x86: |
| 58 | resolveI386Relocation(LocalAddress, |
Eli Bendersky | 6d15e87 | 2012-04-30 10:06:27 +0000 | [diff] [blame] | 59 | FinalAddress, |
| 60 | (uintptr_t)Value, |
| 61 | isPCRel, |
Jim Grosbach | ba9ba9f | 2012-09-13 01:24:32 +0000 | [diff] [blame] | 62 | MachoType, |
Eli Bendersky | 6d15e87 | 2012-04-30 10:06:27 +0000 | [diff] [blame] | 63 | Size, |
| 64 | Addend); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 65 | break; |
| 66 | case Triple::arm: // Fall through. |
| 67 | case Triple::thumb: |
| 68 | resolveARMRelocation(LocalAddress, |
| 69 | FinalAddress, |
| 70 | (uintptr_t)Value, |
| 71 | isPCRel, |
| 72 | MachoType, |
| 73 | Size, |
| 74 | Addend); |
| 75 | break; |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 76 | } |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Eli Bendersky | 6d15e87 | 2012-04-30 10:06:27 +0000 | [diff] [blame] | 79 | bool RuntimeDyldMachO::resolveI386Relocation(uint8_t *LocalAddress, |
| 80 | uint64_t FinalAddress, |
| 81 | uint64_t Value, |
| 82 | bool isPCRel, |
| 83 | unsigned Type, |
| 84 | unsigned Size, |
| 85 | int64_t Addend) { |
Sean Callanan | b38aae4 | 2012-03-26 20:45:52 +0000 | [diff] [blame] | 86 | if (isPCRel) |
| 87 | Value -= FinalAddress + 4; // see resolveX86_64Relocation |
| 88 | |
| 89 | switch (Type) { |
| 90 | default: |
| 91 | llvm_unreachable("Invalid relocation type!"); |
| 92 | case macho::RIT_Vanilla: { |
| 93 | uint8_t *p = LocalAddress; |
| 94 | uint64_t ValueToWrite = Value + Addend; |
| 95 | for (unsigned i = 0; i < Size; ++i) { |
| 96 | *p++ = (uint8_t)(ValueToWrite & 0xff); |
| 97 | ValueToWrite >>= 8; |
| 98 | } |
Jim Grosbach | 6f6f171 | 2013-01-31 19:46:28 +0000 | [diff] [blame] | 99 | return false; |
Sean Callanan | b38aae4 | 2012-03-26 20:45:52 +0000 | [diff] [blame] | 100 | } |
| 101 | case macho::RIT_Difference: |
| 102 | case macho::RIT_Generic_LocalDifference: |
| 103 | case macho::RIT_Generic_PreboundLazyPointer: |
| 104 | return Error("Relocation type not implemented yet!"); |
| 105 | } |
| 106 | } |
| 107 | |
Eli Bendersky | 6d15e87 | 2012-04-30 10:06:27 +0000 | [diff] [blame] | 108 | bool RuntimeDyldMachO::resolveX86_64Relocation(uint8_t *LocalAddress, |
| 109 | uint64_t FinalAddress, |
| 110 | uint64_t Value, |
| 111 | bool isPCRel, |
| 112 | unsigned Type, |
| 113 | unsigned Size, |
| 114 | int64_t Addend) { |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 115 | // If the relocation is PC-relative, the value to be encoded is the |
| 116 | // pointer difference. |
| 117 | if (isPCRel) |
| 118 | // FIXME: It seems this value needs to be adjusted by 4 for an effective PC |
| 119 | // address. Is that expected? Only for branches, perhaps? |
Sean Callanan | 61dfa77 | 2012-03-07 23:05:25 +0000 | [diff] [blame] | 120 | Value -= FinalAddress + 4; |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 121 | |
| 122 | switch(Type) { |
| 123 | default: |
| 124 | llvm_unreachable("Invalid relocation type!"); |
Jim Grosbach | 652ca2f | 2012-01-16 23:50:49 +0000 | [diff] [blame] | 125 | case macho::RIT_X86_64_Signed1: |
| 126 | case macho::RIT_X86_64_Signed2: |
| 127 | case macho::RIT_X86_64_Signed4: |
| 128 | case macho::RIT_X86_64_Signed: |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 129 | case macho::RIT_X86_64_Unsigned: |
| 130 | case macho::RIT_X86_64_Branch: { |
Jim Grosbach | 652ca2f | 2012-01-16 23:50:49 +0000 | [diff] [blame] | 131 | Value += Addend; |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 132 | // Mask in the target value a byte at a time (we don't have an alignment |
| 133 | // guarantee for the target address, so this is safest). |
Sean Callanan | 61dfa77 | 2012-03-07 23:05:25 +0000 | [diff] [blame] | 134 | uint8_t *p = (uint8_t*)LocalAddress; |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 135 | for (unsigned i = 0; i < Size; ++i) { |
| 136 | *p++ = (uint8_t)Value; |
| 137 | Value >>= 8; |
| 138 | } |
| 139 | return false; |
| 140 | } |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 141 | case macho::RIT_X86_64_GOTLoad: |
| 142 | case macho::RIT_X86_64_GOT: |
| 143 | case macho::RIT_X86_64_Subtractor: |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 144 | case macho::RIT_X86_64_TLV: |
| 145 | return Error("Relocation type not implemented yet!"); |
| 146 | } |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Eli Bendersky | 6d15e87 | 2012-04-30 10:06:27 +0000 | [diff] [blame] | 149 | bool RuntimeDyldMachO::resolveARMRelocation(uint8_t *LocalAddress, |
| 150 | uint64_t FinalAddress, |
| 151 | uint64_t Value, |
| 152 | bool isPCRel, |
| 153 | unsigned Type, |
| 154 | unsigned Size, |
| 155 | int64_t Addend) { |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 156 | // If the relocation is PC-relative, the value to be encoded is the |
| 157 | // pointer difference. |
| 158 | if (isPCRel) { |
Sean Callanan | 61dfa77 | 2012-03-07 23:05:25 +0000 | [diff] [blame] | 159 | Value -= FinalAddress; |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 160 | // ARM PCRel relocations have an effective-PC offset of two instructions |
| 161 | // (four bytes in Thumb mode, 8 bytes in ARM mode). |
| 162 | // FIXME: For now, assume ARM mode. |
| 163 | Value -= 8; |
| 164 | } |
| 165 | |
| 166 | switch(Type) { |
| 167 | default: |
| 168 | llvm_unreachable("Invalid relocation type!"); |
| 169 | case macho::RIT_Vanilla: { |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 170 | // Mask in the target value a byte at a time (we don't have an alignment |
| 171 | // guarantee for the target address, so this is safest). |
Sean Callanan | 61dfa77 | 2012-03-07 23:05:25 +0000 | [diff] [blame] | 172 | uint8_t *p = (uint8_t*)LocalAddress; |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 173 | for (unsigned i = 0; i < Size; ++i) { |
| 174 | *p++ = (uint8_t)Value; |
| 175 | Value >>= 8; |
| 176 | } |
| 177 | break; |
| 178 | } |
| 179 | case macho::RIT_ARM_Branch24Bit: { |
| 180 | // Mask the value into the target address. We know instructions are |
| 181 | // 32-bit aligned, so we can do it all at once. |
Sean Callanan | 61dfa77 | 2012-03-07 23:05:25 +0000 | [diff] [blame] | 182 | uint32_t *p = (uint32_t*)LocalAddress; |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 183 | // The low two bits of the value are not encoded. |
| 184 | Value >>= 2; |
| 185 | // Mask the value to 24 bits. |
| 186 | Value &= 0xffffff; |
| 187 | // FIXME: If the destination is a Thumb function (and the instruction |
| 188 | // is a non-predicated BL instruction), we need to change it to a BLX |
| 189 | // instruction instead. |
| 190 | |
| 191 | // Insert the value into the instruction. |
| 192 | *p = (*p & ~0xffffff) | Value; |
| 193 | break; |
| 194 | } |
| 195 | case macho::RIT_ARM_ThumbBranch22Bit: |
| 196 | case macho::RIT_ARM_ThumbBranch32Bit: |
| 197 | case macho::RIT_ARM_Half: |
| 198 | case macho::RIT_ARM_HalfDifference: |
| 199 | case macho::RIT_Pair: |
| 200 | case macho::RIT_Difference: |
| 201 | case macho::RIT_ARM_LocalDifference: |
| 202 | case macho::RIT_ARM_PreboundLazyPointer: |
| 203 | return Error("Relocation type not implemented yet!"); |
| 204 | } |
| 205 | return false; |
| 206 | } |
| 207 | |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 208 | void RuntimeDyldMachO::processRelocationRef(unsigned SectionID, |
| 209 | relocation_iterator RelI, |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 210 | ObjectImage &Obj, |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 211 | ObjSectionToIDMap &ObjSectionToID, |
Eli Bendersky | d98c9e9 | 2012-05-01 06:58:59 +0000 | [diff] [blame] | 212 | const SymbolTableMap &Symbols, |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 213 | StubMap &Stubs) { |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 214 | const ObjectFile *OF = Obj.getObjectFile(); |
| 215 | const MachOObjectFile *MachO = static_cast<const MachOObjectFile*>(OF); |
| 216 | macho::RelocationEntry RE = MachO->getRelocation(RelI->getRawDataRefImpl()); |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 217 | |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 218 | uint32_t RelType = MachO->getAnyRelocationType(RE); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 219 | RelocationValueRef Value; |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 220 | SectionEntry &Section = Sections[SectionID]; |
Jim Grosbach | 61425c0 | 2012-01-16 22:26:39 +0000 | [diff] [blame] | 221 | |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 222 | bool isExtern = MachO->getPlainRelocationExternal(RE); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 223 | if (isExtern) { |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 224 | // Obtain the symbol name which is referenced in the relocation |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 225 | SymbolRef Symbol; |
| 226 | RelI->getSymbol(Symbol); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 227 | StringRef TargetName; |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 228 | Symbol.getName(TargetName); |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 229 | // First search for the symbol in the local symbol table |
Eli Bendersky | d98c9e9 | 2012-05-01 06:58:59 +0000 | [diff] [blame] | 230 | SymbolTableMap::const_iterator lsi = Symbols.find(TargetName.data()); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 231 | if (lsi != Symbols.end()) { |
| 232 | Value.SectionID = lsi->second.first; |
| 233 | Value.Addend = lsi->second.second; |
| 234 | } else { |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 235 | // Search for the symbol in the global symbol table |
Eli Bendersky | d98c9e9 | 2012-05-01 06:58:59 +0000 | [diff] [blame] | 236 | SymbolTableMap::const_iterator gsi = GlobalSymbolTable.find(TargetName.data()); |
| 237 | if (gsi != GlobalSymbolTable.end()) { |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 238 | Value.SectionID = gsi->second.first; |
| 239 | Value.Addend = gsi->second.second; |
| 240 | } else |
| 241 | Value.SymbolName = TargetName.data(); |
Danil Malyshev | 4b0b8ef | 2012-03-29 21:46:18 +0000 | [diff] [blame] | 242 | } |
Bill Wendling | 288967d | 2012-03-29 23:23:59 +0000 | [diff] [blame] | 243 | } else { |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 244 | error_code err; |
| 245 | uint8_t sectionIndex = static_cast<uint8_t>(RelType & 0xFF); |
| 246 | section_iterator si = Obj.begin_sections(), |
| 247 | se = Obj.end_sections(); |
| 248 | for (uint8_t i = 1; i < sectionIndex; i++) { |
| 249 | error_code err; |
| 250 | si.increment(err); |
| 251 | if (si == se) |
| 252 | break; |
| 253 | } |
| 254 | assert(si != se && "No section containing relocation!"); |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 255 | Value.SectionID = findOrEmitSection(Obj, *si, true, ObjSectionToID); |
Jim Grosbach | 7639f98 | 2012-09-13 01:24:37 +0000 | [diff] [blame] | 256 | Value.Addend = 0; |
| 257 | // FIXME: The size and type of the relocation determines if we can |
| 258 | // encode an Addend in the target location itself, and if so, how many |
| 259 | // bytes we should read in order to get it. We don't yet support doing |
| 260 | // that, and just assuming it's sizeof(intptr_t) is blatantly wrong. |
| 261 | //Value.Addend = *(const intptr_t *)Target; |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 262 | if (Value.Addend) { |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 263 | // The MachO addend is an offset from the current section. We need it |
| 264 | // to be an offset from the destination section |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 265 | Value.Addend += Section.ObjAddress - Sections[Value.SectionID].ObjAddress; |
| 266 | } |
Bill Wendling | 288967d | 2012-03-29 23:23:59 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 269 | uint64_t Offset; |
| 270 | RelI->getOffset(Offset); |
Jim Grosbach | 01e1a97 | 2012-09-13 01:24:35 +0000 | [diff] [blame] | 271 | if (Arch == Triple::arm && (RelType & 0xf) == macho::RIT_ARM_Branch24Bit) { |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 272 | // This is an ARM branch relocation, need to use a stub function. |
Bill Wendling | 288967d | 2012-03-29 23:23:59 +0000 | [diff] [blame] | 273 | |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 274 | // Look up for existing stub. |
| 275 | StubMap::const_iterator i = Stubs.find(Value); |
| 276 | if (i != Stubs.end()) |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 277 | resolveRelocation(Section, Offset, |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 278 | (uint64_t)Section.Address + i->second, |
| 279 | RelType, 0); |
| 280 | else { |
| 281 | // Create a new stub function. |
| 282 | Stubs[Value] = Section.StubOffset; |
| 283 | uint8_t *StubTargetAddr = createStubFunction(Section.Address + |
| 284 | Section.StubOffset); |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 285 | RelocationEntry RE(SectionID, StubTargetAddr - Section.Address, |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 286 | macho::RIT_Vanilla, Value.Addend); |
| 287 | if (Value.SymbolName) |
| 288 | addRelocationForSymbol(RE, Value.SymbolName); |
| 289 | else |
| 290 | addRelocationForSection(RE, Value.SectionID); |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 291 | resolveRelocation(Section, Offset, |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 292 | (uint64_t)Section.Address + Section.StubOffset, |
| 293 | RelType, 0); |
| 294 | Section.StubOffset += getMaxStubSize(); |
| 295 | } |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 296 | } else { |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame^] | 297 | RelocationEntry RE(SectionID, Offset, RelType, Value.Addend); |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 298 | if (Value.SymbolName) |
| 299 | addRelocationForSymbol(RE, Value.SymbolName); |
| 300 | else |
| 301 | addRelocationForSection(RE, Value.SectionID); |
| 302 | } |
Bill Wendling | 288967d | 2012-03-29 23:23:59 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Bill Wendling | 288967d | 2012-03-29 23:23:59 +0000 | [diff] [blame] | 305 | |
Eli Bendersky | 6d15e87 | 2012-04-30 10:06:27 +0000 | [diff] [blame] | 306 | bool RuntimeDyldMachO::isCompatibleFormat( |
Andrew Kaylor | 3f23cef | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 307 | const ObjectBuffer *InputBuffer) const { |
| 308 | if (InputBuffer->getBufferSize() < 4) |
| 309 | return false; |
| 310 | StringRef Magic(InputBuffer->getBufferStart(), 4); |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 311 | if (Magic == "\xFE\xED\xFA\xCE") return true; |
| 312 | if (Magic == "\xCE\xFA\xED\xFE") return true; |
| 313 | if (Magic == "\xFE\xED\xFA\xCF") return true; |
| 314 | if (Magic == "\xCF\xFA\xED\xFE") return true; |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | } // end namespace llvm |