blob: 9ca76602ea18e056de319298e75e6caa7fb4f353 [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Danil Malyshev72510f22011-07-13 07:57:58 +00006//
7//===----------------------------------------------------------------------===//
8//
9// Implementation of the MC-JIT runtime dynamic linker.
10//
11//===----------------------------------------------------------------------===//
12
Eli Bendersky058d6472012-01-22 07:05:02 +000013#include "RuntimeDyldMachO.h"
Lang Hamesa5216882014-07-17 18:54:50 +000014#include "Targets/RuntimeDyldMachOAArch64.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000015#include "Targets/RuntimeDyldMachOARM.h"
Lang Hamesa5216882014-07-17 18:54:50 +000016#include "Targets/RuntimeDyldMachOI386.h"
17#include "Targets/RuntimeDyldMachOX86_64.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000018#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/StringRef.h"
Lang Hamesa5216882014-07-17 18:54:50 +000020
Danil Malyshev72510f22011-07-13 07:57:58 +000021using namespace llvm;
22using namespace llvm::object;
23
Chandler Carruthf58e3762014-04-22 03:04:17 +000024#define DEBUG_TYPE "dyld"
25
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000026namespace {
27
David Blaikie5e1ffae2015-08-05 20:20:29 +000028class LoadedMachOObjectInfo final
David Blaikie87131572017-07-05 15:23:56 +000029 : public LoadedObjectInfoHelper<LoadedMachOObjectInfo,
30 RuntimeDyld::LoadedObjectInfo> {
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,
Lang Hames14a22a42017-08-09 20:19:27 +000057 RuntimeDyldMachO::ObjSectionToIDMap &ObjSectionToID,
58 bool TargetIsLocalThumbFunc) {
Lang Hamesa8183e52015-07-24 17:40:04 +000059 const MachOObjectFile &Obj =
60 static_cast<const MachOObjectFile&>(BaseObjT);
61 MachO::any_relocation_info RE =
62 Obj.getRelocation(RelI->getRawDataRefImpl());
63
64 SectionEntry &Section = Sections[SectionID];
65 uint32_t RelocType = Obj.getAnyRelocationType(RE);
66 bool IsPCRel = Obj.getAnyRelocationPCRel(RE);
67 unsigned Size = Obj.getAnyRelocationLength(RE);
68 uint64_t Offset = RelI->getOffset();
Sanjoy Das277776a2015-11-23 21:47:41 +000069 uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);
Lang Hamesa8183e52015-07-24 17:40:04 +000070 unsigned NumBytes = 1 << Size;
71 int64_t Addend = readBytesUnaligned(LocalAddress, NumBytes);
72
73 unsigned SymbolBaseAddr = Obj.getScatteredRelocationValue(RE);
74 section_iterator TargetSI = getSectionByAddress(Obj, SymbolBaseAddr);
75 assert(TargetSI != Obj.section_end() && "Can't find section for symbol");
76 uint64_t SectionBaseAddr = TargetSI->getAddress();
77 SectionRef TargetSection = *TargetSI;
78 bool IsCode = TargetSection.isText();
Lang Hames89595312016-04-27 20:24:48 +000079 uint32_t TargetSectionID = ~0U;
80 if (auto TargetSectionIDOrErr =
81 findOrEmitSection(Obj, TargetSection, IsCode, ObjSectionToID))
82 TargetSectionID = *TargetSectionIDOrErr;
83 else
84 return TargetSectionIDOrErr.takeError();
Lang Hamesa8183e52015-07-24 17:40:04 +000085
86 Addend -= SectionBaseAddr;
87 RelocationEntry R(SectionID, Offset, RelocType, Addend, IsPCRel, Size);
Lang Hames14a22a42017-08-09 20:19:27 +000088 R.IsTargetThumbFunc = TargetIsLocalThumbFunc;
Lang Hamesa8183e52015-07-24 17:40:04 +000089
90 addRelocationForSection(R, TargetSectionID);
91
92 return ++RelI;
93}
94
95
Lang Hames89595312016-04-27 20:24:48 +000096Expected<RelocationValueRef>
97RuntimeDyldMachO::getRelocationValueRef(
Lang Hamesb5c7b1f2014-11-26 16:54:40 +000098 const ObjectFile &BaseTObj, const relocation_iterator &RI,
Lang Hamesa5cd9502014-11-27 05:40:13 +000099 const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID) {
Lang Hamesa5216882014-07-17 18:54:50 +0000100
101 const MachOObjectFile &Obj =
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000102 static_cast<const MachOObjectFile &>(BaseTObj);
Lang Hamesa5216882014-07-17 18:54:50 +0000103 MachO::any_relocation_info RelInfo =
104 Obj.getRelocation(RI->getRawDataRefImpl());
105 RelocationValueRef Value;
106
107 bool IsExternal = Obj.getPlainRelocationExternal(RelInfo);
108 if (IsExternal) {
109 symbol_iterator Symbol = RI->getSymbol();
Lang Hames89595312016-04-27 20:24:48 +0000110 StringRef TargetName;
111 if (auto TargetNameOrErr = Symbol->getName())
112 TargetName = *TargetNameOrErr;
113 else
114 return TargetNameOrErr.takeError();
Lang Hames6bfd3982015-01-16 23:13:56 +0000115 RTDyldSymbolTable::const_iterator SI =
Lang Hamesa5cd9502014-11-27 05:40:13 +0000116 GlobalSymbolTable.find(TargetName.data());
117 if (SI != GlobalSymbolTable.end()) {
Lang Hames6bfd3982015-01-16 23:13:56 +0000118 const auto &SymInfo = SI->second;
119 Value.SectionID = SymInfo.getSectionID();
120 Value.Offset = SymInfo.getOffset() + RE.Addend;
Lang Hamesa5216882014-07-17 18:54:50 +0000121 } else {
Lang Hamesa5cd9502014-11-27 05:40:13 +0000122 Value.SymbolName = TargetName.data();
123 Value.Offset = RE.Addend;
Lang Hamesa5216882014-07-17 18:54:50 +0000124 }
125 } else {
Keno Fischerc780e8e2015-05-21 21:24:32 +0000126 SectionRef Sec = Obj.getAnyRelocationSection(RelInfo);
Rafael Espindola80291272014-10-08 15:28:58 +0000127 bool IsCode = Sec.isText();
Lang Hames89595312016-04-27 20:24:48 +0000128 if (auto SectionIDOrErr = findOrEmitSection(Obj, Sec, IsCode,
129 ObjSectionToID))
130 Value.SectionID = *SectionIDOrErr;
131 else
132 return SectionIDOrErr.takeError();
Rafael Espindola80291272014-10-08 15:28:58 +0000133 uint64_t Addr = Sec.getAddress();
Lang Hamesca279c22014-09-07 04:03:32 +0000134 Value.Offset = RE.Addend - Addr;
Lang Hamesa5216882014-07-17 18:54:50 +0000135 }
136
137 return Value;
138}
139
140void RuntimeDyldMachO::makeValueAddendPCRel(RelocationValueRef &Value,
Lang Hames13163652014-07-30 03:35:05 +0000141 const relocation_iterator &RI,
142 unsigned OffsetToNextPC) {
Rafael Espindola76ad2322015-07-06 14:55:37 +0000143 auto &O = *cast<MachOObjectFile>(RI->getObject());
144 section_iterator SecI = O.getRelocationRelocatedSection(RI);
145 Value.Offset += RI->getOffset() + OffsetToNextPC + SecI->getAddress();
Lang Hamesa5216882014-07-17 18:54:50 +0000146}
147
148void RuntimeDyldMachO::dumpRelocationToResolve(const RelocationEntry &RE,
149 uint64_t Value) const {
150 const SectionEntry &Section = Sections[RE.SectionID];
Sanjoy Das277776a2015-11-23 21:47:41 +0000151 uint8_t *LocalAddress = Section.getAddress() + RE.Offset;
152 uint64_t FinalAddress = Section.getLoadAddress() + RE.Offset;
Lang Hamesa5216882014-07-17 18:54:50 +0000153
154 dbgs() << "resolveRelocation Section: " << RE.SectionID
155 << " LocalAddress: " << format("%p", LocalAddress)
Lang Hamesc5cafbb2014-08-28 04:25:17 +0000156 << " FinalAddress: " << format("0x%016" PRIx64, FinalAddress)
157 << " Value: " << format("0x%016" PRIx64, Value) << " Addend: " << RE.Addend
Lang Hamesa5216882014-07-17 18:54:50 +0000158 << " isPCRel: " << RE.IsPCRel << " MachoType: " << RE.RelType
159 << " Size: " << (1 << RE.Size) << "\n";
160}
161
Lang Hames6f1048f2014-09-11 19:21:14 +0000162section_iterator
163RuntimeDyldMachO::getSectionByAddress(const MachOObjectFile &Obj,
164 uint64_t Addr) {
165 section_iterator SI = Obj.section_begin();
166 section_iterator SE = Obj.section_end();
167
168 for (; SI != SE; ++SI) {
Rafael Espindola80291272014-10-08 15:28:58 +0000169 uint64_t SAddr = SI->getAddress();
170 uint64_t SSize = SI->getSize();
Lang Hames6f1048f2014-09-11 19:21:14 +0000171 if ((Addr >= SAddr) && (Addr < SAddr + SSize))
172 return SI;
173 }
174
175 return SE;
176}
177
178
179// Populate __pointers section.
Lang Hames89595312016-04-27 20:24:48 +0000180Error RuntimeDyldMachO::populateIndirectSymbolPointersSection(
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000181 const MachOObjectFile &Obj,
Lang Hames6f1048f2014-09-11 19:21:14 +0000182 const SectionRef &PTSection,
183 unsigned PTSectionID) {
184 assert(!Obj.is64Bit() &&
185 "Pointer table section not supported in 64-bit MachO.");
186
187 MachO::dysymtab_command DySymTabCmd = Obj.getDysymtabLoadCommand();
188 MachO::section Sec32 = Obj.getSection(PTSection.getRawDataRefImpl());
189 uint32_t PTSectionSize = Sec32.size;
190 unsigned FirstIndirectSymbol = Sec32.reserved1;
191 const unsigned PTEntrySize = 4;
192 unsigned NumPTEntries = PTSectionSize / PTEntrySize;
193 unsigned PTEntryOffset = 0;
194
195 assert((PTSectionSize % PTEntrySize) == 0 &&
196 "Pointers section does not contain a whole number of stubs?");
197
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000198 LLVM_DEBUG(dbgs() << "Populating pointer table section "
199 << Sections[PTSectionID].getName() << ", Section ID "
200 << PTSectionID << ", " << NumPTEntries << " entries, "
201 << PTEntrySize << " bytes each:\n");
Lang Hames6f1048f2014-09-11 19:21:14 +0000202
203 for (unsigned i = 0; i < NumPTEntries; ++i) {
204 unsigned SymbolIndex =
205 Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
206 symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
Lang Hames89595312016-04-27 20:24:48 +0000207 StringRef IndirectSymbolName;
208 if (auto IndirectSymbolNameOrErr = SI->getName())
209 IndirectSymbolName = *IndirectSymbolNameOrErr;
210 else
211 return IndirectSymbolNameOrErr.takeError();
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000212 LLVM_DEBUG(dbgs() << " " << IndirectSymbolName << ": index " << SymbolIndex
213 << ", PT offset: " << PTEntryOffset << "\n");
Lang Hames6f1048f2014-09-11 19:21:14 +0000214 RelocationEntry RE(PTSectionID, PTEntryOffset,
215 MachO::GENERIC_RELOC_VANILLA, 0, false, 2);
216 addRelocationForSymbol(RE, IndirectSymbolName);
217 PTEntryOffset += PTEntrySize;
218 }
Lang Hames89595312016-04-27 20:24:48 +0000219 return Error::success();
Lang Hames6f1048f2014-09-11 19:21:14 +0000220}
221
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000222bool RuntimeDyldMachO::isCompatibleFile(const object::ObjectFile &Obj) const {
223 return Obj.isMachO();
Lang Hamesa5216882014-07-17 18:54:50 +0000224}
225
Lang Hameseb195f02014-09-04 04:53:03 +0000226template <typename Impl>
Lang Hames89595312016-04-27 20:24:48 +0000227Error
228RuntimeDyldMachOCRTPBase<Impl>::finalizeLoad(const ObjectFile &Obj,
229 ObjSectionToIDMap &SectionMap) {
Lang Hameseb195f02014-09-04 04:53:03 +0000230 unsigned EHFrameSID = RTDYLD_INVALID_SECTION_ID;
231 unsigned TextSID = RTDYLD_INVALID_SECTION_ID;
232 unsigned ExceptTabSID = RTDYLD_INVALID_SECTION_ID;
Lang Hameseb195f02014-09-04 04:53:03 +0000233
Lang Hames38aac642015-04-15 03:39:22 +0000234 for (const auto &Section : Obj.sections()) {
Lang Hameseb195f02014-09-04 04:53:03 +0000235 StringRef Name;
George Rimarbcc00e12019-08-14 11:10:11 +0000236 if (Expected<StringRef> NameOrErr = Section.getName())
237 Name = *NameOrErr;
238 else
239 consumeError(NameOrErr.takeError());
Lang Hames38aac642015-04-15 03:39:22 +0000240
241 // Force emission of the __text, __eh_frame, and __gcc_except_tab sections
242 // if they're present. Otherwise call down to the impl to handle other
243 // sections that have already been emitted.
Lang Hames89595312016-04-27 20:24:48 +0000244 if (Name == "__text") {
245 if (auto TextSIDOrErr = findOrEmitSection(Obj, Section, true, SectionMap))
246 TextSID = *TextSIDOrErr;
247 else
248 return TextSIDOrErr.takeError();
249 } else if (Name == "__eh_frame") {
250 if (auto EHFrameSIDOrErr = findOrEmitSection(Obj, Section, false,
251 SectionMap))
252 EHFrameSID = *EHFrameSIDOrErr;
253 else
254 return EHFrameSIDOrErr.takeError();
255 } else if (Name == "__gcc_except_tab") {
256 if (auto ExceptTabSIDOrErr = findOrEmitSection(Obj, Section, true,
257 SectionMap))
258 ExceptTabSID = *ExceptTabSIDOrErr;
259 else
260 return ExceptTabSIDOrErr.takeError();
261 } else {
Lang Hames38aac642015-04-15 03:39:22 +0000262 auto I = SectionMap.find(Section);
263 if (I != SectionMap.end())
Lang Hames89595312016-04-27 20:24:48 +0000264 if (auto Err = impl().finalizeSection(Obj, I->second, Section))
265 return Err;
Lang Hames38aac642015-04-15 03:39:22 +0000266 }
Lang Hameseb195f02014-09-04 04:53:03 +0000267 }
268 UnregisteredEHFrameSections.push_back(
269 EHFrameRelatedSections(EHFrameSID, TextSID, ExceptTabSID));
Lang Hames89595312016-04-27 20:24:48 +0000270
271 return Error::success();
Lang Hameseb195f02014-09-04 04:53:03 +0000272}
273
274template <typename Impl>
Sanjoy Das277776a2015-11-23 21:47:41 +0000275unsigned char *RuntimeDyldMachOCRTPBase<Impl>::processFDE(uint8_t *P,
Lang Hameseb195f02014-09-04 04:53:03 +0000276 int64_t DeltaForText,
277 int64_t DeltaForEH) {
278 typedef typename Impl::TargetPtrT TargetPtrT;
279
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000280 LLVM_DEBUG(dbgs() << "Processing FDE: Delta for text: " << DeltaForText
281 << ", Delta for EH: " << DeltaForEH << "\n");
Daniel Sanders523b1712014-11-01 15:52:31 +0000282 uint32_t Length = readBytesUnaligned(P, 4);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000283 P += 4;
Sanjoy Das277776a2015-11-23 21:47:41 +0000284 uint8_t *Ret = P + Length;
Daniel Sanders523b1712014-11-01 15:52:31 +0000285 uint32_t Offset = readBytesUnaligned(P, 4);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000286 if (Offset == 0) // is a CIE
287 return Ret;
288
289 P += 4;
Daniel Sanders523b1712014-11-01 15:52:31 +0000290 TargetPtrT FDELocation = readBytesUnaligned(P, sizeof(TargetPtrT));
Lang Hameseb195f02014-09-04 04:53:03 +0000291 TargetPtrT NewLocation = FDELocation - DeltaForText;
Daniel Sanders523b1712014-11-01 15:52:31 +0000292 writeBytesUnaligned(NewLocation, P, sizeof(TargetPtrT));
293
Lang Hameseb195f02014-09-04 04:53:03 +0000294 P += sizeof(TargetPtrT);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000295
296 // Skip the FDE address range
Lang Hameseb195f02014-09-04 04:53:03 +0000297 P += sizeof(TargetPtrT);
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000298
299 uint8_t Augmentationsize = *P;
300 P += 1;
301 if (Augmentationsize != 0) {
Daniel Sanders523b1712014-11-01 15:52:31 +0000302 TargetPtrT LSDA = readBytesUnaligned(P, sizeof(TargetPtrT));
Lang Hameseb195f02014-09-04 04:53:03 +0000303 TargetPtrT NewLSDA = LSDA - DeltaForEH;
Daniel Sanders523b1712014-11-01 15:52:31 +0000304 writeBytesUnaligned(NewLSDA, P, sizeof(TargetPtrT));
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000305 }
306
307 return Ret;
308}
309
Lang Hameseb195f02014-09-04 04:53:03 +0000310static int64_t computeDelta(SectionEntry *A, SectionEntry *B) {
Sanjoy Das277776a2015-11-23 21:47:41 +0000311 int64_t ObjDistance = static_cast<int64_t>(A->getObjAddress()) -
312 static_cast<int64_t>(B->getObjAddress());
313 int64_t MemDistance = A->getLoadAddress() - B->getLoadAddress();
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000314 return ObjDistance - MemDistance;
315}
316
Lang Hameseb195f02014-09-04 04:53:03 +0000317template <typename Impl>
318void RuntimeDyldMachOCRTPBase<Impl>::registerEHFrames() {
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000319
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000320 for (int i = 0, e = UnregisteredEHFrameSections.size(); i != e; ++i) {
321 EHFrameRelatedSections &SectionInfo = UnregisteredEHFrameSections[i];
322 if (SectionInfo.EHFrameSID == RTDYLD_INVALID_SECTION_ID ||
323 SectionInfo.TextSID == RTDYLD_INVALID_SECTION_ID)
324 continue;
325 SectionEntry *Text = &Sections[SectionInfo.TextSID];
326 SectionEntry *EHFrame = &Sections[SectionInfo.EHFrameSID];
Craig Topper353eda42014-04-24 06:44:33 +0000327 SectionEntry *ExceptTab = nullptr;
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000328 if (SectionInfo.ExceptTabSID != RTDYLD_INVALID_SECTION_ID)
329 ExceptTab = &Sections[SectionInfo.ExceptTabSID];
330
Lang Hameseb195f02014-09-04 04:53:03 +0000331 int64_t DeltaForText = computeDelta(Text, EHFrame);
332 int64_t DeltaForEH = 0;
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000333 if (ExceptTab)
334 DeltaForEH = computeDelta(ExceptTab, EHFrame);
335
Sanjoy Das277776a2015-11-23 21:47:41 +0000336 uint8_t *P = EHFrame->getAddress();
337 uint8_t *End = P + EHFrame->getSize();
Lang Hames2d8a2aa2016-01-28 22:35:48 +0000338 while (P != End) {
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000339 P = processFDE(P, DeltaForText, DeltaForEH);
Lang Hames2d8a2aa2016-01-28 22:35:48 +0000340 }
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000341
Sanjoy Das277776a2015-11-23 21:47:41 +0000342 MemMgr.registerEHFrames(EHFrame->getAddress(), EHFrame->getLoadAddress(),
343 EHFrame->getSize());
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000344 }
Andrew Kaylor7bb13442013-10-11 21:25:48 +0000345 UnregisteredEHFrameSections.clear();
346}
Rafael Espindolafa5942b2013-05-05 20:43:10 +0000347
Lang Hamesa5216882014-07-17 18:54:50 +0000348std::unique_ptr<RuntimeDyldMachO>
Lang Hames633fe142015-03-30 03:37:06 +0000349RuntimeDyldMachO::create(Triple::ArchType Arch,
350 RuntimeDyld::MemoryManager &MemMgr,
Lang Hamesad4a9112016-08-01 20:49:11 +0000351 JITSymbolResolver &Resolver) {
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000352 switch (Arch) {
Juergen Ributzka7608dc02014-03-21 20:28:42 +0000353 default:
Lang Hamesa5216882014-07-17 18:54:50 +0000354 llvm_unreachable("Unsupported target for RuntimeDyldMachO.");
Danil Malyshev70d22cc2012-03-30 16:45:19 +0000355 break;
Lang Hames633fe142015-03-30 03:37:06 +0000356 case Triple::arm:
Jonas Devlieghere0eaee542019-08-15 15:54:37 +0000357 return std::make_unique<RuntimeDyldMachOARM>(MemMgr, Resolver);
Lang Hames633fe142015-03-30 03:37:06 +0000358 case Triple::aarch64:
Jonas Devlieghere0eaee542019-08-15 15:54:37 +0000359 return std::make_unique<RuntimeDyldMachOAArch64>(MemMgr, Resolver);
Tim Northoverf1c28922019-09-12 10:22:23 +0000360 case Triple::aarch64_32:
361 return std::make_unique<RuntimeDyldMachOAArch64>(MemMgr, Resolver);
Lang Hames633fe142015-03-30 03:37:06 +0000362 case Triple::x86:
Jonas Devlieghere0eaee542019-08-15 15:54:37 +0000363 return std::make_unique<RuntimeDyldMachOI386>(MemMgr, Resolver);
Lang Hames633fe142015-03-30 03:37:06 +0000364 case Triple::x86_64:
Jonas Devlieghere0eaee542019-08-15 15:54:37 +0000365 return std::make_unique<RuntimeDyldMachOX86_64>(MemMgr, Resolver);
Danil Malyshev72510f22011-07-13 07:57:58 +0000366 }
Danil Malyshev72510f22011-07-13 07:57:58 +0000367}
368
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000369std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
370RuntimeDyldMachO::loadObject(const object::ObjectFile &O) {
Lang Hames89595312016-04-27 20:24:48 +0000371 if (auto ObjSectionToIDOrErr = loadObjectImpl(O))
Jonas Devlieghere0eaee542019-08-15 15:54:37 +0000372 return std::make_unique<LoadedMachOObjectInfo>(*this,
Lang Hames89595312016-04-27 20:24:48 +0000373 *ObjSectionToIDOrErr);
374 else {
375 HasError = true;
376 raw_string_ostream ErrStream(ErrorStr);
Jonas Devlieghere45eb84f2018-11-11 01:46:03 +0000377 logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
Lang Hames89595312016-04-27 20:24:48 +0000378 return nullptr;
379 }
Lang Hamesb5c7b1f2014-11-26 16:54:40 +0000380}
381
Danil Malyshev72510f22011-07-13 07:57:58 +0000382} // end namespace llvm