LLVM 19.0.0git
ExecutionUtils.cpp
Go to the documentation of this file.
1//===---- ExecutionUtils.cpp - Utilities for executing functions in Orc ---===//
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8
13#include "llvm/IR/Constants.h"
14#include "llvm/IR/Function.h"
16#include "llvm/IR/Module.h"
22#include <string>
23
24namespace llvm {
25namespace orc {
26
28 : InitList(
29 GV ? dyn_cast_or_null<ConstantArray>(GV->getInitializer()) : nullptr),
30 I((InitList && End) ? InitList->getNumOperands() : 0) {
31}
32
34 assert(InitList == Other.InitList && "Incomparable iterators.");
35 return I == Other.I;
36}
37
39 return !(*this == Other);
40}
41
43 ++I;
44 return *this;
45}
46
48 CtorDtorIterator Temp = *this;
49 ++I;
50 return Temp;
51}
52
54 ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(I));
55 assert(CS && "Unrecognized type in llvm.global_ctors/llvm.global_dtors");
56
57 Constant *FuncC = CS->getOperand(1);
58 Function *Func = nullptr;
59
60 // Extract function pointer, pulling off any casts.
61 while (FuncC) {
62 if (Function *F = dyn_cast_or_null<Function>(FuncC)) {
63 Func = F;
64 break;
65 } else if (ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(FuncC)) {
66 if (CE->isCast())
67 FuncC = CE->getOperand(0);
68 else
69 break;
70 } else {
71 // This isn't anything we recognize. Bail out with Func left set to null.
72 break;
73 }
74 }
75
76 auto *Priority = cast<ConstantInt>(CS->getOperand(0));
77 Value *Data = CS->getNumOperands() == 3 ? CS->getOperand(2) : nullptr;
78 if (Data && !isa<GlobalValue>(Data))
79 Data = nullptr;
80 return Element(Priority->getZExtValue(), Func, Data);
81}
82
84 const GlobalVariable *CtorsList = M.getNamedGlobal("llvm.global_ctors");
85 return make_range(CtorDtorIterator(CtorsList, false),
86 CtorDtorIterator(CtorsList, true));
87}
88
90 const GlobalVariable *DtorsList = M.getNamedGlobal("llvm.global_dtors");
91 return make_range(CtorDtorIterator(DtorsList, false),
92 CtorDtorIterator(DtorsList, true));
93}
94
95bool StaticInitGVIterator::isStaticInitGlobal(GlobalValue &GV) {
96 if (GV.isDeclaration())
97 return false;
98
99 if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
100 GV.getName() == "llvm.global_dtors"))
101 return true;
102
103 if (ObjFmt == Triple::MachO) {
104 // FIXME: These section checks are too strict: We should match first and
105 // second word split by comma.
106 if (GV.hasSection() &&
107 (GV.getSection().starts_with("__DATA,__objc_classlist") ||
108 GV.getSection().starts_with("__DATA,__objc_selrefs")))
109 return true;
110 }
111
112 return false;
113}
114
116 if (CtorDtors.empty())
117 return;
118
119 MangleAndInterner Mangle(
121 (*CtorDtors.begin()).Func->getDataLayout());
122
123 for (auto CtorDtor : CtorDtors) {
124 assert(CtorDtor.Func && CtorDtor.Func->hasName() &&
125 "Ctor/Dtor function must be named to be runnable under the JIT");
126
127 // FIXME: Maybe use a symbol promoter here instead.
128 if (CtorDtor.Func->hasLocalLinkage()) {
129 CtorDtor.Func->setLinkage(GlobalValue::ExternalLinkage);
130 CtorDtor.Func->setVisibility(GlobalValue::HiddenVisibility);
131 }
132
133 if (CtorDtor.Data && cast<GlobalValue>(CtorDtor.Data)->isDeclaration()) {
134 dbgs() << " Skipping because why now?\n";
135 continue;
136 }
137
138 CtorDtorsByPriority[CtorDtor.Priority].push_back(
139 Mangle(CtorDtor.Func->getName()));
140 }
141}
142
144 using CtorDtorTy = void (*)();
145
146 SymbolLookupSet LookupSet;
147 for (auto &KV : CtorDtorsByPriority)
148 for (auto &Name : KV.second)
149 LookupSet.add(Name);
150 assert(!LookupSet.containsDuplicates() &&
151 "Ctor/Dtor list contains duplicates");
152
153 auto &ES = JD.getExecutionSession();
154 if (auto CtorDtorMap = ES.lookup(
156 std::move(LookupSet))) {
157 for (auto &KV : CtorDtorsByPriority) {
158 for (auto &Name : KV.second) {
159 assert(CtorDtorMap->count(Name) && "No entry for Name");
160 auto CtorDtor = (*CtorDtorMap)[Name].getAddress().toPtr<CtorDtorTy>();
161 CtorDtor();
162 }
163 }
164 CtorDtorsByPriority.clear();
165 return Error::success();
166 } else
167 return CtorDtorMap.takeError();
168}
169
171 auto& CXXDestructorDataPairs = DSOHandleOverride;
172 for (auto &P : CXXDestructorDataPairs)
173 P.first(P.second);
174 CXXDestructorDataPairs.clear();
175}
176
178 void *Arg,
179 void *DSOHandle) {
180 auto& CXXDestructorDataPairs =
181 *reinterpret_cast<CXXDestructorDataPairList*>(DSOHandle);
182 CXXDestructorDataPairs.push_back(std::make_pair(Destructor, Arg));
183 return 0;
184}
185
187 MangleAndInterner &Mangle) {
188 SymbolMap RuntimeInterposes;
189 RuntimeInterposes[Mangle("__dso_handle")] = {
191 RuntimeInterposes[Mangle("__cxa_atexit")] = {
193
194 return JD.define(absoluteSymbols(std::move(RuntimeInterposes)));
195}
196
197void ItaniumCXAAtExitSupport::registerAtExit(void (*F)(void *), void *Ctx,
198 void *DSOHandle) {
199 std::lock_guard<std::mutex> Lock(AtExitsMutex);
200 AtExitRecords[DSOHandle].push_back({F, Ctx});
201}
202
204 std::vector<AtExitRecord> AtExitsToRun;
205
206 {
207 std::lock_guard<std::mutex> Lock(AtExitsMutex);
208 auto I = AtExitRecords.find(DSOHandle);
209 if (I != AtExitRecords.end()) {
210 AtExitsToRun = std::move(I->second);
211 AtExitRecords.erase(I);
212 }
213 }
214
215 while (!AtExitsToRun.empty()) {
216 AtExitsToRun.back().F(AtExitsToRun.back().Ctx);
217 AtExitsToRun.pop_back();
218 }
219}
220
223 AddAbsoluteSymbolsFn AddAbsoluteSymbols)
224 : Dylib(std::move(Dylib)), Allow(std::move(Allow)),
225 AddAbsoluteSymbols(std::move(AddAbsoluteSymbols)),
227
230 SymbolPredicate Allow,
231 AddAbsoluteSymbolsFn AddAbsoluteSymbols) {
232 std::string ErrMsg;
233 auto Lib = sys::DynamicLibrary::getPermanentLibrary(FileName, &ErrMsg);
234 if (!Lib.isValid())
235 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
236 return std::make_unique<DynamicLibrarySearchGenerator>(
237 std::move(Lib), GlobalPrefix, std::move(Allow),
238 std::move(AddAbsoluteSymbols));
239}
240
242 LookupState &LS, LookupKind K, JITDylib &JD,
243 JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
244 orc::SymbolMap NewSymbols;
245
246 bool HasGlobalPrefix = (GlobalPrefix != '\0');
247
248 for (auto &KV : Symbols) {
249 auto &Name = KV.first;
250
251 if ((*Name).empty())
252 continue;
253
254 if (Allow && !Allow(Name))
255 continue;
256
257 if (HasGlobalPrefix && (*Name).front() != GlobalPrefix)
258 continue;
259
260 std::string Tmp((*Name).data() + HasGlobalPrefix,
261 (*Name).size() - HasGlobalPrefix);
262 if (void *P = Dylib.getAddressOfSymbol(Tmp.c_str()))
264 }
265
266 if (NewSymbols.empty())
267 return Error::success();
268
269 if (AddAbsoluteSymbols)
270 return AddAbsoluteSymbols(JD, std::move(NewSymbols));
271 return JD.define(absoluteSymbols(std::move(NewSymbols)));
272}
273
276 ObjectLayer &L, const char *FileName,
277 GetObjectFileInterface GetObjFileInterface) {
278
279 auto B = object::createBinary(FileName);
280 if (!B)
281 return createFileError(FileName, B.takeError());
282
283 // If this is a regular archive then create an instance from it.
284 if (isa<object::Archive>(B->getBinary())) {
285 auto [Archive, ArchiveBuffer] = B->takeBinary();
286 return Create(L, std::move(ArchiveBuffer),
287 std::unique_ptr<object::Archive>(
288 static_cast<object::Archive *>(Archive.release())),
289 std::move(GetObjFileInterface));
290 }
291
292 // If this is a universal binary then search for a slice matching the given
293 // Triple.
294 if (auto *UB = dyn_cast<object::MachOUniversalBinary>(B->getBinary())) {
295
296 const auto &TT = L.getExecutionSession().getTargetTriple();
297
298 auto SliceRange = getSliceRangeForArch(*UB, TT);
299 if (!SliceRange)
300 return SliceRange.takeError();
301
302 auto SliceBuffer = MemoryBuffer::getFileSlice(FileName, SliceRange->second,
303 SliceRange->first);
304 if (!SliceBuffer)
305 return make_error<StringError>(
306 Twine("Could not create buffer for ") + TT.str() + " slice of " +
307 FileName + ": [ " + formatv("{0:x}", SliceRange->first) + " .. " +
308 formatv("{0:x}", SliceRange->first + SliceRange->second) + ": " +
309 SliceBuffer.getError().message(),
310 SliceBuffer.getError());
311
312 return Create(L, std::move(*SliceBuffer), std::move(GetObjFileInterface));
313 }
314
315 return make_error<StringError>(Twine("Unrecognized file type for ") +
316 FileName,
318}
319
322 ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
323 std::unique_ptr<object::Archive> Archive,
324 GetObjectFileInterface GetObjFileInterface) {
325
326 Error Err = Error::success();
327
328 std::unique_ptr<StaticLibraryDefinitionGenerator> ADG(
330 L, std::move(ArchiveBuffer), std::move(Archive),
331 std::move(GetObjFileInterface), Err));
332
333 if (Err)
334 return std::move(Err);
335
336 return std::move(ADG);
337}
338
341 ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
342 GetObjectFileInterface GetObjFileInterface) {
343
344 auto B = object::createBinary(ArchiveBuffer->getMemBufferRef());
345 if (!B)
346 return B.takeError();
347
348 // If this is a regular archive then create an instance from it.
349 if (isa<object::Archive>(*B))
350 return Create(L, std::move(ArchiveBuffer),
351 std::unique_ptr<object::Archive>(
352 static_cast<object::Archive *>(B->release())),
353 std::move(GetObjFileInterface));
354
355 // If this is a universal binary then search for a slice matching the given
356 // Triple.
357 if (auto *UB = dyn_cast<object::MachOUniversalBinary>(B->get())) {
358
359 const auto &TT = L.getExecutionSession().getTargetTriple();
360
361 auto SliceRange = getSliceRangeForArch(*UB, TT);
362 if (!SliceRange)
363 return SliceRange.takeError();
364
365 MemoryBufferRef SliceRef(
366 StringRef(ArchiveBuffer->getBufferStart() + SliceRange->first,
367 SliceRange->second),
368 ArchiveBuffer->getBufferIdentifier());
369
370 auto Archive = object::Archive::create(SliceRef);
371 if (!Archive)
372 return Archive.takeError();
373
374 return Create(L, std::move(ArchiveBuffer), std::move(*Archive),
375 std::move(GetObjFileInterface));
376 }
377
378 return make_error<StringError>(Twine("Unrecognized file type for ") +
379 ArchiveBuffer->getBufferIdentifier(),
381}
382
384 LookupState &LS, LookupKind K, JITDylib &JD,
385 JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
386 // Don't materialize symbols from static archives unless this is a static
387 // lookup.
388 if (K != LookupKind::Static)
389 return Error::success();
390
391 // Bail out early if we've already freed the archive.
392 if (!Archive)
393 return Error::success();
394
396
397 for (const auto &KV : Symbols) {
398 const auto &Name = KV.first;
399 if (!ObjectFilesMap.count(Name))
400 continue;
401 auto ChildBuffer = ObjectFilesMap[Name];
402 ChildBufferInfos.insert(
403 {ChildBuffer.getBuffer(), ChildBuffer.getBufferIdentifier()});
404 }
405
406 for (auto ChildBufferInfo : ChildBufferInfos) {
407 MemoryBufferRef ChildBufferRef(ChildBufferInfo.first,
408 ChildBufferInfo.second);
409
410 auto I = GetObjFileInterface(L.getExecutionSession(), ChildBufferRef);
411 if (!I)
412 return I.takeError();
413
414 if (auto Err = L.add(JD, MemoryBuffer::getMemBuffer(ChildBufferRef, false),
415 std::move(*I)))
416 return Err;
417 }
418
419 return Error::success();
420}
421
422Error StaticLibraryDefinitionGenerator::buildObjectFilesMap() {
424 DenseSet<uint64_t> Visited;
425 DenseSet<uint64_t> Excluded;
426 StringSaver FileNames(ObjFileNameStorage);
427 for (auto &S : Archive->symbols()) {
428 StringRef SymName = S.getName();
429 auto Member = S.getMember();
430 if (!Member)
431 return Member.takeError();
432 auto DataOffset = Member->getDataOffset();
433 if (!Visited.count(DataOffset)) {
434 Visited.insert(DataOffset);
435 auto Child = Member->getAsBinary();
436 if (!Child)
437 return Child.takeError();
438 if ((*Child)->isCOFFImportFile()) {
439 ImportedDynamicLibraries.insert((*Child)->getFileName().str());
440 Excluded.insert(DataOffset);
441 continue;
442 }
443
444 // Give members of the archive a name that contains the archive path so
445 // that they can be differentiated from a member with the same name in a
446 // different archive. This also ensure initializer symbols names will be
447 // unique within a JITDylib.
448 StringRef FullName = FileNames.save(Archive->getFileName() + "(" +
449 (*Child)->getFileName() + ")");
450 MemoryBufferRef MemBuffer((*Child)->getMemoryBufferRef().getBuffer(),
451 FullName);
452
453 MemoryBuffers[DataOffset] = MemBuffer;
454 }
455 if (!Excluded.count(DataOffset))
456 ObjectFilesMap[L.getExecutionSession().intern(SymName)] =
457 MemoryBuffers[DataOffset];
458 }
459
460 return Error::success();
461}
462
463Expected<std::pair<size_t, size_t>>
464StaticLibraryDefinitionGenerator::getSliceRangeForArch(
465 object::MachOUniversalBinary &UB, const Triple &TT) {
466
467 for (const auto &Obj : UB.objects()) {
468 auto ObjTT = Obj.getTriple();
469 if (ObjTT.getArch() == TT.getArch() &&
470 ObjTT.getSubArch() == TT.getSubArch() &&
471 (TT.getVendor() == Triple::UnknownVendor ||
472 ObjTT.getVendor() == TT.getVendor())) {
473 // We found a match. Return the range for the slice.
474 return std::make_pair(Obj.getOffset(), Obj.getSize());
475 }
476 }
477
478 return make_error<StringError>(Twine("Universal binary ") + UB.getFileName() +
479 " does not contain a slice for " +
480 TT.str(),
482}
483
484StaticLibraryDefinitionGenerator::StaticLibraryDefinitionGenerator(
485 ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
486 std::unique_ptr<object::Archive> Archive,
487 GetObjectFileInterface GetObjFileInterface, Error &Err)
488 : L(L), GetObjFileInterface(std::move(GetObjFileInterface)),
489 ArchiveBuffer(std::move(ArchiveBuffer)), Archive(std::move(Archive)) {
490 ErrorAsOutParameter _(&Err);
491 if (!this->GetObjFileInterface)
492 this->GetObjFileInterface = getObjectFileInterface;
493 if (!Err)
494 Err = buildObjectFilesMap();
495}
496
497std::unique_ptr<DLLImportDefinitionGenerator>
500 return std::unique_ptr<DLLImportDefinitionGenerator>(
502}
503
505 LookupState &LS, LookupKind K, JITDylib &JD,
506 JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
507 JITDylibSearchOrder LinkOrder;
508 JD.withLinkOrderDo([&](const JITDylibSearchOrder &LO) {
509 LinkOrder.reserve(LO.size());
510 for (auto &KV : LO) {
511 if (KV.first == &JD)
512 continue;
513 LinkOrder.push_back(KV);
514 }
515 });
516
517 // FIXME: if regular symbol name start with __imp_ we have to issue lookup of
518 // both __imp_ and stripped name and use the lookup information to resolve the
519 // real symbol name.
520 SymbolLookupSet LookupSet;
522 for (auto &KV : Symbols) {
523 StringRef Deinterned = *KV.first;
524 if (Deinterned.starts_with(getImpPrefix()))
525 Deinterned = Deinterned.drop_front(StringRef(getImpPrefix()).size());
526 // Don't degrade the required state
527 if (ToLookUpSymbols.count(Deinterned) &&
528 ToLookUpSymbols[Deinterned] == SymbolLookupFlags::RequiredSymbol)
529 continue;
530 ToLookUpSymbols[Deinterned] = KV.second;
531 }
532
533 for (auto &KV : ToLookUpSymbols)
534 LookupSet.add(ES.intern(KV.first), KV.second);
535
536 auto Resolved =
537 ES.lookup(LinkOrder, LookupSet, LookupKind::DLSym, SymbolState::Resolved);
538 if (!Resolved)
539 return Resolved.takeError();
540
541 auto G = createStubsGraph(*Resolved);
542 if (!G)
543 return G.takeError();
544 return L.add(JD, std::move(*G));
545}
546
548DLLImportDefinitionGenerator::getTargetPointerSize(const Triple &TT) {
549 switch (TT.getArch()) {
550 case Triple::x86_64:
551 return 8;
552 default:
553 return make_error<StringError>(
554 "architecture unsupported by DLLImportDefinitionGenerator",
556 }
557}
558
559Expected<llvm::endianness>
560DLLImportDefinitionGenerator::getEndianness(const Triple &TT) {
561 switch (TT.getArch()) {
562 case Triple::x86_64:
564 default:
565 return make_error<StringError>(
566 "architecture unsupported by DLLImportDefinitionGenerator",
568 }
569}
570
571Expected<std::unique_ptr<jitlink::LinkGraph>>
572DLLImportDefinitionGenerator::createStubsGraph(const SymbolMap &Resolved) {
573 Triple TT = ES.getTargetTriple();
574 auto PointerSize = getTargetPointerSize(TT);
575 if (!PointerSize)
576 return PointerSize.takeError();
577 auto Endianness = getEndianness(TT);
578 if (!Endianness)
579 return Endianness.takeError();
580
581 auto G = std::make_unique<jitlink::LinkGraph>(
582 "<DLLIMPORT_STUBS>", TT, *PointerSize, *Endianness,
584 jitlink::Section &Sec =
585 G->createSection(getSectionName(), MemProt::Read | MemProt::Exec);
586
587 for (auto &KV : Resolved) {
588 jitlink::Symbol &Target = G->addAbsoluteSymbol(
589 *KV.first, KV.second.getAddress(), *PointerSize,
591
592 // Create __imp_ symbol
593 jitlink::Symbol &Ptr =
595 auto NameCopy = G->allocateContent(Twine(getImpPrefix()) + *KV.first);
596 StringRef NameCopyRef = StringRef(NameCopy.data(), NameCopy.size());
597 Ptr.setName(NameCopyRef);
598 Ptr.setLinkage(jitlink::Linkage::Strong);
600
601 // Create PLT stub
602 // FIXME: check PLT stub of data symbol is not accessed
603 jitlink::Block &StubBlock =
605 G->addDefinedSymbol(StubBlock, 0, *KV.first, StubBlock.getSize(),
607 false);
608 }
609
610 return std::move(G);
611}
612
613} // End namespace orc.
614} // End namespace llvm.
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
@ GlobalPrefix
Definition: AsmWriter.cpp:376
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::string Name
bool End
Definition: ELF_riscv.cpp:480
#define _
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
Module.h This file contains the declarations for the Module class.
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ConstantArray - Constant Array Declarations.
Definition: Constants.h:424
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1084
This is an important base class in LLVM.
Definition: Constant.h:42
bool empty() const
Definition: DenseMap.h:98
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:151
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:290
StringRef getSection() const
Definition: Globals.cpp:183
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:68
bool hasSection() const
Definition: GlobalValue.h:290
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:52
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Map a subrange of the specified file as a MemoryBuffer.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:250
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:594
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition: StringSaver.h:21
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ UnknownVendor
Definition: Triple.h:182
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Value * getOperand(unsigned i) const
Definition: User.h:169
unsigned getNumOperands() const
Definition: User.h:191
LLVM Value Representation.
Definition: Value.h:74
bool hasName() const
Definition: Value.h:261
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:97
A range adaptor for a pair of iterators.
IteratorT begin() const
static Expected< std::unique_ptr< Archive > > create(MemoryBufferRef Source)
Definition: Archive.cpp:669
This iterator provides a convenient way to iterate over the elements of an llvm.global_ctors/llvm....
bool operator!=(const CtorDtorIterator &Other) const
Test iterators for inequality.
Element operator*() const
Dereference iterator.
CtorDtorIterator(const GlobalVariable *GV, bool End)
Construct an iterator instance.
CtorDtorIterator & operator++()
Pre-increment iterator.
bool operator==(const CtorDtorIterator &Other) const
Test iterators for equality.
void add(iterator_range< CtorDtorIterator > CtorDtors)
A utility class to create COFF dllimport GOT symbols (__imp_*) and PLT stubs.
static std::unique_ptr< DLLImportDefinitionGenerator > Create(ExecutionSession &ES, ObjectLinkingLayer &L)
Creates a DLLImportDefinitionGenerator instance.
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
std::function< bool(const SymbolStringPtr &)> SymbolPredicate
DynamicLibrarySearchGenerator(sys::DynamicLibrary Dylib, char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Create a DynamicLibrarySearchGenerator that searches for symbols in the given sys::DynamicLibrary.
static Expected< std::unique_ptr< DynamicLibrarySearchGenerator > > Load(const char *FileName, char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
An ExecutionSession represents a running JIT program.
Definition: Core.h:1431
const Triple & getTargetTriple() const
Return the triple for the executor.
Definition: Core.h:1474
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:1485
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Definition: Core.cpp:1802
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
void registerAtExit(void(*F)(void *), void *Ctx, void *DSOHandle)
Represents a JIT'd dynamic library.
Definition: Core.h:989
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Definition: Core.h:1910
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Definition: Core.h:1008
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
Definition: Core.h:1903
static int CXAAtExitOverride(DestructorPtr Destructor, void *Arg, void *DSOHandle)
std::vector< CXXDestructorDataPair > CXXDestructorDataPairList
CXXDestructorDataPairList DSOHandleOverride
void runDestructors()
Run any destructors recorded by the overriden __cxa_atexit function (CXAAtExitOverride).
Error enable(JITDylib &JD, MangleAndInterner &Mangler)
Wraps state for a lookup-in-progress.
Definition: Core.h:921
Mangles symbol names then uniques them in the context of an ExecutionSession.
Definition: Mangling.h:26
Interface for Layers that accept object files.
Definition: Layer.h:133
virtual Error add(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > O, MaterializationUnit::Interface I)
Adds a MaterializationUnit for the object file in the given memory buffer to the JITDylib for the giv...
Definition: Layer.cpp:170
ExecutionSession & getExecutionSession()
Returns the execution session for this layer.
Definition: Layer.h:141
An ObjectLayer implementation built on JITLink.
A utility class to expose symbols from a static library.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load(ObjectLayer &L, const char *FileName, GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibraryDefinitionGenerator from the given path.
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > ArchiveBuffer, std::unique_ptr< object::Archive > Archive, GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibrarySearchGenerator from the given memory buffer and Archive object.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:183
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition: Core.h:244
bool containsDuplicates()
Returns true if this set contains any duplicates.
Definition: Core.h:371
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path using the library load operatio...
void * getAddressOfSymbol(const char *symbolName)
Searches through the library for the symbol symbolName.
constexpr llvm::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
Definition: MsgPack.h:24
Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
Definition: Binary.cpp:45
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
Definition: Core.h:166
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Definition: Core.h:162
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:791
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition: Core.h:135
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
Definition: Core.h:121
Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:157
@ Resolved
Queried, materialization begun.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition: Error.h:1380
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1680
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto formatv(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< Ts >(Vals))...))>
auto dyn_cast_or_null(const Y &Val)
Definition: Casting.h:759
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
@ Other
Any other memory.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1849
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
Accessor for an element of the global_ctors/global_dtors array.