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!");
36 return resolveI386Relocation(LocalAddress,
43 case mach::CTM_x86_64:
44 return resolveX86_64Relocation(LocalAddress,
52 return resolveARMRelocation(LocalAddress,
62 bool RuntimeDyldMachO::
63 resolveI386Relocation(uint8_t *LocalAddress,
64 uint64_t FinalAddress,
71 Value -= FinalAddress + 4; // see resolveX86_64Relocation
75 llvm_unreachable("Invalid relocation type!");
76 case macho::RIT_Vanilla: {
77 uint8_t *p = LocalAddress;
78 uint64_t ValueToWrite = Value + Addend;
79 for (unsigned i = 0; i < Size; ++i) {
80 *p++ = (uint8_t)(ValueToWrite & 0xff);
84 case macho::RIT_Difference:
85 case macho::RIT_Generic_LocalDifference:
86 case macho::RIT_Generic_PreboundLazyPointer:
87 return Error("Relocation type not implemented yet!");
91 bool RuntimeDyldMachO::
92 resolveX86_64Relocation(uint8_t *LocalAddress,
93 uint64_t FinalAddress,
99 // If the relocation is PC-relative, the value to be encoded is the
100 // pointer difference.
102 // FIXME: It seems this value needs to be adjusted by 4 for an effective PC
103 // address. Is that expected? Only for branches, perhaps?
104 Value -= FinalAddress + 4;
108 llvm_unreachable("Invalid relocation type!");
109 case macho::RIT_X86_64_Signed1:
110 case macho::RIT_X86_64_Signed2:
111 case macho::RIT_X86_64_Signed4:
112 case macho::RIT_X86_64_Signed:
113 case macho::RIT_X86_64_Unsigned:
114 case macho::RIT_X86_64_Branch: {
116 // Mask in the target value a byte at a time (we don't have an alignment
117 // guarantee for the target address, so this is safest).
118 uint8_t *p = (uint8_t*)LocalAddress;
119 for (unsigned i = 0; i < Size; ++i) {
120 *p++ = (uint8_t)Value;
125 case macho::RIT_X86_64_GOTLoad:
126 case macho::RIT_X86_64_GOT:
127 case macho::RIT_X86_64_Subtractor:
128 case macho::RIT_X86_64_TLV:
129 return Error("Relocation type not implemented yet!");
133 bool RuntimeDyldMachO::
134 resolveARMRelocation(uint8_t *LocalAddress,
135 uint64_t FinalAddress,
141 // If the relocation is PC-relative, the value to be encoded is the
142 // pointer difference.
144 Value -= FinalAddress;
145 // ARM PCRel relocations have an effective-PC offset of two instructions
146 // (four bytes in Thumb mode, 8 bytes in ARM mode).
147 // FIXME: For now, assume ARM mode.
153 llvm_unreachable("Invalid relocation type!");
154 case macho::RIT_Vanilla: {
155 // Mask in the target value a byte at a time (we don't have an alignment
156 // guarantee for the target address, so this is safest).
157 uint8_t *p = (uint8_t*)LocalAddress;
158 for (unsigned i = 0; i < Size; ++i) {
159 *p++ = (uint8_t)Value;
164 case macho::RIT_ARM_Branch24Bit: {
165 // Mask the value into the target address. We know instructions are
166 // 32-bit aligned, so we can do it all at once.
167 uint32_t *p = (uint32_t*)LocalAddress;
168 // The low two bits of the value are not encoded.
170 // Mask the value to 24 bits.
172 // FIXME: If the destination is a Thumb function (and the instruction
173 // is a non-predicated BL instruction), we need to change it to a BLX
174 // instruction instead.
176 // Insert the value into the instruction.
177 *p = (*p & ~0xffffff) | Value;
180 case macho::RIT_ARM_ThumbBranch22Bit:
181 case macho::RIT_ARM_ThumbBranch32Bit:
182 case macho::RIT_ARM_Half:
183 case macho::RIT_ARM_HalfDifference:
184 case macho::RIT_Pair:
185 case macho::RIT_Difference:
186 case macho::RIT_ARM_LocalDifference:
187 case macho::RIT_ARM_PreboundLazyPointer:
188 return Error("Relocation type not implemented yet!");
193 bool RuntimeDyldMachO::
194 loadSegment32(const MachOObject *Obj,
195 const MachOObject::LoadCommandInfo *SegmentLCI,
196 const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC) {
197 // FIXME: This should really be combined w/ loadSegment64. Templatized
198 // function on the 32/64 datatypes maybe?
199 InMemoryStruct<macho::SegmentLoadCommand> SegmentLC;
200 Obj->ReadSegmentLoadCommand(*SegmentLCI, SegmentLC);
202 return Error("unable to load segment load command");
205 SmallVector<unsigned, 16> SectionMap;
206 for (unsigned SectNum = 0; SectNum != SegmentLC->NumSections; ++SectNum) {
207 InMemoryStruct<macho::Section> Sect;
208 Obj->ReadSection(*SegmentLCI, SectNum, Sect);
210 return Error("unable to load section: '" + Twine(SectNum) + "'");
212 // Allocate memory via the MM for the section.
214 uint32_t SectionID = Sections.size();
215 if (Sect->Flags == 0x80000400)
216 Buffer = MemMgr->allocateCodeSection(Sect->Size, Sect->Align, SectionID);
218 Buffer = MemMgr->allocateDataSection(Sect->Size, Sect->Align, SectionID);
220 DEBUG(dbgs() << "Loading "
221 << ((Sect->Flags == 0x80000400) ? "text" : "data")
222 << " (ID #" << SectionID << ")"
223 << " '" << Sect->SegmentName << ","
224 << Sect->Name << "' of size " << Sect->Size
225 << " to address " << Buffer << ".\n");
227 // Copy the payload from the object file into the allocated buffer.
228 uint8_t *Base = (uint8_t*)Obj->getData(SegmentLC->FileOffset,
229 SegmentLC->FileSize).data();
230 memcpy(Buffer, Base + Sect->Address, Sect->Size);
232 // Remember what got allocated for this SectionID.
233 Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
234 SectionLocalMemToID[Buffer] = SectionID;
236 // By default, the load address of a section is its memory buffer.
237 SectionLoadAddress.push_back((uint64_t)Buffer);
239 // Keep a map of object file section numbers to corresponding SectionIDs
240 // while processing the file.
241 SectionMap.push_back(SectionID);
244 // Process the symbol table.
245 SmallVector<StringRef, 64> SymbolNames;
246 processSymbols32(Obj, SectionMap, SymbolNames, SymtabLC);
248 // Process the relocations for each section we're loading.
249 Relocations.grow(Relocations.size() + SegmentLC->NumSections);
250 Referrers.grow(Referrers.size() + SegmentLC->NumSections);
251 for (unsigned SectNum = 0; SectNum != SegmentLC->NumSections; ++SectNum) {
252 InMemoryStruct<macho::Section> Sect;
253 Obj->ReadSection(*SegmentLCI, SectNum, Sect);
255 return Error("unable to load section: '" + Twine(SectNum) + "'");
256 for (unsigned j = 0; j != Sect->NumRelocationTableEntries; ++j) {
257 InMemoryStruct<macho::RelocationEntry> RE;
258 Obj->ReadRelocationEntry(Sect->RelocationTableOffset, j, RE);
259 if (RE->Word0 & macho::RF_Scattered)
260 return Error("NOT YET IMPLEMENTED: scattered relocations.");
261 // Word0 of the relocation is the offset into the section where the
262 // relocation should be applied. We need to translate that into an
263 // offset into a function since that's our atom.
264 uint32_t Offset = RE->Word0;
265 bool isExtern = (RE->Word1 >> 27) & 1;
267 // FIXME: Get the relocation addend from the target address.
268 // FIXME: VERY imporant for internal relocations.
270 // Figure out the source symbol of the relocation. If isExtern is true,
271 // this relocation references the symbol table, otherwise it references
272 // a section in the same object, numbered from 1 through NumSections
273 // (SectionBases is [0, NumSections-1]).
274 uint32_t SourceNum = RE->Word1 & 0xffffff; // 24-bit value
276 assert(SourceNum > 0 && "Invalid relocation section number!");
277 unsigned SectionID = SectionMap[SourceNum - 1];
278 unsigned TargetID = SectionMap[SectNum];
279 DEBUG(dbgs() << "Internal relocation at Section #"
280 << TargetID << " + " << Offset
282 << SectionID << " (Word1: "
283 << format("0x%x", RE->Word1) << ")\n");
285 // Store the relocation information. It will get resolved when
286 // the section addresses are assigned.
287 uint32_t RelocationIndex = Relocations[SectionID].size();
288 Relocations[SectionID].push_back(RelocationEntry(TargetID,
292 Referrers[TargetID].push_back(Referrer(SectionID, RelocationIndex));
294 StringRef SourceName = SymbolNames[SourceNum];
296 // Now store the relocation information. Associate it with the source
297 // symbol. Just add it to the unresolved list and let the general
298 // path post-load resolve it if we know where the symbol is.
299 UnresolvedRelocations[SourceName].push_back(RelocationEntry(SectNum,
303 DEBUG(dbgs() << "Relocation at Section #" << SectNum << " + " << Offset
304 << " from '" << SourceName << "(Word1: "
305 << format("0x%x", RE->Word1) << ")\n");
310 // Resolve the addresses of any symbols that were defined in this segment.
311 for (int i = 0, e = SymbolNames.size(); i != e; ++i)
312 resolveSymbol(SymbolNames[i]);
318 bool RuntimeDyldMachO::
319 loadSegment64(const MachOObject *Obj,
320 const MachOObject::LoadCommandInfo *SegmentLCI,
321 const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC) {
322 InMemoryStruct<macho::Segment64LoadCommand> Segment64LC;
323 Obj->ReadSegment64LoadCommand(*SegmentLCI, Segment64LC);
325 return Error("unable to load segment load command");
328 SmallVector<unsigned, 16> SectionMap;
329 for (unsigned SectNum = 0; SectNum != Segment64LC->NumSections; ++SectNum) {
330 InMemoryStruct<macho::Section64> Sect;
331 Obj->ReadSection64(*SegmentLCI, SectNum, Sect);
333 return Error("unable to load section: '" + Twine(SectNum) + "'");
335 // Allocate memory via the MM for the section.
337 uint32_t SectionID = Sections.size();
338 unsigned Align = 1 << Sect->Align; // .o file has log2 alignment.
339 if (Sect->Flags == 0x80000400)
340 Buffer = MemMgr->allocateCodeSection(Sect->Size, Align, SectionID);
342 Buffer = MemMgr->allocateDataSection(Sect->Size, Align, SectionID);
344 DEBUG(dbgs() << "Loading "
345 << ((Sect->Flags == 0x80000400) ? "text" : "data")
346 << " (ID #" << SectionID << ")"
347 << " '" << Sect->SegmentName << ","
348 << Sect->Name << "' of size " << Sect->Size
349 << " (align " << Align << ")"
350 << " to address " << Buffer << ".\n");
352 // Copy the payload from the object file into the allocated buffer.
353 uint8_t *Base = (uint8_t*)Obj->getData(Segment64LC->FileOffset,
354 Segment64LC->FileSize).data();
355 memcpy(Buffer, Base + Sect->Address, Sect->Size);
357 // Remember what got allocated for this SectionID.
358 Sections.push_back(sys::MemoryBlock(Buffer, Sect->Size));
359 SectionLocalMemToID[Buffer] = SectionID;
361 // By default, the load address of a section is its memory buffer.
362 SectionLoadAddress.push_back((uint64_t)Buffer);
364 // Keep a map of object file section numbers to corresponding SectionIDs
365 // while processing the file.
366 SectionMap.push_back(SectionID);
369 // Process the symbol table.
370 SmallVector<StringRef, 64> SymbolNames;
371 processSymbols64(Obj, SectionMap, SymbolNames, SymtabLC);
373 // Process the relocations for each section we're loading.
374 Relocations.grow(Relocations.size() + Segment64LC->NumSections);
375 Referrers.grow(Referrers.size() + Segment64LC->NumSections);
376 for (unsigned SectNum = 0; SectNum != Segment64LC->NumSections; ++SectNum) {
377 InMemoryStruct<macho::Section64> Sect;
378 Obj->ReadSection64(*SegmentLCI, SectNum, Sect);
380 return Error("unable to load section: '" + Twine(SectNum) + "'");
381 for (unsigned j = 0; j != Sect->NumRelocationTableEntries; ++j) {
382 InMemoryStruct<macho::RelocationEntry> RE;
383 Obj->ReadRelocationEntry(Sect->RelocationTableOffset, j, RE);
384 if (RE->Word0 & macho::RF_Scattered)
385 return Error("NOT YET IMPLEMENTED: scattered relocations.");
386 // Word0 of the relocation is the offset into the section where the
387 // relocation should be applied. We need to translate that into an
388 // offset into a function since that's our atom.
389 uint32_t Offset = RE->Word0;
390 bool isExtern = (RE->Word1 >> 27) & 1;
392 // FIXME: Get the relocation addend from the target address.
393 // FIXME: VERY imporant for internal relocations.
395 // Figure out the source symbol of the relocation. If isExtern is true,
396 // this relocation references the symbol table, otherwise it references
397 // a section in the same object, numbered from 1 through NumSections
398 // (SectionBases is [0, NumSections-1]).
399 uint32_t SourceNum = RE->Word1 & 0xffffff; // 24-bit value
401 assert(SourceNum > 0 && "Invalid relocation section number!");
402 unsigned SectionID = SectionMap[SourceNum - 1];
403 unsigned TargetID = SectionMap[SectNum];
404 DEBUG(dbgs() << "Internal relocation at Section #"
405 << TargetID << " + " << Offset
407 << SectionID << " (Word1: "
408 << format("0x%x", RE->Word1) << ")\n");
410 // Store the relocation information. It will get resolved when
411 // the section addresses are assigned.
412 uint32_t RelocationIndex = Relocations[SectionID].size();
413 Relocations[SectionID].push_back(RelocationEntry(TargetID,
417 Referrers[TargetID].push_back(Referrer(SectionID, RelocationIndex));
419 StringRef SourceName = SymbolNames[SourceNum];
421 // Now store the relocation information. Associate it with the source
422 // symbol. Just add it to the unresolved list and let the general
423 // path post-load resolve it if we know where the symbol is.
424 UnresolvedRelocations[SourceName].push_back(RelocationEntry(SectNum,
428 DEBUG(dbgs() << "Relocation at Section #" << SectNum << " + " << Offset
429 << " from '" << SourceName << "(Word1: "
430 << format("0x%x", RE->Word1) << ")\n");
435 // Resolve the addresses of any symbols that were defined in this segment.
436 for (int i = 0, e = SymbolNames.size(); i != e; ++i)
437 resolveSymbol(SymbolNames[i]);
442 bool RuntimeDyldMachO::
443 processSymbols32(const MachOObject *Obj,
444 SmallVectorImpl<unsigned> &SectionMap,
445 SmallVectorImpl<StringRef> &SymbolNames,
446 const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC) {
447 // FIXME: Combine w/ processSymbols64. Factor 64/32 datatype and such.
448 for (unsigned i = 0; i != SymtabLC->NumSymbolTableEntries; ++i) {
449 InMemoryStruct<macho::SymbolTableEntry> STE;
450 Obj->ReadSymbolTableEntry(SymtabLC->SymbolTableOffset, i, STE);
452 return Error("unable to read symbol: '" + Twine(i) + "'");
453 // Get the symbol name.
454 StringRef Name = Obj->getStringAtIndex(STE->StringIndex);
455 SymbolNames.push_back(Name);
457 // FIXME: Check the symbol type and flags.
458 if (STE->Type != 0xF) // external, defined in this segment.
460 // Flags in the upper nibble we don't care about.
461 if ((STE->Flags & 0xf) != 0x0)
464 // Remember the symbol.
465 uint32_t SectionID = SectionMap[STE->SectionIndex - 1];
466 SymbolTable[Name] = SymbolLoc(SectionID, STE->Value);
468 DEBUG(dbgs() << "Symbol: '" << Name << "' @ "
469 << (getSectionAddress(SectionID) + STE->Value)
475 bool RuntimeDyldMachO::
476 processSymbols64(const MachOObject *Obj,
477 SmallVectorImpl<unsigned> &SectionMap,
478 SmallVectorImpl<StringRef> &SymbolNames,
479 const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC) {
480 for (unsigned i = 0; i != SymtabLC->NumSymbolTableEntries; ++i) {
481 InMemoryStruct<macho::Symbol64TableEntry> STE;
482 Obj->ReadSymbol64TableEntry(SymtabLC->SymbolTableOffset, i, STE);
484 return Error("unable to read symbol: '" + Twine(i) + "'");
485 // Get the symbol name.
486 StringRef Name = Obj->getStringAtIndex(STE->StringIndex);
487 SymbolNames.push_back(Name);
489 // FIXME: Check the symbol type and flags.
490 if (STE->Type != 0xF) // external, defined in this segment.
492 // Flags in the upper nibble we don't care about.
493 if ((STE->Flags & 0xf) != 0x0)
496 // Remember the symbol.
497 uint32_t SectionID = SectionMap[STE->SectionIndex - 1];
498 SymbolTable[Name] = SymbolLoc(SectionID, STE->Value);
500 DEBUG(dbgs() << "Symbol: '" << Name << "' @ "
501 << (getSectionAddress(SectionID) + STE->Value)
507 // resolveSymbol - Resolve any relocations to the specified symbol if
508 // we know where it lives.
509 void RuntimeDyldMachO::resolveSymbol(StringRef Name) {
510 StringMap<SymbolLoc>::const_iterator Loc = SymbolTable.find(Name);
511 if (Loc == SymbolTable.end())
514 RelocationList &Relocs = UnresolvedRelocations[Name];
515 DEBUG(dbgs() << "Resolving symbol '" << Name << "'\n");
516 for (int i = 0, e = Relocs.size(); i != e; ++i) {
517 // Change the relocation to be section relative rather than symbol
518 // relative and move it to the resolved relocation list.
519 RelocationEntry Entry = Relocs[i];
520 Entry.Addend += Loc->second.second;
521 uint32_t RelocationIndex = Relocations[Loc->second.first].size();
522 Relocations[Loc->second.first].push_back(Entry);
523 Referrers[Entry.SectionID].push_back(Referrer(Loc->second.first, RelocationIndex));
525 // FIXME: Keep a worklist of the relocations we've added so that we can
526 // resolve more selectively later.
530 bool RuntimeDyldMachO::loadObject(MemoryBuffer *InputBuffer) {
531 // If the linker is in an error state, don't do anything.
534 // Load the Mach-O wrapper object.
535 std::string ErrorStr;
536 OwningPtr<MachOObject> Obj(
537 MachOObject::LoadFromBuffer(InputBuffer, &ErrorStr));
539 return Error("unable to load object: '" + ErrorStr + "'");
541 // Get the CPU type information from the header.
542 const macho::Header &Header = Obj->getHeader();
544 // FIXME: Error checking that the loaded object is compatible with
545 // the system we're running on.
546 CPUType = Header.CPUType;
547 CPUSubtype = Header.CPUSubtype;
549 // Validate that the load commands match what we expect.
550 const MachOObject::LoadCommandInfo *SegmentLCI = 0, *SymtabLCI = 0,
552 for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
553 const MachOObject::LoadCommandInfo &LCI = Obj->getLoadCommandInfo(i);
554 switch (LCI.Command.Type) {
555 case macho::LCT_Segment:
556 case macho::LCT_Segment64:
558 return Error("unexpected input object (multiple segments)");
561 case macho::LCT_Symtab:
563 return Error("unexpected input object (multiple symbol tables)");
566 case macho::LCT_Dysymtab:
568 return Error("unexpected input object (multiple symbol tables)");
572 return Error("unexpected input object (unexpected load command");
577 return Error("no symbol table found in object");
579 return Error("no segments found in object");
581 // Read and register the symbol table data.
582 InMemoryStruct<macho::SymtabLoadCommand> SymtabLC;
583 Obj->ReadSymtabLoadCommand(*SymtabLCI, SymtabLC);
585 return Error("unable to load symbol table load command");
586 Obj->RegisterStringTable(*SymtabLC);
588 // Read the dynamic link-edit information, if present (not present in static
591 InMemoryStruct<macho::DysymtabLoadCommand> DysymtabLC;
592 Obj->ReadDysymtabLoadCommand(*DysymtabLCI, DysymtabLC);
594 return Error("unable to load dynamic link-exit load command");
596 // FIXME: We don't support anything interesting yet.
597 // if (DysymtabLC->LocalSymbolsIndex != 0)
598 // return Error("NOT YET IMPLEMENTED: local symbol entries");
599 // if (DysymtabLC->ExternalSymbolsIndex != 0)
600 // return Error("NOT YET IMPLEMENTED: non-external symbol entries");
601 // if (DysymtabLC->UndefinedSymbolsIndex != SymtabLC->NumSymbolTableEntries)
602 // return Error("NOT YET IMPLEMENTED: undefined symbol entries");
605 // Load the segment load command.
606 if (SegmentLCI->Command.Type == macho::LCT_Segment) {
607 if (loadSegment32(Obj.get(), SegmentLCI, SymtabLC))
610 if (loadSegment64(Obj.get(), SegmentLCI, SymtabLC))
614 // Assign the addresses of the sections from the object so that any
615 // relocations to them get set properly.
616 // FIXME: This is done directly from the client at the moment. We should
617 // default the values to the local storage, at least when the target arch
618 // is the same as the host arch.
623 // Assign an address to a symbol name and resolve all the relocations
624 // associated with it.
625 void RuntimeDyldMachO::reassignSectionAddress(unsigned SectionID,
627 // The address to use for relocation resolution is not
628 // the address of the local section buffer. We must be doing
629 // a remote execution environment of some sort. Re-apply any
630 // relocations referencing this section with the given address.
632 // Addr is a uint64_t because we can't assume the pointer width
633 // of the target is the same as that of the host. Just use a generic
634 // "big enough" type.
636 SectionLoadAddress[SectionID] = Addr;
638 RelocationList &Relocs = Relocations[SectionID];
639 for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
640 RelocationEntry &RE = Relocs[i];
641 uint8_t *Target = (uint8_t*)Sections[RE.SectionID].base() + RE.Offset;
642 uint64_t FinalTarget = (uint64_t)SectionLoadAddress[RE.SectionID] + RE.Offset;
643 bool isPCRel = (RE.Data >> 24) & 1;
644 unsigned Type = (RE.Data >> 28) & 0xf;
645 unsigned Size = 1 << ((RE.Data >> 25) & 3);
647 DEBUG(dbgs() << "Resolving relocation at Section #" << RE.SectionID
648 << " + " << RE.Offset << " (" << format("%p", Target) << ")"
649 << " from Section #" << SectionID << " (" << format("%p", Addr) << ")"
650 << "(" << (isPCRel ? "pcrel" : "absolute")
651 << ", type: " << Type << ", Size: " << Size << ", Addend: "
652 << RE.Addend << ").\n");
654 resolveRelocation(Target,
662 ReferrerList &Refers = Referrers[SectionID];
663 for (unsigned i = 0, e = Refers.size(); i != e; ++i) {
664 Referrer &R = Refers[i];
665 RelocationEntry &RE = Relocations[R.SectionID][R.Index];
666 uint8_t *Target = (uint8_t*)Sections[RE.SectionID].base() + RE.Offset;
667 uint64_t FinalTarget = (uint64_t)SectionLoadAddress[RE.SectionID] + RE.Offset;
668 bool isPCRel = (RE.Data >> 24) & 1;
669 unsigned Type = (RE.Data >> 28) & 0xf;
670 unsigned Size = 1 << ((RE.Data >> 25) & 3);
672 DEBUG(dbgs() << "Resolving relocation at Section #" << RE.SectionID
673 << " + " << RE.Offset << " (" << format("%p", Target) << ")"
674 << " from Section #" << SectionID << " (" << format("%p", Addr) << ")"
675 << "(" << (isPCRel ? "pcrel" : "absolute")
676 << ", type: " << Type << ", Size: " << Size << ", Addend: "
677 << RE.Addend << ").\n");
679 resolveRelocation(Target,
689 bool RuntimeDyldMachO::isKnownFormat(const MemoryBuffer *InputBuffer) {
690 StringRef Magic = InputBuffer->getBuffer().slice(0, 4);
691 if (Magic == "\xFE\xED\xFA\xCE") return true;
692 if (Magic == "\xCE\xFA\xED\xFE") return true;
693 if (Magic == "\xFE\xED\xFA\xCF") return true;
694 if (Magic == "\xCF\xFA\xED\xFE") return true;
698 } // end namespace llvm