blob: fd109aea91d49aa0e8f52f0e61342b71a4ce5601 [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
NAKAMURA Takumi73dc2e42015-05-22 10:11:07 +000030 : public RuntimeDyld::LoadedObjectInfoHelper<LoadedMachOObjectInfo> {
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000031public:
Lang Hames2e88f4f2015-07-28 17:52:11 +000032 LoadedMachOObjectInfo(RuntimeDyldImpl &RTDyld,
33 ObjSectionToIDMap ObjSecToIDMap)
34 : LoadedObjectInfoHelper(RTDyld, std::move(ObjSecToIDMap)) {}
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000035
36 OwningBinary<ObjectFile>
37 getObjectForDebug(const ObjectFile &Obj) const override {
38 return OwningBinary<ObjectFile>();
39 }
40};
41
Alexander Kornienkof00654e2015-06-23 09:49:53 +000042}
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000043
Danil Malyshev72510f22011-07-13 07:57:58 +000044namespace llvm {
45
Lang Hames25d93092014-08-08 23:12:22 +000046int64_t RuntimeDyldMachO::memcpyAddend(const RelocationEntry &RE) const {
Lang Hames25d93092014-08-08 23:12:22 +000047 unsigned NumBytes = 1 << RE.Size;
Sanjoy Das277776a2015-11-23 21:47:41 +000048 uint8_t *Src = Sections[RE.SectionID].getAddress() + RE.Offset;
Lang Hamesdc77feb2014-08-27 17:41:06 +000049
Lang Hamese1287c02014-08-29 23:17:47 +000050 return static_cast<int64_t>(readBytesUnaligned(Src, NumBytes));
Lang Hamesa5216882014-07-17 18:54:50 +000051}
52
Lang Hames89595312016-04-27 20:24:48 +000053Expected<relocation_iterator>
54RuntimeDyldMachO::processScatteredVANILLA(
Lang Hamesa8183e52015-07-24 17:40:04 +000055 unsigned SectionID, relocation_iterator RelI,
56 const ObjectFile &BaseObjT,
57 RuntimeDyldMachO::ObjSectionToIDMap &ObjSectionToID) {
58 const MachOObjectFile &Obj =
59 static_cast<const MachOObjectFile&>(BaseObjT);
60 MachO::any_relocation_info RE =
61 Obj.getRelocation(RelI->getRawDataRefImpl());
62
63 SectionEntry &Section = Sections[SectionID];
64 uint32_t RelocType = Obj.getAnyRelocationType(RE);
65 bool IsPCRel = Obj.getAnyRelocationPCRel(RE);
66 unsigned Size = Obj.getAnyRelocationLength(RE);
67 uint64_t Offset = RelI->getOffset();
Sanjoy Das277776a2015-11-23 21:47:41 +000068 uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);
Lang Hamesa8183e52015-07-24 17:40:04 +000069 unsigned NumBytes = 1 << Size;
70 int64_t Addend = readBytesUnaligned(LocalAddress, NumBytes);
71
72 unsigned SymbolBaseAddr = Obj.getScatteredRelocationValue(RE);
73 section_iterator TargetSI = getSectionByAddress(Obj, SymbolBaseAddr);
74 assert(TargetSI != Obj.section_end() && "Can't find section for symbol");
75 uint64_t SectionBaseAddr = TargetSI->getAddress();
76 SectionRef TargetSection = *TargetSI;
77 bool IsCode = TargetSection.isText();
Lang Hames89595312016-04-27 20:24:48 +000078 uint32_t TargetSectionID = ~0U;
79 if (auto TargetSectionIDOrErr =
80 findOrEmitSection(Obj, TargetSection, IsCode, ObjSectionToID))
81 TargetSectionID = *TargetSectionIDOrErr;
82 else
83 return TargetSectionIDOrErr.takeError();
Lang Hamesa8183e52015-07-24 17:40:04 +000084
85 Addend -= SectionBaseAddr;
86 RelocationEntry R(SectionID, Offset, RelocType, Addend, IsPCRel, Size);
87
88 addRelocationForSection(R, TargetSectionID);
89
90 return ++RelI;
91}
92
93
Lang Hames89595312016-04-27 20:24:48 +000094Expected<RelocationValueRef>
95RuntimeDyldMachO::getRelocationValueRef(
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000096 const ObjectFile &BaseTObj, const relocation_iterator &RI,
Lang Hamesa5cd9502014-11-27 05:40:13 +000097 const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID) {
Lang Hamesa5216882014-07-17 18:54:50 +000098
99 const MachOObjectFile &Obj =
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000100 static_cast<const MachOObjectFile &>(BaseTObj);
Lang Hamesa5216882014-07-17 18:54:50 +0000101 MachO::any_relocation_info RelInfo =
102 Obj.getRelocation(RI->getRawDataRefImpl());
103 RelocationValueRef Value;
104
105 bool IsExternal = Obj.getPlainRelocationExternal(RelInfo);
106 if (IsExternal) {
107 symbol_iterator Symbol = RI->getSymbol();
Lang Hames89595312016-04-27 20:24:48 +0000108 StringRef TargetName;
109 if (auto TargetNameOrErr = Symbol->getName())
110 TargetName = *TargetNameOrErr;
111 else
112 return TargetNameOrErr.takeError();
Lang Hames6bfd3982015-01-16 23:13:56 +0000113 RTDyldSymbolTable::const_iterator SI =
Lang Hamesa5cd9502014-11-27 05:40:13 +0000114 GlobalSymbolTable.find(TargetName.data());
115 if (SI != GlobalSymbolTable.end()) {
Lang Hames6bfd3982015-01-16 23:13:56 +0000116 const auto &SymInfo = SI->second;
117 Value.SectionID = SymInfo.getSectionID();
118 Value.Offset = SymInfo.getOffset() + RE.Addend;
Lang Hamesa5216882014-07-17 18:54:50 +0000119 } else {
Lang Hamesa5cd9502014-11-27 05:40:13 +0000120 Value.SymbolName = TargetName.data();
121 Value.Offset = RE.Addend;
Lang Hamesa5216882014-07-17 18:54:50 +0000122 }
123 } else {
Keno Fischerc780e8e2015-05-21 21:24:32 +0000124 SectionRef Sec = Obj.getAnyRelocationSection(RelInfo);
Rafael Espindola80291272014-10-08 15:28:58 +0000125 bool IsCode = Sec.isText();
Lang Hames89595312016-04-27 20:24:48 +0000126 if (auto SectionIDOrErr = findOrEmitSection(Obj, Sec, IsCode,
127 ObjSectionToID))
128 Value.SectionID = *SectionIDOrErr;
129 else
130 return SectionIDOrErr.takeError();
Rafael Espindola80291272014-10-08 15:28:58 +0000131 uint64_t Addr = Sec.getAddress();
Lang Hamesca279c22014-09-07 04:03:32 +0000132 Value.Offset = RE.Addend - Addr;
Lang Hamesa5216882014-07-17 18:54:50 +0000133 }
134
135 return Value;
136}
137
138void RuntimeDyldMachO::makeValueAddendPCRel(RelocationValueRef &Value,
Lang Hames13163652014-07-30 03:35:05 +0000139 const relocation_iterator &RI,
140 unsigned OffsetToNextPC) {
Rafael Espindola76ad2322015-07-06 14:55:37 +0000141 auto &O = *cast<MachOObjectFile>(RI->getObject());
142 section_iterator SecI = O.getRelocationRelocatedSection(RI);
143 Value.Offset += RI->getOffset() + OffsetToNextPC + SecI->getAddress();
Lang Hamesa5216882014-07-17 18:54:50 +0000144}
145
146void RuntimeDyldMachO::dumpRelocationToResolve(const RelocationEntry &RE,
147 uint64_t Value) const {
148 const SectionEntry &Section = Sections[RE.SectionID];
Sanjoy Das277776a2015-11-23 21:47:41 +0000149 uint8_t *LocalAddress = Section.getAddress() + RE.Offset;
150 uint64_t FinalAddress = Section.getLoadAddress() + RE.Offset;
Lang Hamesa5216882014-07-17 18:54:50 +0000151
152 dbgs() << "resolveRelocation Section: " << RE.SectionID
153 << " LocalAddress: " << format("%p", LocalAddress)
Lang Hamesc5cafbb2014-08-28 04:25:17 +0000154 << " FinalAddress: " << format("0x%016" PRIx64, FinalAddress)
155 << " Value: " << format("0x%016" PRIx64, Value) << " Addend: " << RE.Addend
Lang Hamesa5216882014-07-17 18:54:50 +0000156 << " isPCRel: " << RE.IsPCRel << " MachoType: " << RE.RelType
157 << " Size: " << (1 << RE.Size) << "\n";
158}
159
Lang Hames6f1048f2014-09-11 19:21:14 +0000160section_iterator
161RuntimeDyldMachO::getSectionByAddress(const MachOObjectFile &Obj,
162 uint64_t Addr) {
163 section_iterator SI = Obj.section_begin();
164 section_iterator SE = Obj.section_end();
165
166 for (; SI != SE; ++SI) {
Rafael Espindola80291272014-10-08 15:28:58 +0000167 uint64_t SAddr = SI->getAddress();
168 uint64_t SSize = SI->getSize();
Lang Hames6f1048f2014-09-11 19:21:14 +0000169 if ((Addr >= SAddr) && (Addr < SAddr + SSize))
170 return SI;
171 }
172
173 return SE;
174}
175
176
177// Populate __pointers section.
Lang Hames89595312016-04-27 20:24:48 +0000178Error RuntimeDyldMachO::populateIndirectSymbolPointersSection(
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000179 const MachOObjectFile &Obj,
Lang Hames6f1048f2014-09-11 19:21:14 +0000180 const SectionRef &PTSection,
181 unsigned PTSectionID) {
182 assert(!Obj.is64Bit() &&
183 "Pointer table section not supported in 64-bit MachO.");
184
185 MachO::dysymtab_command DySymTabCmd = Obj.getDysymtabLoadCommand();
186 MachO::section Sec32 = Obj.getSection(PTSection.getRawDataRefImpl());
187 uint32_t PTSectionSize = Sec32.size;
188 unsigned FirstIndirectSymbol = Sec32.reserved1;
189 const unsigned PTEntrySize = 4;
190 unsigned NumPTEntries = PTSectionSize / PTEntrySize;
191 unsigned PTEntryOffset = 0;
192
193 assert((PTSectionSize % PTEntrySize) == 0 &&
194 "Pointers section does not contain a whole number of stubs?");
195
196 DEBUG(dbgs() << "Populating pointer table section "
Sanjoy Das277776a2015-11-23 21:47:41 +0000197 << Sections[PTSectionID].getName() << ", Section ID "
198 << PTSectionID << ", " << NumPTEntries << " entries, "
199 << PTEntrySize << " bytes each:\n");
Lang Hames6f1048f2014-09-11 19:21:14 +0000200
201 for (unsigned i = 0; i < NumPTEntries; ++i) {
202 unsigned SymbolIndex =
203 Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
204 symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
Lang Hames89595312016-04-27 20:24:48 +0000205 StringRef IndirectSymbolName;
206 if (auto IndirectSymbolNameOrErr = SI->getName())
207 IndirectSymbolName = *IndirectSymbolNameOrErr;
208 else
209 return IndirectSymbolNameOrErr.takeError();
Lang Hames6f1048f2014-09-11 19:21:14 +0000210 DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
211 << ", PT offset: " << PTEntryOffset << "\n");
212 RelocationEntry RE(PTSectionID, PTEntryOffset,
213 MachO::GENERIC_RELOC_VANILLA, 0, false, 2);
214 addRelocationForSymbol(RE, IndirectSymbolName);
215 PTEntryOffset += PTEntrySize;
216 }
Lang Hames89595312016-04-27 20:24:48 +0000217 return Error::success();
Lang Hames6f1048f2014-09-11 19:21:14 +0000218}
219
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000220bool RuntimeDyldMachO::isCompatibleFile(const object::ObjectFile &Obj) const {
221 return Obj.isMachO();
Lang Hamesa5216882014-07-17 18:54:50 +0000222}
223
Lang Hameseb195f02014-09-04 04:53:03 +0000224template <typename Impl>
Lang Hames89595312016-04-27 20:24:48 +0000225Error
226RuntimeDyldMachOCRTPBase<Impl>::finalizeLoad(const ObjectFile &Obj,
227 ObjSectionToIDMap &SectionMap) {
Lang Hameseb195f02014-09-04 04:53:03 +0000228 unsigned EHFrameSID = RTDYLD_INVALID_SECTION_ID;
229 unsigned TextSID = RTDYLD_INVALID_SECTION_ID;
230 unsigned ExceptTabSID = RTDYLD_INVALID_SECTION_ID;
Lang Hameseb195f02014-09-04 04:53:03 +0000231
Lang Hames38aac642015-04-15 03:39:22 +0000232 for (const auto &Section : Obj.sections()) {
Lang Hameseb195f02014-09-04 04:53:03 +0000233 StringRef Name;
234 Section.getName(Name);
Lang Hames38aac642015-04-15 03:39:22 +0000235
236 // Force emission of the __text, __eh_frame, and __gcc_except_tab sections
237 // if they're present. Otherwise call down to the impl to handle other
238 // sections that have already been emitted.
Lang Hames89595312016-04-27 20:24:48 +0000239 if (Name == "__text") {
240 if (auto TextSIDOrErr = findOrEmitSection(Obj, Section, true, SectionMap))
241 TextSID = *TextSIDOrErr;
242 else
243 return TextSIDOrErr.takeError();
244 } else if (Name == "__eh_frame") {
245 if (auto EHFrameSIDOrErr = findOrEmitSection(Obj, Section, false,
246 SectionMap))
247 EHFrameSID = *EHFrameSIDOrErr;
248 else
249 return EHFrameSIDOrErr.takeError();
250 } else if (Name == "__gcc_except_tab") {
251 if (auto ExceptTabSIDOrErr = findOrEmitSection(Obj, Section, true,
252 SectionMap))
253 ExceptTabSID = *ExceptTabSIDOrErr;
254 else
255 return ExceptTabSIDOrErr.takeError();
256 } else {
Lang Hames38aac642015-04-15 03:39:22 +0000257 auto I = SectionMap.find(Section);
258 if (I != SectionMap.end())
Lang Hames89595312016-04-27 20:24:48 +0000259 if (auto Err = impl().finalizeSection(Obj, I->second, Section))
260 return Err;
Lang Hames38aac642015-04-15 03:39:22 +0000261 }
Lang Hameseb195f02014-09-04 04:53:03 +0000262 }
263 UnregisteredEHFrameSections.push_back(
264 EHFrameRelatedSections(EHFrameSID, TextSID, ExceptTabSID));
Lang Hames89595312016-04-27 20:24:48 +0000265
266 return Error::success();
Lang Hameseb195f02014-09-04 04:53:03 +0000267}
268
269template <typename Impl>
Sanjoy Das277776a2015-11-23 21:47:41 +0000270unsigned char *RuntimeDyldMachOCRTPBase<Impl>::processFDE(uint8_t *P,
Lang Hameseb195f02014-09-04 04:53:03 +0000271 int64_t DeltaForText,
272 int64_t DeltaForEH) {
273 typedef typename Impl::TargetPtrT TargetPtrT;
274
Lang Hames36072da2014-05-12 21:39:59 +0000275 DEBUG(dbgs() << "Processing FDE: Delta for text: " << DeltaForText
276 << ", Delta for EH: " << DeltaForEH << "\n");
Daniel Sanders523b1712014-11-01 15:52:31 +0000277 uint32_t Length = readBytesUnaligned(P, 4);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000278 P += 4;
Sanjoy Das277776a2015-11-23 21:47:41 +0000279 uint8_t *Ret = P + Length;
Daniel Sanders523b1712014-11-01 15:52:31 +0000280 uint32_t Offset = readBytesUnaligned(P, 4);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000281 if (Offset == 0) // is a CIE
282 return Ret;
283
284 P += 4;
Daniel Sanders523b1712014-11-01 15:52:31 +0000285 TargetPtrT FDELocation = readBytesUnaligned(P, sizeof(TargetPtrT));
Lang Hameseb195f02014-09-04 04:53:03 +0000286 TargetPtrT NewLocation = FDELocation - DeltaForText;
Daniel Sanders523b1712014-11-01 15:52:31 +0000287 writeBytesUnaligned(NewLocation, P, sizeof(TargetPtrT));
288
Lang Hameseb195f02014-09-04 04:53:03 +0000289 P += sizeof(TargetPtrT);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000290
291 // Skip the FDE address range
Lang Hameseb195f02014-09-04 04:53:03 +0000292 P += sizeof(TargetPtrT);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000293
294 uint8_t Augmentationsize = *P;
295 P += 1;
296 if (Augmentationsize != 0) {
Daniel Sanders523b1712014-11-01 15:52:31 +0000297 TargetPtrT LSDA = readBytesUnaligned(P, sizeof(TargetPtrT));
Lang Hameseb195f02014-09-04 04:53:03 +0000298 TargetPtrT NewLSDA = LSDA - DeltaForEH;
Daniel Sanders523b1712014-11-01 15:52:31 +0000299 writeBytesUnaligned(NewLSDA, P, sizeof(TargetPtrT));
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000300 }
301
302 return Ret;
303}
304
Lang Hameseb195f02014-09-04 04:53:03 +0000305static int64_t computeDelta(SectionEntry *A, SectionEntry *B) {
Sanjoy Das277776a2015-11-23 21:47:41 +0000306 int64_t ObjDistance = static_cast<int64_t>(A->getObjAddress()) -
307 static_cast<int64_t>(B->getObjAddress());
308 int64_t MemDistance = A->getLoadAddress() - B->getLoadAddress();
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000309 return ObjDistance - MemDistance;
310}
311
Lang Hameseb195f02014-09-04 04:53:03 +0000312template <typename Impl>
313void RuntimeDyldMachOCRTPBase<Impl>::registerEHFrames() {
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000314
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000315 for (int i = 0, e = UnregisteredEHFrameSections.size(); i != e; ++i) {
316 EHFrameRelatedSections &SectionInfo = UnregisteredEHFrameSections[i];
317 if (SectionInfo.EHFrameSID == RTDYLD_INVALID_SECTION_ID ||
318 SectionInfo.TextSID == RTDYLD_INVALID_SECTION_ID)
319 continue;
320 SectionEntry *Text = &Sections[SectionInfo.TextSID];
321 SectionEntry *EHFrame = &Sections[SectionInfo.EHFrameSID];
Craig Topper353eda42014-04-24 06:44:33 +0000322 SectionEntry *ExceptTab = nullptr;
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000323 if (SectionInfo.ExceptTabSID != RTDYLD_INVALID_SECTION_ID)
324 ExceptTab = &Sections[SectionInfo.ExceptTabSID];
325
Lang Hameseb195f02014-09-04 04:53:03 +0000326 int64_t DeltaForText = computeDelta(Text, EHFrame);
327 int64_t DeltaForEH = 0;
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000328 if (ExceptTab)
329 DeltaForEH = computeDelta(ExceptTab, EHFrame);
330
Sanjoy Das277776a2015-11-23 21:47:41 +0000331 uint8_t *P = EHFrame->getAddress();
332 uint8_t *End = P + EHFrame->getSize();
Lang Hames2d8a2aa2016-01-28 22:35:48 +0000333 while (P != End) {
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000334 P = processFDE(P, DeltaForText, DeltaForEH);
Lang Hames2d8a2aa2016-01-28 22:35:48 +0000335 }
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000336
Sanjoy Das277776a2015-11-23 21:47:41 +0000337 MemMgr.registerEHFrames(EHFrame->getAddress(), EHFrame->getLoadAddress(),
338 EHFrame->getSize());
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000339 }
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000340 UnregisteredEHFrameSections.clear();
341}
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000342
Lang Hamesa5216882014-07-17 18:54:50 +0000343std::unique_ptr<RuntimeDyldMachO>
Lang Hames633fe142015-03-30 03:37:06 +0000344RuntimeDyldMachO::create(Triple::ArchType Arch,
345 RuntimeDyld::MemoryManager &MemMgr,
346 RuntimeDyld::SymbolResolver &Resolver) {
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000347 switch (Arch) {
Juergen Ributzka7608dc02014-03-21 20:28:42 +0000348 default:
Lang Hamesa5216882014-07-17 18:54:50 +0000349 llvm_unreachable("Unsupported target for RuntimeDyldMachO.");
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000350 break;
Lang Hames633fe142015-03-30 03:37:06 +0000351 case Triple::arm:
352 return make_unique<RuntimeDyldMachOARM>(MemMgr, Resolver);
353 case Triple::aarch64:
354 return make_unique<RuntimeDyldMachOAArch64>(MemMgr, Resolver);
355 case Triple::x86:
356 return make_unique<RuntimeDyldMachOI386>(MemMgr, Resolver);
357 case Triple::x86_64:
358 return make_unique<RuntimeDyldMachOX86_64>(MemMgr, Resolver);
Danil Malyshev72510f22011-07-13 07:57:58 +0000359 }
Danil Malyshev72510f22011-07-13 07:57:58 +0000360}
361
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000362std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
363RuntimeDyldMachO::loadObject(const object::ObjectFile &O) {
Lang Hames89595312016-04-27 20:24:48 +0000364 if (auto ObjSectionToIDOrErr = loadObjectImpl(O))
365 return llvm::make_unique<LoadedMachOObjectInfo>(*this,
366 *ObjSectionToIDOrErr);
367 else {
368 HasError = true;
369 raw_string_ostream ErrStream(ErrorStr);
370 logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
371 return nullptr;
372 }
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000373}
374
Danil Malyshev72510f22011-07-13 07:57:58 +0000375} // end namespace llvm