blob: c5a215c833315039b643bf685ba79af1429518e5 [file] [log] [blame]
Jim Grosbach06594e12012-01-16 23:50:58 +00001//===-- RuntimeDyldMachO.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-=//
Danil Malyshev72510f22011-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
Eli Bendersky058d6472012-01-22 07:05:02 +000014#include "RuntimeDyldMachO.h"
Lang Hamesa5216882014-07-17 18:54:50 +000015#include "Targets/RuntimeDyldMachOAArch64.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000016#include "Targets/RuntimeDyldMachOARM.h"
Lang Hamesa5216882014-07-17 18:54:50 +000017#include "Targets/RuntimeDyldMachOI386.h"
18#include "Targets/RuntimeDyldMachOX86_64.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000019#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/StringRef.h"
Lang Hamesa5216882014-07-17 18:54:50 +000021
Danil Malyshev72510f22011-07-13 07:57:58 +000022using namespace llvm;
23using namespace llvm::object;
24
Chandler Carruthf58e3762014-04-22 03:04:17 +000025#define DEBUG_TYPE "dyld"
26
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000027namespace {
28
David Blaikie5e1ffae2015-08-05 20:20:29 +000029class LoadedMachOObjectInfo final
David Blaikie87131572017-07-05 15:23:56 +000030 : public LoadedObjectInfoHelper<LoadedMachOObjectInfo,
31 RuntimeDyld::LoadedObjectInfo> {
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000032public:
Lang Hames2e88f4f2015-07-28 17:52:11 +000033 LoadedMachOObjectInfo(RuntimeDyldImpl &RTDyld,
34 ObjSectionToIDMap ObjSecToIDMap)
35 : LoadedObjectInfoHelper(RTDyld, std::move(ObjSecToIDMap)) {}
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000036
37 OwningBinary<ObjectFile>
38 getObjectForDebug(const ObjectFile &Obj) const override {
39 return OwningBinary<ObjectFile>();
40 }
41};
42
Alexander Kornienkof00654e2015-06-23 09:49:53 +000043}
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000044
Danil Malyshev72510f22011-07-13 07:57:58 +000045namespace llvm {
46
Lang Hames25d93092014-08-08 23:12:22 +000047int64_t RuntimeDyldMachO::memcpyAddend(const RelocationEntry &RE) const {
Lang Hames25d93092014-08-08 23:12:22 +000048 unsigned NumBytes = 1 << RE.Size;
Sanjoy Das277776a2015-11-23 21:47:41 +000049 uint8_t *Src = Sections[RE.SectionID].getAddress() + RE.Offset;
Lang Hamesdc77feb2014-08-27 17:41:06 +000050
Lang Hamese1287c02014-08-29 23:17:47 +000051 return static_cast<int64_t>(readBytesUnaligned(Src, NumBytes));
Lang Hamesa5216882014-07-17 18:54:50 +000052}
53
Lang Hames89595312016-04-27 20:24:48 +000054Expected<relocation_iterator>
55RuntimeDyldMachO::processScatteredVANILLA(
Lang Hamesa8183e52015-07-24 17:40:04 +000056 unsigned SectionID, relocation_iterator RelI,
57 const ObjectFile &BaseObjT,
Lang Hames14a22a42017-08-09 20:19:27 +000058 RuntimeDyldMachO::ObjSectionToIDMap &ObjSectionToID,
59 bool TargetIsLocalThumbFunc) {
Lang Hamesa8183e52015-07-24 17:40:04 +000060 const MachOObjectFile &Obj =
61 static_cast<const MachOObjectFile&>(BaseObjT);
62 MachO::any_relocation_info RE =
63 Obj.getRelocation(RelI->getRawDataRefImpl());
64
65 SectionEntry &Section = Sections[SectionID];
66 uint32_t RelocType = Obj.getAnyRelocationType(RE);
67 bool IsPCRel = Obj.getAnyRelocationPCRel(RE);
68 unsigned Size = Obj.getAnyRelocationLength(RE);
69 uint64_t Offset = RelI->getOffset();
Sanjoy Das277776a2015-11-23 21:47:41 +000070 uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);
Lang Hamesa8183e52015-07-24 17:40:04 +000071 unsigned NumBytes = 1 << Size;
72 int64_t Addend = readBytesUnaligned(LocalAddress, NumBytes);
73
74 unsigned SymbolBaseAddr = Obj.getScatteredRelocationValue(RE);
75 section_iterator TargetSI = getSectionByAddress(Obj, SymbolBaseAddr);
76 assert(TargetSI != Obj.section_end() && "Can't find section for symbol");
77 uint64_t SectionBaseAddr = TargetSI->getAddress();
78 SectionRef TargetSection = *TargetSI;
79 bool IsCode = TargetSection.isText();
Lang Hames89595312016-04-27 20:24:48 +000080 uint32_t TargetSectionID = ~0U;
81 if (auto TargetSectionIDOrErr =
82 findOrEmitSection(Obj, TargetSection, IsCode, ObjSectionToID))
83 TargetSectionID = *TargetSectionIDOrErr;
84 else
85 return TargetSectionIDOrErr.takeError();
Lang Hamesa8183e52015-07-24 17:40:04 +000086
87 Addend -= SectionBaseAddr;
88 RelocationEntry R(SectionID, Offset, RelocType, Addend, IsPCRel, Size);
Lang Hames14a22a42017-08-09 20:19:27 +000089 R.IsTargetThumbFunc = TargetIsLocalThumbFunc;
Lang Hamesa8183e52015-07-24 17:40:04 +000090
91 addRelocationForSection(R, TargetSectionID);
92
93 return ++RelI;
94}
95
96
Lang Hames89595312016-04-27 20:24:48 +000097Expected<RelocationValueRef>
98RuntimeDyldMachO::getRelocationValueRef(
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000099 const ObjectFile &BaseTObj, const relocation_iterator &RI,
Lang Hamesa5cd9502014-11-27 05:40:13 +0000100 const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID) {
Lang Hamesa5216882014-07-17 18:54:50 +0000101
102 const MachOObjectFile &Obj =
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000103 static_cast<const MachOObjectFile &>(BaseTObj);
Lang Hamesa5216882014-07-17 18:54:50 +0000104 MachO::any_relocation_info RelInfo =
105 Obj.getRelocation(RI->getRawDataRefImpl());
106 RelocationValueRef Value;
107
108 bool IsExternal = Obj.getPlainRelocationExternal(RelInfo);
109 if (IsExternal) {
110 symbol_iterator Symbol = RI->getSymbol();
Lang Hames89595312016-04-27 20:24:48 +0000111 StringRef TargetName;
112 if (auto TargetNameOrErr = Symbol->getName())
113 TargetName = *TargetNameOrErr;
114 else
115 return TargetNameOrErr.takeError();
Lang Hames6bfd3982015-01-16 23:13:56 +0000116 RTDyldSymbolTable::const_iterator SI =
Lang Hamesa5cd9502014-11-27 05:40:13 +0000117 GlobalSymbolTable.find(TargetName.data());
118 if (SI != GlobalSymbolTable.end()) {
Lang Hames6bfd3982015-01-16 23:13:56 +0000119 const auto &SymInfo = SI->second;
120 Value.SectionID = SymInfo.getSectionID();
121 Value.Offset = SymInfo.getOffset() + RE.Addend;
Lang Hamesa5216882014-07-17 18:54:50 +0000122 } else {
Lang Hamesa5cd9502014-11-27 05:40:13 +0000123 Value.SymbolName = TargetName.data();
124 Value.Offset = RE.Addend;
Lang Hamesa5216882014-07-17 18:54:50 +0000125 }
126 } else {
Keno Fischerc780e8e2015-05-21 21:24:32 +0000127 SectionRef Sec = Obj.getAnyRelocationSection(RelInfo);
Rafael Espindola80291272014-10-08 15:28:58 +0000128 bool IsCode = Sec.isText();
Lang Hames89595312016-04-27 20:24:48 +0000129 if (auto SectionIDOrErr = findOrEmitSection(Obj, Sec, IsCode,
130 ObjSectionToID))
131 Value.SectionID = *SectionIDOrErr;
132 else
133 return SectionIDOrErr.takeError();
Rafael Espindola80291272014-10-08 15:28:58 +0000134 uint64_t Addr = Sec.getAddress();
Lang Hamesca279c22014-09-07 04:03:32 +0000135 Value.Offset = RE.Addend - Addr;
Lang Hamesa5216882014-07-17 18:54:50 +0000136 }
137
138 return Value;
139}
140
141void RuntimeDyldMachO::makeValueAddendPCRel(RelocationValueRef &Value,
Lang Hames13163652014-07-30 03:35:05 +0000142 const relocation_iterator &RI,
143 unsigned OffsetToNextPC) {
Rafael Espindola76ad2322015-07-06 14:55:37 +0000144 auto &O = *cast<MachOObjectFile>(RI->getObject());
145 section_iterator SecI = O.getRelocationRelocatedSection(RI);
146 Value.Offset += RI->getOffset() + OffsetToNextPC + SecI->getAddress();
Lang Hamesa5216882014-07-17 18:54:50 +0000147}
148
149void RuntimeDyldMachO::dumpRelocationToResolve(const RelocationEntry &RE,
150 uint64_t Value) const {
151 const SectionEntry &Section = Sections[RE.SectionID];
Sanjoy Das277776a2015-11-23 21:47:41 +0000152 uint8_t *LocalAddress = Section.getAddress() + RE.Offset;
153 uint64_t FinalAddress = Section.getLoadAddress() + RE.Offset;
Lang Hamesa5216882014-07-17 18:54:50 +0000154
155 dbgs() << "resolveRelocation Section: " << RE.SectionID
156 << " LocalAddress: " << format("%p", LocalAddress)
Lang Hamesc5cafbb2014-08-28 04:25:17 +0000157 << " FinalAddress: " << format("0x%016" PRIx64, FinalAddress)
158 << " Value: " << format("0x%016" PRIx64, Value) << " Addend: " << RE.Addend
Lang Hamesa5216882014-07-17 18:54:50 +0000159 << " isPCRel: " << RE.IsPCRel << " MachoType: " << RE.RelType
160 << " Size: " << (1 << RE.Size) << "\n";
161}
162
Lang Hames6f1048f2014-09-11 19:21:14 +0000163section_iterator
164RuntimeDyldMachO::getSectionByAddress(const MachOObjectFile &Obj,
165 uint64_t Addr) {
166 section_iterator SI = Obj.section_begin();
167 section_iterator SE = Obj.section_end();
168
169 for (; SI != SE; ++SI) {
Rafael Espindola80291272014-10-08 15:28:58 +0000170 uint64_t SAddr = SI->getAddress();
171 uint64_t SSize = SI->getSize();
Lang Hames6f1048f2014-09-11 19:21:14 +0000172 if ((Addr >= SAddr) && (Addr < SAddr + SSize))
173 return SI;
174 }
175
176 return SE;
177}
178
179
180// Populate __pointers section.
Lang Hames89595312016-04-27 20:24:48 +0000181Error RuntimeDyldMachO::populateIndirectSymbolPointersSection(
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000182 const MachOObjectFile &Obj,
Lang Hames6f1048f2014-09-11 19:21:14 +0000183 const SectionRef &PTSection,
184 unsigned PTSectionID) {
185 assert(!Obj.is64Bit() &&
186 "Pointer table section not supported in 64-bit MachO.");
187
188 MachO::dysymtab_command DySymTabCmd = Obj.getDysymtabLoadCommand();
189 MachO::section Sec32 = Obj.getSection(PTSection.getRawDataRefImpl());
190 uint32_t PTSectionSize = Sec32.size;
191 unsigned FirstIndirectSymbol = Sec32.reserved1;
192 const unsigned PTEntrySize = 4;
193 unsigned NumPTEntries = PTSectionSize / PTEntrySize;
194 unsigned PTEntryOffset = 0;
195
196 assert((PTSectionSize % PTEntrySize) == 0 &&
197 "Pointers section does not contain a whole number of stubs?");
198
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000199 LLVM_DEBUG(dbgs() << "Populating pointer table section "
200 << Sections[PTSectionID].getName() << ", Section ID "
201 << PTSectionID << ", " << NumPTEntries << " entries, "
202 << PTEntrySize << " bytes each:\n");
Lang Hames6f1048f2014-09-11 19:21:14 +0000203
204 for (unsigned i = 0; i < NumPTEntries; ++i) {
205 unsigned SymbolIndex =
206 Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
207 symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
Lang Hames89595312016-04-27 20:24:48 +0000208 StringRef IndirectSymbolName;
209 if (auto IndirectSymbolNameOrErr = SI->getName())
210 IndirectSymbolName = *IndirectSymbolNameOrErr;
211 else
212 return IndirectSymbolNameOrErr.takeError();
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000213 LLVM_DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
214 << ", PT offset: " << PTEntryOffset << "\n");
Lang Hames6f1048f2014-09-11 19:21:14 +0000215 RelocationEntry RE(PTSectionID, PTEntryOffset,
216 MachO::GENERIC_RELOC_VANILLA, 0, false, 2);
217 addRelocationForSymbol(RE, IndirectSymbolName);
218 PTEntryOffset += PTEntrySize;
219 }
Lang Hames89595312016-04-27 20:24:48 +0000220 return Error::success();
Lang Hames6f1048f2014-09-11 19:21:14 +0000221}
222
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000223bool RuntimeDyldMachO::isCompatibleFile(const object::ObjectFile &Obj) const {
224 return Obj.isMachO();
Lang Hamesa5216882014-07-17 18:54:50 +0000225}
226
Lang Hameseb195f02014-09-04 04:53:03 +0000227template <typename Impl>
Lang Hames89595312016-04-27 20:24:48 +0000228Error
229RuntimeDyldMachOCRTPBase<Impl>::finalizeLoad(const ObjectFile &Obj,
230 ObjSectionToIDMap &SectionMap) {
Lang Hameseb195f02014-09-04 04:53:03 +0000231 unsigned EHFrameSID = RTDYLD_INVALID_SECTION_ID;
232 unsigned TextSID = RTDYLD_INVALID_SECTION_ID;
233 unsigned ExceptTabSID = RTDYLD_INVALID_SECTION_ID;
Lang Hameseb195f02014-09-04 04:53:03 +0000234
Lang Hames38aac642015-04-15 03:39:22 +0000235 for (const auto &Section : Obj.sections()) {
Lang Hameseb195f02014-09-04 04:53:03 +0000236 StringRef Name;
237 Section.getName(Name);
Lang Hames38aac642015-04-15 03:39:22 +0000238
239 // Force emission of the __text, __eh_frame, and __gcc_except_tab sections
240 // if they're present. Otherwise call down to the impl to handle other
241 // sections that have already been emitted.
Lang Hames89595312016-04-27 20:24:48 +0000242 if (Name == "__text") {
243 if (auto TextSIDOrErr = findOrEmitSection(Obj, Section, true, SectionMap))
244 TextSID = *TextSIDOrErr;
245 else
246 return TextSIDOrErr.takeError();
247 } else if (Name == "__eh_frame") {
248 if (auto EHFrameSIDOrErr = findOrEmitSection(Obj, Section, false,
249 SectionMap))
250 EHFrameSID = *EHFrameSIDOrErr;
251 else
252 return EHFrameSIDOrErr.takeError();
253 } else if (Name == "__gcc_except_tab") {
254 if (auto ExceptTabSIDOrErr = findOrEmitSection(Obj, Section, true,
255 SectionMap))
256 ExceptTabSID = *ExceptTabSIDOrErr;
257 else
258 return ExceptTabSIDOrErr.takeError();
259 } else {
Lang Hames38aac642015-04-15 03:39:22 +0000260 auto I = SectionMap.find(Section);
261 if (I != SectionMap.end())
Lang Hames89595312016-04-27 20:24:48 +0000262 if (auto Err = impl().finalizeSection(Obj, I->second, Section))
263 return Err;
Lang Hames38aac642015-04-15 03:39:22 +0000264 }
Lang Hameseb195f02014-09-04 04:53:03 +0000265 }
266 UnregisteredEHFrameSections.push_back(
267 EHFrameRelatedSections(EHFrameSID, TextSID, ExceptTabSID));
Lang Hames89595312016-04-27 20:24:48 +0000268
269 return Error::success();
Lang Hameseb195f02014-09-04 04:53:03 +0000270}
271
272template <typename Impl>
Sanjoy Das277776a2015-11-23 21:47:41 +0000273unsigned char *RuntimeDyldMachOCRTPBase<Impl>::processFDE(uint8_t *P,
Lang Hameseb195f02014-09-04 04:53:03 +0000274 int64_t DeltaForText,
275 int64_t DeltaForEH) {
276 typedef typename Impl::TargetPtrT TargetPtrT;
277
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000278 LLVM_DEBUG(dbgs() << "Processing FDE: Delta for text: " << DeltaForText
279 << ", Delta for EH: " << DeltaForEH << "\n");
Daniel Sanders523b1712014-11-01 15:52:31 +0000280 uint32_t Length = readBytesUnaligned(P, 4);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000281 P += 4;
Sanjoy Das277776a2015-11-23 21:47:41 +0000282 uint8_t *Ret = P + Length;
Daniel Sanders523b1712014-11-01 15:52:31 +0000283 uint32_t Offset = readBytesUnaligned(P, 4);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000284 if (Offset == 0) // is a CIE
285 return Ret;
286
287 P += 4;
Daniel Sanders523b1712014-11-01 15:52:31 +0000288 TargetPtrT FDELocation = readBytesUnaligned(P, sizeof(TargetPtrT));
Lang Hameseb195f02014-09-04 04:53:03 +0000289 TargetPtrT NewLocation = FDELocation - DeltaForText;
Daniel Sanders523b1712014-11-01 15:52:31 +0000290 writeBytesUnaligned(NewLocation, P, sizeof(TargetPtrT));
291
Lang Hameseb195f02014-09-04 04:53:03 +0000292 P += sizeof(TargetPtrT);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000293
294 // Skip the FDE address range
Lang Hameseb195f02014-09-04 04:53:03 +0000295 P += sizeof(TargetPtrT);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000296
297 uint8_t Augmentationsize = *P;
298 P += 1;
299 if (Augmentationsize != 0) {
Daniel Sanders523b1712014-11-01 15:52:31 +0000300 TargetPtrT LSDA = readBytesUnaligned(P, sizeof(TargetPtrT));
Lang Hameseb195f02014-09-04 04:53:03 +0000301 TargetPtrT NewLSDA = LSDA - DeltaForEH;
Daniel Sanders523b1712014-11-01 15:52:31 +0000302 writeBytesUnaligned(NewLSDA, P, sizeof(TargetPtrT));
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000303 }
304
305 return Ret;
306}
307
Lang Hameseb195f02014-09-04 04:53:03 +0000308static int64_t computeDelta(SectionEntry *A, SectionEntry *B) {
Sanjoy Das277776a2015-11-23 21:47:41 +0000309 int64_t ObjDistance = static_cast<int64_t>(A->getObjAddress()) -
310 static_cast<int64_t>(B->getObjAddress());
311 int64_t MemDistance = A->getLoadAddress() - B->getLoadAddress();
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000312 return ObjDistance - MemDistance;
313}
314
Lang Hameseb195f02014-09-04 04:53:03 +0000315template <typename Impl>
316void RuntimeDyldMachOCRTPBase<Impl>::registerEHFrames() {
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000317
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000318 for (int i = 0, e = UnregisteredEHFrameSections.size(); i != e; ++i) {
319 EHFrameRelatedSections &SectionInfo = UnregisteredEHFrameSections[i];
320 if (SectionInfo.EHFrameSID == RTDYLD_INVALID_SECTION_ID ||
321 SectionInfo.TextSID == RTDYLD_INVALID_SECTION_ID)
322 continue;
323 SectionEntry *Text = &Sections[SectionInfo.TextSID];
324 SectionEntry *EHFrame = &Sections[SectionInfo.EHFrameSID];
Craig Topper353eda42014-04-24 06:44:33 +0000325 SectionEntry *ExceptTab = nullptr;
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000326 if (SectionInfo.ExceptTabSID != RTDYLD_INVALID_SECTION_ID)
327 ExceptTab = &Sections[SectionInfo.ExceptTabSID];
328
Lang Hameseb195f02014-09-04 04:53:03 +0000329 int64_t DeltaForText = computeDelta(Text, EHFrame);
330 int64_t DeltaForEH = 0;
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000331 if (ExceptTab)
332 DeltaForEH = computeDelta(ExceptTab, EHFrame);
333
Sanjoy Das277776a2015-11-23 21:47:41 +0000334 uint8_t *P = EHFrame->getAddress();
335 uint8_t *End = P + EHFrame->getSize();
Lang Hames2d8a2aa2016-01-28 22:35:48 +0000336 while (P != End) {
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000337 P = processFDE(P, DeltaForText, DeltaForEH);
Lang Hames2d8a2aa2016-01-28 22:35:48 +0000338 }
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000339
Sanjoy Das277776a2015-11-23 21:47:41 +0000340 MemMgr.registerEHFrames(EHFrame->getAddress(), EHFrame->getLoadAddress(),
341 EHFrame->getSize());
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000342 }
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000343 UnregisteredEHFrameSections.clear();
344}
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000345
Lang Hamesa5216882014-07-17 18:54:50 +0000346std::unique_ptr<RuntimeDyldMachO>
Lang Hames633fe142015-03-30 03:37:06 +0000347RuntimeDyldMachO::create(Triple::ArchType Arch,
348 RuntimeDyld::MemoryManager &MemMgr,
Lang Hamesad4a9112016-08-01 20:49:11 +0000349 JITSymbolResolver &Resolver) {
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000350 switch (Arch) {
Juergen Ributzka7608dc02014-03-21 20:28:42 +0000351 default:
Lang Hamesa5216882014-07-17 18:54:50 +0000352 llvm_unreachable("Unsupported target for RuntimeDyldMachO.");
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000353 break;
Lang Hames633fe142015-03-30 03:37:06 +0000354 case Triple::arm:
355 return make_unique<RuntimeDyldMachOARM>(MemMgr, Resolver);
356 case Triple::aarch64:
357 return make_unique<RuntimeDyldMachOAArch64>(MemMgr, Resolver);
358 case Triple::x86:
359 return make_unique<RuntimeDyldMachOI386>(MemMgr, Resolver);
360 case Triple::x86_64:
361 return make_unique<RuntimeDyldMachOX86_64>(MemMgr, Resolver);
Danil Malyshev72510f22011-07-13 07:57:58 +0000362 }
Danil Malyshev72510f22011-07-13 07:57:58 +0000363}
364
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000365std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
366RuntimeDyldMachO::loadObject(const object::ObjectFile &O) {
Lang Hames89595312016-04-27 20:24:48 +0000367 if (auto ObjSectionToIDOrErr = loadObjectImpl(O))
368 return llvm::make_unique<LoadedMachOObjectInfo>(*this,
369 *ObjSectionToIDOrErr);
370 else {
371 HasError = true;
372 raw_string_ostream ErrStream(ErrorStr);
373 logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
374 return nullptr;
375 }
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000376}
377
Danil Malyshev72510f22011-07-13 07:57:58 +0000378} // end namespace llvm