LLVM 20.0.0git
Core.h
Go to the documentation of this file.
1//===------ Core.h -- Core ORC APIs (Layer, JITDylib, etc.) -----*- C++ -*-===//
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//
9// Contains core ORC APIs.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_CORE_H
14#define LLVM_EXECUTIONENGINE_ORC_CORE_H
15
17#include "llvm/ADT/DenseSet.h"
29#include "llvm/Support/Debug.h"
31
32#include <atomic>
33#include <deque>
34#include <future>
35#include <memory>
36#include <vector>
37
38namespace llvm {
39namespace orc {
40
41// Forward declare some classes.
42class AsynchronousSymbolQuery;
43class ExecutionSession;
44class MaterializationResponsibility;
45class JITDylib;
46class ResourceTracker;
47class InProgressLookupState;
48
49enum class SymbolState : uint8_t;
50
53
54/// A definition of a Symbol within a JITDylib.
56public:
59
61 : JD(std::move(JD)), Name(std::move(Name)) {}
62
63 const JITDylib &getJITDylib() const { return *JD; }
64 const SymbolStringPtr &getName() const { return Name; }
65
67 void lookupAsync(LookupAsyncOnCompleteFn OnComplete) const;
68
69private:
70 JITDylibSP JD;
71 SymbolStringPtr Name;
72};
73
74using ResourceKey = uintptr_t;
75
76/// API to remove / transfer ownership of JIT resources.
77class ResourceTracker : public ThreadSafeRefCountedBase<ResourceTracker> {
78private:
79 friend class ExecutionSession;
80 friend class JITDylib;
82
83public:
88
90
91 /// Return the JITDylib targeted by this tracker.
93 return *reinterpret_cast<JITDylib *>(JDAndFlag.load() &
94 ~static_cast<uintptr_t>(1));
95 }
96
97 /// Runs the given callback under the session lock, passing in the associated
98 /// ResourceKey. This is the safe way to associate resources with trackers.
99 template <typename Func> Error withResourceKeyDo(Func &&F);
100
101 /// Remove all resources associated with this key.
102 Error remove();
103
104 /// Transfer all resources associated with this key to the given
105 /// tracker, which must target the same JITDylib as this one.
106 void transferTo(ResourceTracker &DstRT);
107
108 /// Return true if this tracker has become defunct.
109 bool isDefunct() const { return JDAndFlag.load() & 0x1; }
110
111 /// Returns the key associated with this tracker.
112 /// This method should not be used except for debug logging: there is no
113 /// guarantee that the returned value will remain valid.
114 ResourceKey getKeyUnsafe() const { return reinterpret_cast<uintptr_t>(this); }
115
116private:
118
119 void makeDefunct();
120
121 std::atomic_uintptr_t JDAndFlag;
122};
123
124/// Listens for ResourceTracker operations.
126public:
128
129 /// This function will be called *outside* the session lock. ResourceManagers
130 /// should perform book-keeping under the session lock, and any expensive
131 /// cleanup outside the session lock.
133
134 /// This function will be called *inside* the session lock. ResourceManagers
135 /// DO NOT need to re-lock the session.
137 ResourceKey SrcK) = 0;
138};
139
140/// Lookup flags that apply to each dylib in the search order for a lookup.
141///
142/// If MatchHiddenSymbolsOnly is used (the default) for a given dylib, then
143/// only symbols in that Dylib's interface will be searched. If
144/// MatchHiddenSymbols is used then symbols with hidden visibility will match
145/// as well.
147
148/// Lookup flags that apply to each symbol in a lookup.
149///
150/// If RequiredSymbol is used (the default) for a given symbol then that symbol
151/// must be found during the lookup or the lookup will fail returning a
152/// SymbolNotFound error. If WeaklyReferencedSymbol is used and the given
153/// symbol is not found then the query will continue, and no result for the
154/// missing symbol will be present in the result (assuming the rest of the
155/// lookup succeeds).
157
158/// Describes the kind of lookup being performed. The lookup kind is passed to
159/// symbol generators (if they're invoked) to help them determine what
160/// definitions to generate.
161///
162/// Static -- Lookup is being performed as-if at static link time (e.g.
163/// generators representing static archives should pull in new
164/// definitions).
165///
166/// DLSym -- Lookup is being performed as-if at runtime (e.g. generators
167/// representing static archives should not pull in new definitions).
168enum class LookupKind { Static, DLSym };
169
170/// A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search
171/// order during symbol lookup.
173 std::vector<std::pair<JITDylib *, JITDylibLookupFlags>>;
174
175/// Convenience function for creating a search order from an ArrayRef of
176/// JITDylib*, all with the same flags.
181 O.reserve(JDs.size());
182 for (auto *JD : JDs)
183 O.push_back(std::make_pair(JD, Flags));
184 return O;
185}
186
187/// A set of symbols to look up, each associated with a SymbolLookupFlags
188/// value.
189///
190/// This class is backed by a vector and optimized for fast insertion,
191/// deletion and iteration. It does not guarantee a stable order between
192/// operations, and will not automatically detect duplicate elements (they
193/// can be manually checked by calling the validate method).
195public:
196 using value_type = std::pair<SymbolStringPtr, SymbolLookupFlags>;
197 using UnderlyingVector = std::vector<value_type>;
198 using iterator = UnderlyingVector::iterator;
199 using const_iterator = UnderlyingVector::const_iterator;
200
201 SymbolLookupSet() = default;
202
203 SymbolLookupSet(std::initializer_list<value_type> Elems) {
204 for (auto &E : Elems)
205 Symbols.push_back(std::move(E));
206 }
207
211 add(std::move(Name), Flags);
212 }
213
214 /// Construct a SymbolLookupSet from an initializer list of SymbolStringPtrs.
216 std::initializer_list<SymbolStringPtr> Names,
218 Symbols.reserve(Names.size());
219 for (const auto &Name : Names)
220 add(std::move(Name), Flags);
221 }
222
223 /// Construct a SymbolLookupSet from a SymbolNameSet with the given
224 /// Flags used for each value.
226 const SymbolNameSet &Names,
228 Symbols.reserve(Names.size());
229 for (const auto &Name : Names)
230 add(Name, Flags);
231 }
232
233 /// Construct a SymbolLookupSet from a vector of symbols with the given Flags
234 /// used for each value.
235 /// If the ArrayRef contains duplicates it is up to the client to remove these
236 /// before using this instance for lookup.
240 Symbols.reserve(Names.size());
241 for (const auto &Name : Names)
242 add(Name, Flags);
243 }
244
245 /// Construct a SymbolLookupSet from DenseMap keys.
246 template <typename ValT>
247 static SymbolLookupSet
251 Result.Symbols.reserve(M.size());
252 for (const auto &[Name, Val] : M)
253 Result.add(Name, Flags);
254 return Result;
255 }
256
257 /// Add an element to the set. The client is responsible for checking that
258 /// duplicates are not added.
262 Symbols.push_back(std::make_pair(std::move(Name), Flags));
263 return *this;
264 }
265
266 /// Quickly append one lookup set to another.
268 Symbols.reserve(Symbols.size() + Other.size());
269 for (auto &KV : Other)
270 Symbols.push_back(std::move(KV));
271 return *this;
272 }
273
274 bool empty() const { return Symbols.empty(); }
275 UnderlyingVector::size_type size() const { return Symbols.size(); }
276 iterator begin() { return Symbols.begin(); }
277 iterator end() { return Symbols.end(); }
278 const_iterator begin() const { return Symbols.begin(); }
279 const_iterator end() const { return Symbols.end(); }
280
281 /// Removes the Ith element of the vector, replacing it with the last element.
282 void remove(UnderlyingVector::size_type I) {
283 std::swap(Symbols[I], Symbols.back());
284 Symbols.pop_back();
285 }
286
287 /// Removes the element pointed to by the given iterator. This iterator and
288 /// all subsequent ones (including end()) are invalidated.
289 void remove(iterator I) { remove(I - begin()); }
290
291 /// Removes all elements matching the given predicate, which must be callable
292 /// as bool(const SymbolStringPtr &, SymbolLookupFlags Flags).
293 template <typename PredFn> void remove_if(PredFn &&Pred) {
294 UnderlyingVector::size_type I = 0;
295 while (I != Symbols.size()) {
296 const auto &Name = Symbols[I].first;
297 auto Flags = Symbols[I].second;
298 if (Pred(Name, Flags))
299 remove(I);
300 else
301 ++I;
302 }
303 }
304
305 /// Loop over the elements of this SymbolLookupSet, applying the Body function
306 /// to each one. Body must be callable as
307 /// bool(const SymbolStringPtr &, SymbolLookupFlags).
308 /// If Body returns true then the element just passed in is removed from the
309 /// set. If Body returns false then the element is retained.
310 template <typename BodyFn>
311 auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t<
312 std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
313 std::declval<SymbolLookupFlags>())),
314 bool>::value> {
315 UnderlyingVector::size_type I = 0;
316 while (I != Symbols.size()) {
317 const auto &Name = Symbols[I].first;
318 auto Flags = Symbols[I].second;
319 if (Body(Name, Flags))
320 remove(I);
321 else
322 ++I;
323 }
324 }
325
326 /// Loop over the elements of this SymbolLookupSet, applying the Body function
327 /// to each one. Body must be callable as
328 /// Expected<bool>(const SymbolStringPtr &, SymbolLookupFlags).
329 /// If Body returns a failure value, the loop exits immediately. If Body
330 /// returns true then the element just passed in is removed from the set. If
331 /// Body returns false then the element is retained.
332 template <typename BodyFn>
333 auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t<
334 std::is_same<decltype(Body(std::declval<const SymbolStringPtr &>(),
335 std::declval<SymbolLookupFlags>())),
337 Error> {
338 UnderlyingVector::size_type I = 0;
339 while (I != Symbols.size()) {
340 const auto &Name = Symbols[I].first;
341 auto Flags = Symbols[I].second;
342 auto Remove = Body(Name, Flags);
343 if (!Remove)
344 return Remove.takeError();
345 if (*Remove)
346 remove(I);
347 else
348 ++I;
349 }
350 return Error::success();
351 }
352
353 /// Construct a SymbolNameVector from this instance by dropping the Flags
354 /// values.
356 SymbolNameVector Names;
357 Names.reserve(Symbols.size());
358 for (const auto &KV : Symbols)
359 Names.push_back(KV.first);
360 return Names;
361 }
362
363 /// Sort the lookup set by pointer value. This sort is fast but sensitive to
364 /// allocation order and so should not be used where a consistent order is
365 /// required.
367
368 /// Sort the lookup set lexicographically. This sort is slow but the order
369 /// is unaffected by allocation order.
370 void sortByName() {
371 llvm::sort(Symbols, [](const value_type &LHS, const value_type &RHS) {
372 return *LHS.first < *RHS.first;
373 });
374 }
375
376 /// Remove any duplicate elements. If a SymbolLookupSet is not duplicate-free
377 /// by construction, this method can be used to turn it into a proper set.
380 auto LastI = llvm::unique(Symbols);
381 Symbols.erase(LastI, Symbols.end());
382 }
383
384#ifndef NDEBUG
385 /// Returns true if this set contains any duplicates. This should only be used
386 /// in assertions.
388 if (Symbols.size() < 2)
389 return false;
391 for (UnderlyingVector::size_type I = 1; I != Symbols.size(); ++I)
392 if (Symbols[I].first == Symbols[I - 1].first)
393 return true;
394 return false;
395 }
396#endif
397
398private:
399 UnderlyingVector Symbols;
400};
401
406
409};
410
411/// A map of Symbols to (Symbol, Flags) pairs.
413
414/// Callback to notify client that symbols have been resolved.
416
417/// Callback to register the dependencies for a given query.
419 std::function<void(const SymbolDependenceMap &)>;
420
421/// This can be used as the value for a RegisterDependenciesFunction if there
422/// are no dependants to register with.
424
425class ResourceTrackerDefunct : public ErrorInfo<ResourceTrackerDefunct> {
426public:
427 static char ID;
428
430 std::error_code convertToErrorCode() const override;
431 void log(raw_ostream &OS) const override;
432
433private:
435};
436
437/// Used to notify a JITDylib that the given set of symbols failed to
438/// materialize.
439class FailedToMaterialize : public ErrorInfo<FailedToMaterialize> {
440public:
441 static char ID;
442
443 FailedToMaterialize(std::shared_ptr<SymbolStringPool> SSP,
444 std::shared_ptr<SymbolDependenceMap> Symbols);
446 std::error_code convertToErrorCode() const override;
447 void log(raw_ostream &OS) const override;
448 const SymbolDependenceMap &getSymbols() const { return *Symbols; }
449
450private:
451 std::shared_ptr<SymbolStringPool> SSP;
452 std::shared_ptr<SymbolDependenceMap> Symbols;
453};
454
455/// Used to report failure due to unsatisfiable symbol dependencies.
457 : public ErrorInfo<UnsatisfiedSymbolDependencies> {
458public:
459 static char ID;
460
461 UnsatisfiedSymbolDependencies(std::shared_ptr<SymbolStringPool> SSP,
462 JITDylibSP JD, SymbolNameSet FailedSymbols,
463 SymbolDependenceMap BadDeps,
464 std::string Explanation);
465 std::error_code convertToErrorCode() const override;
466 void log(raw_ostream &OS) const override;
467
468private:
469 std::shared_ptr<SymbolStringPool> SSP;
470 JITDylibSP JD;
471 SymbolNameSet FailedSymbols;
472 SymbolDependenceMap BadDeps;
473 std::string Explanation;
474};
475
476/// Used to notify clients when symbols can not be found during a lookup.
477class SymbolsNotFound : public ErrorInfo<SymbolsNotFound> {
478public:
479 static char ID;
480
481 SymbolsNotFound(std::shared_ptr<SymbolStringPool> SSP, SymbolNameSet Symbols);
482 SymbolsNotFound(std::shared_ptr<SymbolStringPool> SSP,
483 SymbolNameVector Symbols);
484 std::error_code convertToErrorCode() const override;
485 void log(raw_ostream &OS) const override;
486 std::shared_ptr<SymbolStringPool> getSymbolStringPool() { return SSP; }
487 const SymbolNameVector &getSymbols() const { return Symbols; }
488
489private:
490 std::shared_ptr<SymbolStringPool> SSP;
491 SymbolNameVector Symbols;
492};
493
494/// Used to notify clients that a set of symbols could not be removed.
495class SymbolsCouldNotBeRemoved : public ErrorInfo<SymbolsCouldNotBeRemoved> {
496public:
497 static char ID;
498
499 SymbolsCouldNotBeRemoved(std::shared_ptr<SymbolStringPool> SSP,
500 SymbolNameSet Symbols);
501 std::error_code convertToErrorCode() const override;
502 void log(raw_ostream &OS) const override;
503 std::shared_ptr<SymbolStringPool> getSymbolStringPool() { return SSP; }
504 const SymbolNameSet &getSymbols() const { return Symbols; }
505
506private:
507 std::shared_ptr<SymbolStringPool> SSP;
508 SymbolNameSet Symbols;
509};
510
511/// Errors of this type should be returned if a module fails to include
512/// definitions that are claimed by the module's associated
513/// MaterializationResponsibility. If this error is returned it is indicative of
514/// a broken transformation / compiler / object cache.
515class MissingSymbolDefinitions : public ErrorInfo<MissingSymbolDefinitions> {
516public:
517 static char ID;
518
519 MissingSymbolDefinitions(std::shared_ptr<SymbolStringPool> SSP,
520 std::string ModuleName, SymbolNameVector Symbols)
521 : SSP(std::move(SSP)), ModuleName(std::move(ModuleName)),
522 Symbols(std::move(Symbols)) {}
523 std::error_code convertToErrorCode() const override;
524 void log(raw_ostream &OS) const override;
525 std::shared_ptr<SymbolStringPool> getSymbolStringPool() { return SSP; }
526 const std::string &getModuleName() const { return ModuleName; }
527 const SymbolNameVector &getSymbols() const { return Symbols; }
528private:
529 std::shared_ptr<SymbolStringPool> SSP;
530 std::string ModuleName;
531 SymbolNameVector Symbols;
532};
533
534/// Errors of this type should be returned if a module contains definitions for
535/// symbols that are not claimed by the module's associated
536/// MaterializationResponsibility. If this error is returned it is indicative of
537/// a broken transformation / compiler / object cache.
538class UnexpectedSymbolDefinitions : public ErrorInfo<UnexpectedSymbolDefinitions> {
539public:
540 static char ID;
541
542 UnexpectedSymbolDefinitions(std::shared_ptr<SymbolStringPool> SSP,
543 std::string ModuleName, SymbolNameVector Symbols)
544 : SSP(std::move(SSP)), ModuleName(std::move(ModuleName)),
545 Symbols(std::move(Symbols)) {}
546 std::error_code convertToErrorCode() const override;
547 void log(raw_ostream &OS) const override;
548 std::shared_ptr<SymbolStringPool> getSymbolStringPool() { return SSP; }
549 const std::string &getModuleName() const { return ModuleName; }
550 const SymbolNameVector &getSymbols() const { return Symbols; }
551private:
552 std::shared_ptr<SymbolStringPool> SSP;
553 std::string ModuleName;
554 SymbolNameVector Symbols;
555};
556
557/// A set of symbols and the their dependencies. Used to describe dependencies
558/// for the MaterializationResponsibility::notifyEmitted operation.
562};
563
564/// Tracks responsibility for materialization, and mediates interactions between
565/// MaterializationUnits and JDs.
566///
567/// An instance of this class is passed to MaterializationUnits when their
568/// materialize method is called. It allows MaterializationUnits to resolve and
569/// emit symbols, or abandon materialization by notifying any unmaterialized
570/// symbols of an error.
572 friend class ExecutionSession;
573 friend class JITDylib;
574
575public:
579
580 /// Destruct a MaterializationResponsibility instance. In debug mode
581 /// this asserts that all symbols being tracked have been either
582 /// emitted or notified of an error.
584
585 /// Return the ResourceTracker associated with this instance.
586 const ResourceTrackerSP &getResourceTracker() const { return RT; }
587
588 /// Runs the given callback under the session lock, passing in the associated
589 /// ResourceKey. This is the safe way to associate resources with trackers.
590 template <typename Func> Error withResourceKeyDo(Func &&F) const {
591 return RT->withResourceKeyDo(std::forward<Func>(F));
592 }
593
594 /// Returns the target JITDylib that these symbols are being materialized
595 /// into.
596 JITDylib &getTargetJITDylib() const { return JD; }
597
598 /// Returns the ExecutionSession for this instance.
600
601 /// Returns the symbol flags map for this responsibility instance.
602 /// Note: The returned flags may have transient flags (Lazy, Materializing)
603 /// set. These should be stripped with JITSymbolFlags::stripTransientFlags
604 /// before using.
605 const SymbolFlagsMap &getSymbols() const { return SymbolFlags; }
606
607 /// Returns the initialization pseudo-symbol, if any. This symbol will also
608 /// be present in the SymbolFlagsMap for this MaterializationResponsibility
609 /// object.
610 const SymbolStringPtr &getInitializerSymbol() const { return InitSymbol; }
611
612 /// Returns the names of any symbols covered by this
613 /// MaterializationResponsibility object that have queries pending. This
614 /// information can be used to return responsibility for unrequested symbols
615 /// back to the JITDylib via the delegate method.
617
618 /// Notifies the target JITDylib that the given symbols have been resolved.
619 /// This will update the given symbols' addresses in the JITDylib, and notify
620 /// any pending queries on the given symbols of their resolution. The given
621 /// symbols must be ones covered by this MaterializationResponsibility
622 /// instance. Individual calls to this method may resolve a subset of the
623 /// symbols, but all symbols must have been resolved prior to calling emit.
624 ///
625 /// This method will return an error if any symbols being resolved have been
626 /// moved to the error state due to the failure of a dependency. If this
627 /// method returns an error then clients should log it and call
628 /// failMaterialize. If no dependencies have been registered for the
629 /// symbols covered by this MaterializationResponsibility then this method
630 /// is guaranteed to return Error::success() and can be wrapped with cantFail.
631 Error notifyResolved(const SymbolMap &Symbols);
632
633 /// Notifies the target JITDylib (and any pending queries on that JITDylib)
634 /// that all symbols covered by this MaterializationResponsibility instance
635 /// have been emitted.
636 ///
637 /// The DepGroups array describes the dependencies of symbols being emitted on
638 /// symbols that are outside this MaterializationResponsibility object. Each
639 /// group consists of a pair of a set of symbols and a SymbolDependenceMap
640 /// that describes the dependencies for the symbols in the first set. The
641 /// elements of DepGroups must be non-overlapping (no symbol should appear in
642 /// more than one of hte symbol sets), but do not have to be exhaustive. Any
643 /// symbol in this MaterializationResponsibility object that is not covered
644 /// by an entry will be treated as having no dependencies.
645 ///
646 /// This method will return an error if any symbols being resolved have been
647 /// moved to the error state due to the failure of a dependency. If this
648 /// method returns an error then clients should log it and call
649 /// failMaterialize. If no dependencies have been registered for the
650 /// symbols covered by this MaterializationResponsibility then this method
651 /// is guaranteed to return Error::success() and can be wrapped with cantFail.
653
654 /// Attempt to claim responsibility for new definitions. This method can be
655 /// used to claim responsibility for symbols that are added to a
656 /// materialization unit during the compilation process (e.g. literal pool
657 /// symbols). Symbol linkage rules are the same as for symbols that are
658 /// defined up front: duplicate strong definitions will result in errors.
659 /// Duplicate weak definitions will be discarded (in which case they will
660 /// not be added to this responsibility instance).
661 ///
662 /// This method can be used by materialization units that want to add
663 /// additional symbols at materialization time (e.g. stubs, compile
664 /// callbacks, metadata).
666
667 /// Notify all not-yet-emitted covered by this MaterializationResponsibility
668 /// instance that an error has occurred.
669 /// This will remove all symbols covered by this MaterializationResponsibility
670 /// from the target JITDylib, and send an error to any queries waiting on
671 /// these symbols.
672 void failMaterialization();
673
674 /// Transfers responsibility to the given MaterializationUnit for all
675 /// symbols defined by that MaterializationUnit. This allows
676 /// materializers to break up work based on run-time information (e.g.
677 /// by introspecting which symbols have actually been looked up and
678 /// materializing only those).
679 Error replace(std::unique_ptr<MaterializationUnit> MU);
680
681 /// Delegates responsibility for the given symbols to the returned
682 /// materialization responsibility. Useful for breaking up work between
683 /// threads, or different kinds of materialization processes.
685 delegate(const SymbolNameSet &Symbols);
686
687private:
688 /// Create a MaterializationResponsibility for the given JITDylib and
689 /// initial symbols.
691 SymbolFlagsMap SymbolFlags,
692 SymbolStringPtr InitSymbol)
693 : JD(RT->getJITDylib()), RT(std::move(RT)),
694 SymbolFlags(std::move(SymbolFlags)), InitSymbol(std::move(InitSymbol)) {
695 assert(!this->SymbolFlags.empty() && "Materializing nothing?");
696 }
697
698 JITDylib &JD;
700 SymbolFlagsMap SymbolFlags;
701 SymbolStringPtr InitSymbol;
702};
703
704/// A materialization unit for symbol aliases. Allows existing symbols to be
705/// aliased with alternate flags.
707public:
708 /// SourceJD is allowed to be nullptr, in which case the source JITDylib is
709 /// taken to be whatever JITDylib these definitions are materialized in (and
710 /// MatchNonExported has no effect). This is useful for defining aliases
711 /// within a JITDylib.
712 ///
713 /// Note: Care must be taken that no sets of aliases form a cycle, as such
714 /// a cycle will result in a deadlock when any symbol in the cycle is
715 /// resolved.
717 JITDylibLookupFlags SourceJDLookupFlags,
718 SymbolAliasMap Aliases);
719
720 StringRef getName() const override;
721
722private:
723 void materialize(std::unique_ptr<MaterializationResponsibility> R) override;
724 void discard(const JITDylib &JD, const SymbolStringPtr &Name) override;
726 extractFlags(const SymbolAliasMap &Aliases);
727
728 JITDylib *SourceJD = nullptr;
729 JITDylibLookupFlags SourceJDLookupFlags;
730 SymbolAliasMap Aliases;
731};
732
733/// Create a ReExportsMaterializationUnit with the given aliases.
734/// Useful for defining symbol aliases.: E.g., given a JITDylib JD containing
735/// symbols "foo" and "bar", we can define aliases "baz" (for "foo") and "qux"
736/// (for "bar") with: \code{.cpp}
737/// SymbolStringPtr Baz = ...;
738/// SymbolStringPtr Qux = ...;
739/// if (auto Err = JD.define(symbolAliases({
740/// {Baz, { Foo, JITSymbolFlags::Exported }},
741/// {Qux, { Bar, JITSymbolFlags::Weak }}}))
742/// return Err;
743/// \endcode
744inline std::unique_ptr<ReExportsMaterializationUnit>
746 return std::make_unique<ReExportsMaterializationUnit>(
747 nullptr, JITDylibLookupFlags::MatchAllSymbols, std::move(Aliases));
748}
749
750/// Create a materialization unit for re-exporting symbols from another JITDylib
751/// with alternative names/flags.
752/// SourceJD will be searched using the given JITDylibLookupFlags.
753inline std::unique_ptr<ReExportsMaterializationUnit>
755 JITDylibLookupFlags SourceJDLookupFlags =
757 return std::make_unique<ReExportsMaterializationUnit>(
758 &SourceJD, SourceJDLookupFlags, std::move(Aliases));
759}
760
761/// Build a SymbolAliasMap for the common case where you want to re-export
762/// symbols from another JITDylib with the same linkage/flags.
765
766/// Represents the state that a symbol has reached during materialization.
767enum class SymbolState : uint8_t {
768 Invalid, /// No symbol should be in this state.
769 NeverSearched, /// Added to the symbol table, never queried.
770 Materializing, /// Queried, materialization begun.
771 Resolved, /// Assigned address, still materializing.
772 Emitted, /// Emitted to memory, but waiting on transitive dependencies.
773 Ready = 0x3f /// Ready and safe for clients to access.
774};
775
776/// A symbol query that returns results via a callback when results are
777/// ready.
778///
779/// makes a callback when all symbols are available.
781 friend class ExecutionSession;
783 friend class JITDylib;
786
787public:
788 /// Create a query for the given symbols. The NotifyComplete
789 /// callback will be called once all queried symbols reach the given
790 /// minimum state.
792 SymbolState RequiredState,
793 SymbolsResolvedCallback NotifyComplete);
794
795 /// Notify the query that a requested symbol has reached the required state.
798
799 /// Returns true if all symbols covered by this query have been
800 /// resolved.
801 bool isComplete() const { return OutstandingSymbolsCount == 0; }
802
803
804private:
805 void handleComplete(ExecutionSession &ES);
806
807 SymbolState getRequiredState() { return RequiredState; }
808
809 void addQueryDependence(JITDylib &JD, SymbolStringPtr Name);
810
811 void removeQueryDependence(JITDylib &JD, const SymbolStringPtr &Name);
812
813 void dropSymbol(const SymbolStringPtr &Name);
814
815 void handleFailed(Error Err);
816
817 void detach();
818
819 SymbolsResolvedCallback NotifyComplete;
820 SymbolDependenceMap QueryRegistrations;
821 SymbolMap ResolvedSymbols;
822 size_t OutstandingSymbolsCount;
823 SymbolState RequiredState;
824};
825
826/// Wraps state for a lookup-in-progress.
827/// DefinitionGenerators can optionally take ownership of a LookupState object
828/// to suspend a lookup-in-progress while they search for definitions.
830 friend class OrcV2CAPIHelper;
831 friend class ExecutionSession;
832
833public:
838
839 /// Continue the lookup. This can be called by DefinitionGenerators
840 /// to re-start a captured query-application operation.
841 void continueLookup(Error Err);
842
843private:
844 LookupState(std::unique_ptr<InProgressLookupState> IPLS);
845
846 // For C API.
847 void reset(InProgressLookupState *IPLS);
848
849 std::unique_ptr<InProgressLookupState> IPLS;
850};
851
852/// Definition generators can be attached to JITDylibs to generate new
853/// definitions for otherwise unresolved symbols during lookup.
855 friend class ExecutionSession;
856
857public:
858 virtual ~DefinitionGenerator();
859
860 /// DefinitionGenerators should override this method to insert new
861 /// definitions into the parent JITDylib. K specifies the kind of this
862 /// lookup. JD specifies the target JITDylib being searched, and
863 /// JDLookupFlags specifies whether the search should match against
864 /// hidden symbols. Finally, Symbols describes the set of unresolved
865 /// symbols and their associated lookup flags.
867 JITDylibLookupFlags JDLookupFlags,
868 const SymbolLookupSet &LookupSet) = 0;
869
870private:
871 std::mutex M;
872 bool InUse = false;
873 std::deque<LookupState> PendingLookups;
874};
875
876/// Represents a JIT'd dynamic library.
877///
878/// This class aims to mimic the behavior of a regular dylib or shared object,
879/// but without requiring the contained program representations to be compiled
880/// up-front. The JITDylib's content is defined by adding MaterializationUnits,
881/// and contained MaterializationUnits will typically rely on the JITDylib's
882/// links-against order to resolve external references (similar to a regular
883/// dylib).
884///
885/// The JITDylib object is a thin wrapper that references state held by the
886/// ExecutionSession. JITDylibs can be removed, clearing this underlying state
887/// and leaving the JITDylib object in a defunct state. In this state the
888/// JITDylib's name is guaranteed to remain accessible. If the ExecutionSession
889/// is still alive then other operations are callable but will return an Error
890/// or null result (depending on the API). It is illegal to call any operation
891/// other than getName on a JITDylib after the ExecutionSession has been torn
892/// down.
893///
894/// JITDylibs cannot be moved or copied. Their address is stable, and useful as
895/// a key in some JIT data structures.
896class JITDylib : public ThreadSafeRefCountedBase<JITDylib>,
897 public jitlink::JITLinkDylib {
899 friend class ExecutionSession;
900 friend class Platform;
902public:
903
904 JITDylib(const JITDylib &) = delete;
905 JITDylib &operator=(const JITDylib &) = delete;
906 JITDylib(JITDylib &&) = delete;
908 ~JITDylib();
909
910 /// Get a reference to the ExecutionSession for this JITDylib.
911 ///
912 /// It is legal to call this method on a defunct JITDylib, however the result
913 /// will only usable if the ExecutionSession is still alive. If this JITDylib
914 /// is held by an error that may have torn down the JIT then the result
915 /// should not be used.
916 ExecutionSession &getExecutionSession() const { return ES; }
917
918 /// Dump current JITDylib state to OS.
919 ///
920 /// It is legal to call this method on a defunct JITDylib.
921 void dump(raw_ostream &OS);
922
923 /// Calls remove on all trackers currently associated with this JITDylib.
924 /// Does not run static deinits.
925 ///
926 /// Note that removal happens outside the session lock, so new code may be
927 /// added concurrently while the clear is underway, and the newly added
928 /// code will *not* be cleared. Adding new code concurrently with a clear
929 /// is usually a bug and should be avoided.
930 ///
931 /// It is illegal to call this method on a defunct JITDylib and the client
932 /// is responsible for ensuring that they do not do so.
933 Error clear();
934
935 /// Get the default resource tracker for this JITDylib.
936 ///
937 /// It is illegal to call this method on a defunct JITDylib and the client
938 /// is responsible for ensuring that they do not do so.
940
941 /// Create a resource tracker for this JITDylib.
942 ///
943 /// It is illegal to call this method on a defunct JITDylib and the client
944 /// is responsible for ensuring that they do not do so.
946
947 /// Adds a definition generator to this JITDylib and returns a referenece to
948 /// it.
949 ///
950 /// When JITDylibs are searched during lookup, if no existing definition of
951 /// a symbol is found, then any generators that have been added are run (in
952 /// the order that they were added) to potentially generate a definition.
953 ///
954 /// It is illegal to call this method on a defunct JITDylib and the client
955 /// is responsible for ensuring that they do not do so.
956 template <typename GeneratorT>
957 GeneratorT &addGenerator(std::unique_ptr<GeneratorT> DefGenerator);
958
959 /// Remove a definition generator from this JITDylib.
960 ///
961 /// The given generator must exist in this JITDylib's generators list (i.e.
962 /// have been added and not yet removed).
963 ///
964 /// It is illegal to call this method on a defunct JITDylib and the client
965 /// is responsible for ensuring that they do not do so.
967
968 /// Set the link order to be used when fixing up definitions in JITDylib.
969 /// This will replace the previous link order, and apply to any symbol
970 /// resolutions made for definitions in this JITDylib after the call to
971 /// setLinkOrder (even if the definition itself was added before the
972 /// call).
973 ///
974 /// If LinkAgainstThisJITDylibFirst is true (the default) then this JITDylib
975 /// will add itself to the beginning of the LinkOrder (Clients should not
976 /// put this JITDylib in the list in this case, to avoid redundant lookups).
977 ///
978 /// If LinkAgainstThisJITDylibFirst is false then the link order will be used
979 /// as-is. The primary motivation for this feature is to support deliberate
980 /// shadowing of symbols in this JITDylib by a facade JITDylib. For example,
981 /// the facade may resolve function names to stubs, and the stubs may compile
982 /// lazily by looking up symbols in this dylib. Adding the facade dylib
983 /// as the first in the link order (instead of this dylib) ensures that
984 /// definitions within this dylib resolve to the lazy-compiling stubs,
985 /// rather than immediately materializing the definitions in this dylib.
986 ///
987 /// It is illegal to call this method on a defunct JITDylib and the client
988 /// is responsible for ensuring that they do not do so.
989 void setLinkOrder(JITDylibSearchOrder NewSearchOrder,
990 bool LinkAgainstThisJITDylibFirst = true);
991
992 /// Append the given JITDylibSearchOrder to the link order for this
993 /// JITDylib (discarding any elements already present in this JITDylib's
994 /// link order).
995 void addToLinkOrder(const JITDylibSearchOrder &NewLinks);
996
997 /// Add the given JITDylib to the link order for definitions in this
998 /// JITDylib.
999 ///
1000 /// It is illegal to call this method on a defunct JITDylib and the client
1001 /// is responsible for ensuring that they do not do so.
1002 void addToLinkOrder(JITDylib &JD,
1003 JITDylibLookupFlags JDLookupFlags =
1005
1006 /// Replace OldJD with NewJD in the link order if OldJD is present.
1007 /// Otherwise this operation is a no-op.
1008 ///
1009 /// It is illegal to call this method on a defunct JITDylib and the client
1010 /// is responsible for ensuring that they do not do so.
1011 void replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD,
1012 JITDylibLookupFlags JDLookupFlags =
1014
1015 /// Remove the given JITDylib from the link order for this JITDylib if it is
1016 /// present. Otherwise this operation is a no-op.
1017 ///
1018 /// It is illegal to call this method on a defunct JITDylib and the client
1019 /// is responsible for ensuring that they do not do so.
1020 void removeFromLinkOrder(JITDylib &JD);
1021
1022 /// Do something with the link order (run under the session lock).
1023 ///
1024 /// It is illegal to call this method on a defunct JITDylib and the client
1025 /// is responsible for ensuring that they do not do so.
1026 template <typename Func>
1027 auto withLinkOrderDo(Func &&F)
1028 -> decltype(F(std::declval<const JITDylibSearchOrder &>()));
1029
1030 /// Define all symbols provided by the materialization unit to be part of this
1031 /// JITDylib.
1032 ///
1033 /// If RT is not specified then the default resource tracker will be used.
1034 ///
1035 /// This overload always takes ownership of the MaterializationUnit. If any
1036 /// errors occur, the MaterializationUnit consumed.
1037 ///
1038 /// It is illegal to call this method on a defunct JITDylib and the client
1039 /// is responsible for ensuring that they do not do so.
1040 template <typename MaterializationUnitType>
1041 Error define(std::unique_ptr<MaterializationUnitType> &&MU,
1042 ResourceTrackerSP RT = nullptr);
1043
1044 /// Define all symbols provided by the materialization unit to be part of this
1045 /// JITDylib.
1046 ///
1047 /// This overload only takes ownership of the MaterializationUnit no error is
1048 /// generated. If an error occurs, ownership remains with the caller. This
1049 /// may allow the caller to modify the MaterializationUnit to correct the
1050 /// issue, then re-call define.
1051 ///
1052 /// It is illegal to call this method on a defunct JITDylib and the client
1053 /// is responsible for ensuring that they do not do so.
1054 template <typename MaterializationUnitType>
1055 Error define(std::unique_ptr<MaterializationUnitType> &MU,
1056 ResourceTrackerSP RT = nullptr);
1057
1058 /// Tries to remove the given symbols.
1059 ///
1060 /// If any symbols are not defined in this JITDylib this method will return
1061 /// a SymbolsNotFound error covering the missing symbols.
1062 ///
1063 /// If all symbols are found but some symbols are in the process of being
1064 /// materialized this method will return a SymbolsCouldNotBeRemoved error.
1065 ///
1066 /// On success, all symbols are removed. On failure, the JITDylib state is
1067 /// left unmodified (no symbols are removed).
1068 ///
1069 /// It is illegal to call this method on a defunct JITDylib and the client
1070 /// is responsible for ensuring that they do not do so.
1071 Error remove(const SymbolNameSet &Names);
1072
1073 /// Returns the given JITDylibs and all of their transitive dependencies in
1074 /// DFS order (based on linkage relationships). Each JITDylib will appear
1075 /// only once.
1076 ///
1077 /// If any JITDylib in the order is defunct then this method will return an
1078 /// error, otherwise returns the order.
1081
1082 /// Returns the given JITDylibs and all of their transitive dependencies in
1083 /// reverse DFS order (based on linkage relationships). Each JITDylib will
1084 /// appear only once.
1085 ///
1086 /// If any JITDylib in the order is defunct then this method will return an
1087 /// error, otherwise returns the order.
1090
1091 /// Return this JITDylib and its transitive dependencies in DFS order
1092 /// based on linkage relationships.
1093 ///
1094 /// If any JITDylib in the order is defunct then this method will return an
1095 /// error, otherwise returns the order.
1097
1098 /// Rteurn this JITDylib and its transitive dependencies in reverse DFS order
1099 /// based on linkage relationships.
1100 ///
1101 /// If any JITDylib in the order is defunct then this method will return an
1102 /// error, otherwise returns the order.
1104
1105private:
1106 using AsynchronousSymbolQuerySet =
1107 std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
1108
1109 using AsynchronousSymbolQueryList =
1110 std::vector<std::shared_ptr<AsynchronousSymbolQuery>>;
1111
1112 struct UnmaterializedInfo {
1113 UnmaterializedInfo(std::unique_ptr<MaterializationUnit> MU,
1114 ResourceTracker *RT)
1115 : MU(std::move(MU)), RT(RT) {}
1116
1117 std::unique_ptr<MaterializationUnit> MU;
1118 ResourceTracker *RT;
1119 };
1120
1121 using UnmaterializedInfosMap =
1122 DenseMap<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
1123
1124 using UnmaterializedInfosList =
1125 std::vector<std::shared_ptr<UnmaterializedInfo>>;
1126
1127 struct EmissionDepUnit {
1128 EmissionDepUnit(JITDylib &JD) : JD(&JD) {}
1129
1130 JITDylib *JD = nullptr;
1131 DenseMap<NonOwningSymbolStringPtr, JITSymbolFlags> Symbols;
1132 DenseMap<JITDylib *, DenseSet<NonOwningSymbolStringPtr>> Dependencies;
1133 };
1134
1135 struct EmissionDepUnitInfo {
1136 std::shared_ptr<EmissionDepUnit> EDU;
1137 DenseSet<EmissionDepUnit *> IntraEmitUsers;
1138 DenseMap<JITDylib *, DenseSet<NonOwningSymbolStringPtr>> NewDeps;
1139 };
1140
1141 // Information about not-yet-ready symbol.
1142 // * DefiningEDU will point to the EmissionDepUnit that defines the symbol.
1143 // * DependantEDUs will hold pointers to any EmissionDepUnits currently
1144 // waiting on this symbol.
1145 // * Pending queries holds any not-yet-completed queries that include this
1146 // symbol.
1147 struct MaterializingInfo {
1148 friend class ExecutionSession;
1149
1150 std::shared_ptr<EmissionDepUnit> DefiningEDU;
1151 DenseSet<EmissionDepUnit *> DependantEDUs;
1152
1153 void addQuery(std::shared_ptr<AsynchronousSymbolQuery> Q);
1154 void removeQuery(const AsynchronousSymbolQuery &Q);
1155 AsynchronousSymbolQueryList takeQueriesMeeting(SymbolState RequiredState);
1156 AsynchronousSymbolQueryList takeAllPendingQueries() {
1157 return std::move(PendingQueries);
1158 }
1159 bool hasQueriesPending() const { return !PendingQueries.empty(); }
1160 const AsynchronousSymbolQueryList &pendingQueries() const {
1161 return PendingQueries;
1162 }
1163 private:
1164 AsynchronousSymbolQueryList PendingQueries;
1165 };
1166
1167 using MaterializingInfosMap = DenseMap<SymbolStringPtr, MaterializingInfo>;
1168
1169 class SymbolTableEntry {
1170 public:
1171 SymbolTableEntry() = default;
1172 SymbolTableEntry(JITSymbolFlags Flags)
1173 : Flags(Flags), State(static_cast<uint8_t>(SymbolState::NeverSearched)),
1174 MaterializerAttached(false) {}
1175
1176 ExecutorAddr getAddress() const { return Addr; }
1177 JITSymbolFlags getFlags() const { return Flags; }
1178 SymbolState getState() const { return static_cast<SymbolState>(State); }
1179
1180 bool hasMaterializerAttached() const { return MaterializerAttached; }
1181
1182 void setAddress(ExecutorAddr Addr) { this->Addr = Addr; }
1183 void setFlags(JITSymbolFlags Flags) { this->Flags = Flags; }
1184 void setState(SymbolState State) {
1185 assert(static_cast<uint8_t>(State) < (1 << 6) &&
1186 "State does not fit in bitfield");
1187 this->State = static_cast<uint8_t>(State);
1188 }
1189
1190 void setMaterializerAttached(bool MaterializerAttached) {
1191 this->MaterializerAttached = MaterializerAttached;
1192 }
1193
1194 ExecutorSymbolDef getSymbol() const { return {Addr, Flags}; }
1195
1196 private:
1197 ExecutorAddr Addr;
1198 JITSymbolFlags Flags;
1199 uint8_t State : 7;
1200 uint8_t MaterializerAttached : 1;
1201 };
1202
1203 using SymbolTable = DenseMap<SymbolStringPtr, SymbolTableEntry>;
1204
1205 JITDylib(ExecutionSession &ES, std::string Name);
1206
1207 std::pair<AsynchronousSymbolQuerySet, std::shared_ptr<SymbolDependenceMap>>
1208 IL_removeTracker(ResourceTracker &RT);
1209
1210 void transferTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT);
1211
1212 Error defineImpl(MaterializationUnit &MU);
1213
1214 void installMaterializationUnit(std::unique_ptr<MaterializationUnit> MU,
1215 ResourceTracker &RT);
1216
1217 void detachQueryHelper(AsynchronousSymbolQuery &Q,
1218 const SymbolNameSet &QuerySymbols);
1219
1220 void transferEmittedNodeDependencies(MaterializingInfo &DependantMI,
1221 const SymbolStringPtr &DependantName,
1222 MaterializingInfo &EmittedMI);
1223
1224 Expected<SymbolFlagsMap>
1225 defineMaterializing(MaterializationResponsibility &FromMR,
1226 SymbolFlagsMap SymbolFlags);
1227
1228 Error replace(MaterializationResponsibility &FromMR,
1229 std::unique_ptr<MaterializationUnit> MU);
1230
1231 Expected<std::unique_ptr<MaterializationResponsibility>>
1232 delegate(MaterializationResponsibility &FromMR, SymbolFlagsMap SymbolFlags,
1233 SymbolStringPtr InitSymbol);
1234
1235 SymbolNameSet getRequestedSymbols(const SymbolFlagsMap &SymbolFlags) const;
1236
1237 void addDependencies(const SymbolStringPtr &Name,
1238 const SymbolDependenceMap &Dependants);
1239
1241
1242 void unlinkMaterializationResponsibility(MaterializationResponsibility &MR);
1243
1244 /// Attempt to reduce memory usage from empty \c UnmaterializedInfos and
1245 /// \c MaterializingInfos tables.
1246 void shrinkMaterializationInfoMemory();
1247
1248 ExecutionSession &ES;
1249 enum { Open, Closing, Closed } State = Open;
1250 std::mutex GeneratorsMutex;
1251 SymbolTable Symbols;
1252 UnmaterializedInfosMap UnmaterializedInfos;
1253 MaterializingInfosMap MaterializingInfos;
1254 std::vector<std::shared_ptr<DefinitionGenerator>> DefGenerators;
1255 JITDylibSearchOrder LinkOrder;
1256 ResourceTrackerSP DefaultTracker;
1257
1258 // Map trackers to sets of symbols tracked.
1259 DenseMap<ResourceTracker *, SymbolNameVector> TrackerSymbols;
1260 DenseMap<ResourceTracker *, DenseSet<MaterializationResponsibility *>>
1261 TrackerMRs;
1262};
1263
1264/// Platforms set up standard symbols and mediate interactions between dynamic
1265/// initializers (e.g. C++ static constructors) and ExecutionSession state.
1266/// Note that Platforms do not automatically run initializers: clients are still
1267/// responsible for doing this.
1269public:
1270 virtual ~Platform();
1271
1272 /// This method will be called outside the session lock each time a JITDylib
1273 /// is created (unless it is created with EmptyJITDylib set) to allow the
1274 /// Platform to install any JITDylib specific standard symbols (e.g
1275 /// __dso_handle).
1276 virtual Error setupJITDylib(JITDylib &JD) = 0;
1277
1278 /// This method will be called outside the session lock each time a JITDylib
1279 /// is removed to allow the Platform to remove any JITDylib-specific data.
1281
1282 /// This method will be called under the ExecutionSession lock each time a
1283 /// MaterializationUnit is added to a JITDylib.
1285 const MaterializationUnit &MU) = 0;
1286
1287 /// This method will be called under the ExecutionSession lock when a
1288 /// ResourceTracker is removed.
1290
1291 /// A utility function for looking up initializer symbols. Performs a blocking
1292 /// lookup for the given symbols in each of the given JITDylibs.
1293 ///
1294 /// Note: This function is deprecated and will be removed in the near future.
1298
1299 /// Performs an async lookup for the given symbols in each of the given
1300 /// JITDylibs, calling the given handler once all lookups have completed.
1301 static void
1303 ExecutionSession &ES,
1305};
1306
1307/// A materialization task.
1308class MaterializationTask : public RTTIExtends<MaterializationTask, Task> {
1309public:
1310 static char ID;
1311
1312 MaterializationTask(std::unique_ptr<MaterializationUnit> MU,
1313 std::unique_ptr<MaterializationResponsibility> MR)
1314 : MU(std::move(MU)), MR(std::move(MR)) {}
1315 void printDescription(raw_ostream &OS) override;
1316 void run() override;
1317
1318private:
1319 std::unique_ptr<MaterializationUnit> MU;
1320 std::unique_ptr<MaterializationResponsibility> MR;
1321};
1322
1323/// Lookups are usually run on the current thread, but in some cases they may
1324/// be run as tasks, e.g. if the lookup has been continued from a suspended
1325/// state.
1326class LookupTask : public RTTIExtends<LookupTask, Task> {
1327public:
1328 static char ID;
1329
1330 LookupTask(LookupState LS) : LS(std::move(LS)) {}
1331 void printDescription(raw_ostream &OS) override;
1332 void run() override;
1333
1334private:
1335 LookupState LS;
1336};
1337
1338/// An ExecutionSession represents a running JIT program.
1342 friend class JITDylib;
1343 friend class LookupState;
1345 friend class ResourceTracker;
1346
1347public:
1348 /// For reporting errors.
1350
1351 /// Send a result to the remote.
1353
1354 /// An asynchronous wrapper-function callable from the executor via
1355 /// jit-dispatch.
1357 SendResultFunction SendResult,
1358 const char *ArgData, size_t ArgSize)>;
1359
1360 /// A map associating tag names with asynchronous wrapper function
1361 /// implementations in the JIT.
1364
1365 /// Construct an ExecutionSession with the given ExecutorProcessControl
1366 /// object.
1367 ExecutionSession(std::unique_ptr<ExecutorProcessControl> EPC);
1368
1369 /// Destroy an ExecutionSession. Verifies that endSession was called prior to
1370 /// destruction.
1372
1373 /// End the session. Closes all JITDylibs and disconnects from the
1374 /// executor. Clients must call this method before destroying the session.
1375 Error endSession();
1376
1377 /// Get the ExecutorProcessControl object associated with this
1378 /// ExecutionSession.
1380
1381 /// Return the triple for the executor.
1382 const Triple &getTargetTriple() const { return EPC->getTargetTriple(); }
1383
1384 // Return the page size for the executor.
1385 size_t getPageSize() const { return EPC->getPageSize(); }
1386
1387 /// Get the SymbolStringPool for this instance.
1388 std::shared_ptr<SymbolStringPool> getSymbolStringPool() {
1389 return EPC->getSymbolStringPool();
1390 }
1391
1392 /// Add a symbol name to the SymbolStringPool and return a pointer to it.
1393 SymbolStringPtr intern(StringRef SymName) { return EPC->intern(SymName); }
1394
1395 /// Set the Platform for this ExecutionSession.
1396 void setPlatform(std::unique_ptr<Platform> P) { this->P = std::move(P); }
1397
1398 /// Get the Platform for this session.
1399 /// Will return null if no Platform has been set for this ExecutionSession.
1400 Platform *getPlatform() { return P.get(); }
1401
1402 /// Run the given lambda with the session mutex locked.
1403 template <typename Func> decltype(auto) runSessionLocked(Func &&F) {
1404 std::lock_guard<std::recursive_mutex> Lock(SessionMutex);
1405 return F();
1406 }
1407
1408 /// Register the given ResourceManager with this ExecutionSession.
1409 /// Managers will be notified of events in reverse order of registration.
1411
1412 /// Deregister the given ResourceManager with this ExecutionSession.
1413 /// Manager must have been previously registered.
1415
1416 /// Return a pointer to the "name" JITDylib.
1417 /// Ownership of JITDylib remains within Execution Session
1419
1420 /// Add a new bare JITDylib to this ExecutionSession.
1421 ///
1422 /// The JITDylib Name is required to be unique. Clients should verify that
1423 /// names are not being re-used (E.g. by calling getJITDylibByName) if names
1424 /// are based on user input.
1425 ///
1426 /// This call does not install any library code or symbols into the newly
1427 /// created JITDylib. The client is responsible for all configuration.
1428 JITDylib &createBareJITDylib(std::string Name);
1429
1430 /// Add a new JITDylib to this ExecutionSession.
1431 ///
1432 /// The JITDylib Name is required to be unique. Clients should verify that
1433 /// names are not being re-used (e.g. by calling getJITDylibByName) if names
1434 /// are based on user input.
1435 ///
1436 /// If a Platform is attached then Platform::setupJITDylib will be called to
1437 /// install standard platform symbols (e.g. standard library interposes).
1438 /// If no Platform is attached this call is equivalent to createBareJITDylib.
1440
1441 /// Removes the given JITDylibs from the ExecutionSession.
1442 ///
1443 /// This method clears all resources held for the JITDylibs, puts them in the
1444 /// closed state, and clears all references to them that are held by the
1445 /// ExecutionSession or other JITDylibs. No further code can be added to the
1446 /// removed JITDylibs, and the JITDylib objects will be freed once any
1447 /// remaining JITDylibSPs pointing to them are destroyed.
1448 ///
1449 /// This method does *not* run static destructors for code contained in the
1450 /// JITDylibs, and each JITDylib can only be removed once.
1451 ///
1452 /// JITDylibs will be removed in the order given. Teardown is usually
1453 /// independent for each JITDylib, but not always. In particular, where the
1454 /// ORC runtime is used it is expected that teardown off all JITDylibs will
1455 /// depend on it, so the JITDylib containing the ORC runtime must be removed
1456 /// last. If the client has introduced any other dependencies they should be
1457 /// accounted for in the removal order too.
1458 Error removeJITDylibs(std::vector<JITDylibSP> JDsToRemove);
1459
1460 /// Calls removeJTIDylibs on the gives JITDylib.
1462 return removeJITDylibs(std::vector<JITDylibSP>({&JD}));
1463 }
1464
1465 /// Set the error reporter function.
1467 this->ReportError = std::move(ReportError);
1468 return *this;
1469 }
1470
1471 /// Report a error for this execution session.
1472 ///
1473 /// Unhandled errors can be sent here to log them.
1474 void reportError(Error Err) { ReportError(std::move(Err)); }
1475
1476 /// Search the given JITDylibs to find the flags associated with each of the
1477 /// given symbols.
1478 void lookupFlags(LookupKind K, JITDylibSearchOrder SearchOrder,
1479 SymbolLookupSet Symbols,
1480 unique_function<void(Expected<SymbolFlagsMap>)> OnComplete);
1481
1482 /// Blocking version of lookupFlags.
1484 JITDylibSearchOrder SearchOrder,
1485 SymbolLookupSet Symbols);
1486
1487 /// Search the given JITDylibs for the given symbols.
1488 ///
1489 /// SearchOrder lists the JITDylibs to search. For each dylib, the associated
1490 /// boolean indicates whether the search should match against non-exported
1491 /// (hidden visibility) symbols in that dylib (true means match against
1492 /// non-exported symbols, false means do not match).
1493 ///
1494 /// The NotifyComplete callback will be called once all requested symbols
1495 /// reach the required state.
1496 ///
1497 /// If all symbols are found, the RegisterDependencies function will be called
1498 /// while the session lock is held. This gives clients a chance to register
1499 /// dependencies for on the queried symbols for any symbols they are
1500 /// materializing (if a MaterializationResponsibility instance is present,
1501 /// this can be implemented by calling
1502 /// MaterializationResponsibility::addDependencies). If there are no
1503 /// dependenant symbols for this query (e.g. it is being made by a top level
1504 /// client to get an address to call) then the value NoDependenciesToRegister
1505 /// can be used.
1506 void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder,
1507 SymbolLookupSet Symbols, SymbolState RequiredState,
1508 SymbolsResolvedCallback NotifyComplete,
1509 RegisterDependenciesFunction RegisterDependencies);
1510
1511 /// Blocking version of lookup above. Returns the resolved symbol map.
1512 /// If WaitUntilReady is true (the default), will not return until all
1513 /// requested symbols are ready (or an error occurs). If WaitUntilReady is
1514 /// false, will return as soon as all requested symbols are resolved,
1515 /// or an error occurs. If WaitUntilReady is false and an error occurs
1516 /// after resolution, the function will return a success value, but the
1517 /// error will be reported via reportErrors.
1519 SymbolLookupSet Symbols,
1521 SymbolState RequiredState = SymbolState::Ready,
1522 RegisterDependenciesFunction RegisterDependencies =
1524
1525 /// Convenience version of blocking lookup.
1526 /// Searches each of the JITDylibs in the search order in turn for the given
1527 /// symbol.
1529 lookup(const JITDylibSearchOrder &SearchOrder, SymbolStringPtr Symbol,
1530 SymbolState RequiredState = SymbolState::Ready);
1531
1532 /// Convenience version of blocking lookup.
1533 /// Searches each of the JITDylibs in the search order in turn for the given
1534 /// symbol. The search will not find non-exported symbols.
1536 lookup(ArrayRef<JITDylib *> SearchOrder, SymbolStringPtr Symbol,
1537 SymbolState RequiredState = SymbolState::Ready);
1538
1539 /// Convenience version of blocking lookup.
1540 /// Searches each of the JITDylibs in the search order in turn for the given
1541 /// symbol. The search will not find non-exported symbols.
1543 lookup(ArrayRef<JITDylib *> SearchOrder, StringRef Symbol,
1544 SymbolState RequiredState = SymbolState::Ready);
1545
1546 /// Materialize the given unit.
1547 void dispatchTask(std::unique_ptr<Task> T) {
1548 assert(T && "T must be non-null");
1549 DEBUG_WITH_TYPE("orc", dumpDispatchInfo(*T));
1550 EPC->getDispatcher().dispatch(std::move(T));
1551 }
1552
1553 /// Run a wrapper function in the executor.
1554 ///
1555 /// The wrapper function should be callable as:
1556 ///
1557 /// \code{.cpp}
1558 /// CWrapperFunctionResult fn(uint8_t *Data, uint64_t Size);
1559 /// \endcode{.cpp}
1560 ///
1561 /// The given OnComplete function will be called to return the result.
1562 template <typename... ArgTs>
1563 void callWrapperAsync(ArgTs &&... Args) {
1564 EPC->callWrapperAsync(std::forward<ArgTs>(Args)...);
1565 }
1566
1567 /// Run a wrapper function in the executor. The wrapper function should be
1568 /// callable as:
1569 ///
1570 /// \code{.cpp}
1571 /// CWrapperFunctionResult fn(uint8_t *Data, uint64_t Size);
1572 /// \endcode{.cpp}
1574 ArrayRef<char> ArgBuffer) {
1575 return EPC->callWrapper(WrapperFnAddr, ArgBuffer);
1576 }
1577
1578 /// Run a wrapper function using SPS to serialize the arguments and
1579 /// deserialize the results.
1580 template <typename SPSSignature, typename SendResultT, typename... ArgTs>
1581 void callSPSWrapperAsync(ExecutorAddr WrapperFnAddr, SendResultT &&SendResult,
1582 const ArgTs &...Args) {
1583 EPC->callSPSWrapperAsync<SPSSignature, SendResultT, ArgTs...>(
1584 WrapperFnAddr, std::forward<SendResultT>(SendResult), Args...);
1585 }
1586
1587 /// Run a wrapper function using SPS to serialize the arguments and
1588 /// deserialize the results.
1589 ///
1590 /// If SPSSignature is a non-void function signature then the second argument
1591 /// (the first in the Args list) should be a reference to a return value.
1592 template <typename SPSSignature, typename... WrapperCallArgTs>
1594 WrapperCallArgTs &&...WrapperCallArgs) {
1595 return EPC->callSPSWrapper<SPSSignature, WrapperCallArgTs...>(
1596 WrapperFnAddr, std::forward<WrapperCallArgTs>(WrapperCallArgs)...);
1597 }
1598
1599 /// Wrap a handler that takes concrete argument types (and a sender for a
1600 /// concrete return type) to produce an AsyncHandlerWrapperFunction. Uses SPS
1601 /// to unpack the arguments and pack the result.
1602 ///
1603 /// This function is intended to support easy construction of
1604 /// AsyncHandlerWrapperFunctions that can be associated with a tag
1605 /// (using registerJITDispatchHandler) and called from the executor.
1606 template <typename SPSSignature, typename HandlerT>
1608 return [H = std::forward<HandlerT>(H)](
1609 SendResultFunction SendResult,
1610 const char *ArgData, size_t ArgSize) mutable {
1612 std::move(SendResult));
1613 };
1614 }
1615
1616 /// Wrap a class method that takes concrete argument types (and a sender for
1617 /// a concrete return type) to produce an AsyncHandlerWrapperFunction. Uses
1618 /// SPS to unpack the arguments and pack the result.
1619 ///
1620 /// This function is intended to support easy construction of
1621 /// AsyncHandlerWrapperFunctions that can be associated with a tag
1622 /// (using registerJITDispatchHandler) and called from the executor.
1623 template <typename SPSSignature, typename ClassT, typename... MethodArgTs>
1625 wrapAsyncWithSPS(ClassT *Instance, void (ClassT::*Method)(MethodArgTs...)) {
1626 return wrapAsyncWithSPS<SPSSignature>(
1627 [Instance, Method](MethodArgTs &&...MethodArgs) {
1628 (Instance->*Method)(std::forward<MethodArgTs>(MethodArgs)...);
1629 });
1630 }
1631
1632 /// For each tag symbol name, associate the corresponding
1633 /// AsyncHandlerWrapperFunction with the address of that symbol. The
1634 /// handler becomes callable from the executor using the ORC runtime
1635 /// __orc_rt_jit_dispatch function and the given tag.
1636 ///
1637 /// Tag symbols will be looked up in JD using LookupKind::Static,
1638 /// JITDylibLookupFlags::MatchAllSymbols (hidden tags will be found), and
1639 /// LookupFlags::WeaklyReferencedSymbol. Missing tag definitions will not
1640 /// cause an error, the handler will simply be dropped.
1643
1644 /// Run a registered jit-side wrapper function.
1645 /// This should be called by the ExecutorProcessControl instance in response
1646 /// to incoming jit-dispatch requests from the executor.
1648 ExecutorAddr HandlerFnTagAddr,
1649 ArrayRef<char> ArgBuffer);
1650
1651 /// Dump the state of all the JITDylibs in this session.
1652 void dump(raw_ostream &OS);
1653
1654 /// Check the internal consistency of ExecutionSession data structures.
1655#ifdef EXPENSIVE_CHECKS
1656 bool verifySessionState(Twine Phase);
1657#endif
1658
1659private:
1660 static void logErrorsToStdErr(Error Err) {
1661 logAllUnhandledErrors(std::move(Err), errs(), "JIT session error: ");
1662 }
1663
1664 void dispatchOutstandingMUs();
1665
1666 static std::unique_ptr<MaterializationResponsibility>
1667 createMaterializationResponsibility(ResourceTracker &RT,
1668 SymbolFlagsMap Symbols,
1669 SymbolStringPtr InitSymbol) {
1670 auto &JD = RT.getJITDylib();
1671 std::unique_ptr<MaterializationResponsibility> MR(
1672 new MaterializationResponsibility(&RT, std::move(Symbols),
1673 std::move(InitSymbol)));
1674 JD.TrackerMRs[&RT].insert(MR.get());
1675 return MR;
1676 }
1677
1678 Error removeResourceTracker(ResourceTracker &RT);
1679 void transferResourceTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT);
1680 void destroyResourceTracker(ResourceTracker &RT);
1681
1682 // State machine functions for query application..
1683
1684 /// IL_updateCandidatesFor is called to remove already-defined symbols that
1685 /// match a given query from the set of candidate symbols to generate
1686 /// definitions for (no need to generate a definition if one already exists).
1687 Error IL_updateCandidatesFor(JITDylib &JD, JITDylibLookupFlags JDLookupFlags,
1688 SymbolLookupSet &Candidates,
1689 SymbolLookupSet *NonCandidates);
1690
1691 /// Handle resumption of a lookup after entering a generator.
1692 void OL_resumeLookupAfterGeneration(InProgressLookupState &IPLS);
1693
1694 /// OL_applyQueryPhase1 is an optionally re-startable loop for triggering
1695 /// definition generation. It is called when a lookup is performed, and again
1696 /// each time that LookupState::continueLookup is called.
1697 void OL_applyQueryPhase1(std::unique_ptr<InProgressLookupState> IPLS,
1698 Error Err);
1699
1700 /// OL_completeLookup is run once phase 1 successfully completes for a lookup
1701 /// call. It attempts to attach the symbol to all symbol table entries and
1702 /// collect all MaterializationUnits to dispatch. If this method fails then
1703 /// all MaterializationUnits will be left un-materialized.
1704 void OL_completeLookup(std::unique_ptr<InProgressLookupState> IPLS,
1705 std::shared_ptr<AsynchronousSymbolQuery> Q,
1706 RegisterDependenciesFunction RegisterDependencies);
1707
1708 /// OL_completeLookupFlags is run once phase 1 successfully completes for a
1709 /// lookupFlags call.
1710 void OL_completeLookupFlags(
1711 std::unique_ptr<InProgressLookupState> IPLS,
1712 unique_function<void(Expected<SymbolFlagsMap>)> OnComplete);
1713
1714 // State machine functions for MaterializationResponsibility.
1715 void OL_destroyMaterializationResponsibility(
1717 SymbolNameSet OL_getRequestedSymbols(const MaterializationResponsibility &MR);
1718 Error OL_notifyResolved(MaterializationResponsibility &MR,
1719 const SymbolMap &Symbols);
1720
1721 using EDUInfosMap =
1722 DenseMap<JITDylib::EmissionDepUnit *, JITDylib::EmissionDepUnitInfo>;
1723
1724 template <typename HandleNewDepFn>
1725 void propagateExtraEmitDeps(std::deque<JITDylib::EmissionDepUnit *> Worklist,
1726 EDUInfosMap &EDUInfos,
1727 HandleNewDepFn HandleNewDep);
1728 EDUInfosMap simplifyDepGroups(MaterializationResponsibility &MR,
1729 ArrayRef<SymbolDependenceGroup> EmittedDeps);
1730 void IL_makeEDUReady(std::shared_ptr<JITDylib::EmissionDepUnit> EDU,
1731 JITDylib::AsynchronousSymbolQuerySet &Queries);
1732 void IL_makeEDUEmitted(std::shared_ptr<JITDylib::EmissionDepUnit> EDU,
1733 JITDylib::AsynchronousSymbolQuerySet &Queries);
1734 bool IL_removeEDUDependence(JITDylib::EmissionDepUnit &EDU, JITDylib &DepJD,
1735 NonOwningSymbolStringPtr DepSym,
1736 EDUInfosMap &EDUInfos);
1737
1738 static Error makeJDClosedError(JITDylib::EmissionDepUnit &EDU,
1739 JITDylib &ClosedJD);
1740 static Error makeUnsatisfiedDepsError(JITDylib::EmissionDepUnit &EDU,
1741 JITDylib &BadJD, SymbolNameSet BadDeps);
1742
1743 Expected<JITDylib::AsynchronousSymbolQuerySet>
1744 IL_emit(MaterializationResponsibility &MR, EDUInfosMap EDUInfos);
1745 Error OL_notifyEmitted(MaterializationResponsibility &MR,
1746 ArrayRef<SymbolDependenceGroup> EmittedDeps);
1747
1748 Error OL_defineMaterializing(MaterializationResponsibility &MR,
1749 SymbolFlagsMap SymbolFlags);
1750
1751 std::pair<JITDylib::AsynchronousSymbolQuerySet,
1752 std::shared_ptr<SymbolDependenceMap>>
1753 IL_failSymbols(JITDylib &JD, const SymbolNameVector &SymbolsToFail);
1754 void OL_notifyFailed(MaterializationResponsibility &MR);
1755 Error OL_replace(MaterializationResponsibility &MR,
1756 std::unique_ptr<MaterializationUnit> MU);
1757 Expected<std::unique_ptr<MaterializationResponsibility>>
1758 OL_delegate(MaterializationResponsibility &MR, const SymbolNameSet &Symbols);
1759
1760#ifndef NDEBUG
1761 void dumpDispatchInfo(Task &T);
1762#endif // NDEBUG
1763
1764 mutable std::recursive_mutex SessionMutex;
1765 bool SessionOpen = true;
1766 std::unique_ptr<ExecutorProcessControl> EPC;
1767 std::unique_ptr<Platform> P;
1768 ErrorReporter ReportError = logErrorsToStdErr;
1769
1770 std::vector<ResourceManager *> ResourceManagers;
1771
1772 std::vector<JITDylibSP> JDs;
1773
1774 // FIXME: Remove this (and runOutstandingMUs) once the linking layer works
1775 // with callbacks from asynchronous queries.
1776 mutable std::recursive_mutex OutstandingMUsMutex;
1777 std::vector<std::pair<std::unique_ptr<MaterializationUnit>,
1778 std::unique_ptr<MaterializationResponsibility>>>
1779 OutstandingMUs;
1780
1781 mutable std::mutex JITDispatchHandlersMutex;
1782 DenseMap<ExecutorAddr, std::shared_ptr<JITDispatchHandlerFunction>>
1783 JITDispatchHandlers;
1784};
1785
1787 return JD->getExecutionSession().lookup({JD.get()}, Name);
1788}
1789
1790template <typename Func> Error ResourceTracker::withResourceKeyDo(Func &&F) {
1792 if (isDefunct())
1793 return make_error<ResourceTrackerDefunct>(this);
1794 F(getKeyUnsafe());
1795 return Error::success();
1796 });
1797}
1798
1799inline ExecutionSession &
1801 return JD.getExecutionSession();
1802}
1803
1804template <typename GeneratorT>
1805GeneratorT &JITDylib::addGenerator(std::unique_ptr<GeneratorT> DefGenerator) {
1806 auto &G = *DefGenerator;
1807 ES.runSessionLocked([&] {
1808 assert(State == Open && "Cannot add generator to closed JITDylib");
1809 DefGenerators.push_back(std::move(DefGenerator));
1810 });
1811 return G;
1812}
1813
1814template <typename Func>
1816 -> decltype(F(std::declval<const JITDylibSearchOrder &>())) {
1817 assert(State == Open && "Cannot use link order of closed JITDylib");
1818 return ES.runSessionLocked([&]() { return F(LinkOrder); });
1819}
1820
1821template <typename MaterializationUnitType>
1822Error JITDylib::define(std::unique_ptr<MaterializationUnitType> &&MU,
1823 ResourceTrackerSP RT) {
1824 assert(MU && "Can not define with a null MU");
1825
1826 if (MU->getSymbols().empty()) {
1827 // Empty MUs are allowable but pathological, so issue a warning.
1828 DEBUG_WITH_TYPE("orc", {
1829 dbgs() << "Warning: Discarding empty MU " << MU->getName() << " for "
1830 << getName() << "\n";
1831 });
1832 return Error::success();
1833 } else
1834 DEBUG_WITH_TYPE("orc", {
1835 dbgs() << "Defining MU " << MU->getName() << " for " << getName()
1836 << " (tracker: ";
1837 if (RT == getDefaultResourceTracker())
1838 dbgs() << "default)";
1839 else if (RT)
1840 dbgs() << RT.get() << ")\n";
1841 else
1842 dbgs() << "0x0, default will be used)\n";
1843 });
1844
1845 return ES.runSessionLocked([&, this]() -> Error {
1846 assert(State == Open && "JD is defunct");
1847
1848 if (auto Err = defineImpl(*MU))
1849 return Err;
1850
1851 if (!RT)
1853
1854 if (auto *P = ES.getPlatform()) {
1855 if (auto Err = P->notifyAdding(*RT, *MU))
1856 return Err;
1857 }
1858
1859 installMaterializationUnit(std::move(MU), *RT);
1860 return Error::success();
1861 });
1862}
1863
1864template <typename MaterializationUnitType>
1865Error JITDylib::define(std::unique_ptr<MaterializationUnitType> &MU,
1866 ResourceTrackerSP RT) {
1867 assert(MU && "Can not define with a null MU");
1868
1869 if (MU->getSymbols().empty()) {
1870 // Empty MUs are allowable but pathological, so issue a warning.
1871 DEBUG_WITH_TYPE("orc", {
1872 dbgs() << "Warning: Discarding empty MU " << MU->getName() << getName()
1873 << "\n";
1874 });
1875 return Error::success();
1876 } else
1877 DEBUG_WITH_TYPE("orc", {
1878 dbgs() << "Defining MU " << MU->getName() << " for " << getName()
1879 << " (tracker: ";
1880 if (RT == getDefaultResourceTracker())
1881 dbgs() << "default)";
1882 else if (RT)
1883 dbgs() << RT.get() << ")\n";
1884 else
1885 dbgs() << "0x0, default will be used)\n";
1886 });
1887
1888 return ES.runSessionLocked([&, this]() -> Error {
1889 assert(State == Open && "JD is defunct");
1890
1891 if (auto Err = defineImpl(*MU))
1892 return Err;
1893
1894 if (!RT)
1896
1897 if (auto *P = ES.getPlatform()) {
1898 if (auto Err = P->notifyAdding(*RT, *MU))
1899 return Err;
1900 }
1901
1902 installMaterializationUnit(std::move(MU), *RT);
1903 return Error::success();
1904 });
1905}
1906
1907/// ReexportsGenerator can be used with JITDylib::addGenerator to automatically
1908/// re-export a subset of the source JITDylib's symbols in the target.
1910public:
1911 using SymbolPredicate = std::function<bool(SymbolStringPtr)>;
1912
1913 /// Create a reexports generator. If an Allow predicate is passed, only
1914 /// symbols for which the predicate returns true will be reexported. If no
1915 /// Allow predicate is passed, all symbols will be exported.
1916 ReexportsGenerator(JITDylib &SourceJD,
1917 JITDylibLookupFlags SourceJDLookupFlags,
1919
1921 JITDylibLookupFlags JDLookupFlags,
1922 const SymbolLookupSet &LookupSet) override;
1923
1924private:
1925 JITDylib &SourceJD;
1926 JITDylibLookupFlags SourceJDLookupFlags;
1927 SymbolPredicate Allow;
1928};
1929
1930// --------------- IMPLEMENTATION --------------
1931// Implementations for inline functions/methods.
1932// ---------------------------------------------
1933
1935 getExecutionSession().OL_destroyMaterializationResponsibility(*this);
1936}
1937
1939 return getExecutionSession().OL_getRequestedSymbols(*this);
1940}
1941
1943 const SymbolMap &Symbols) {
1944 return getExecutionSession().OL_notifyResolved(*this, Symbols);
1945}
1946
1948 ArrayRef<SymbolDependenceGroup> EmittedDeps) {
1949 return getExecutionSession().OL_notifyEmitted(*this, EmittedDeps);
1950}
1951
1953 SymbolFlagsMap SymbolFlags) {
1954 return getExecutionSession().OL_defineMaterializing(*this,
1955 std::move(SymbolFlags));
1956}
1957
1959 getExecutionSession().OL_notifyFailed(*this);
1960}
1961
1963 std::unique_ptr<MaterializationUnit> MU) {
1964 return getExecutionSession().OL_replace(*this, std::move(MU));
1965}
1966
1969 return getExecutionSession().OL_delegate(*this, Symbols);
1970}
1971
1972} // End namespace orc
1973} // End namespace llvm
1974
1975#endif // LLVM_EXECUTIONENGINE_ORC_CORE_H
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Given that RA is a live value
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition: Debug.h:64
This file defines the DenseSet and SmallDenseSet classes.
uint64_t Addr
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.
#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
#define H(x, y, z)
Definition: MD5.cpp:57
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const Value * getAddress(const DbgVariableIntrinsic *DVI)
Definition: SROA.cpp:5023
raw_pwrite_stream & OS
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
bool empty() const
Definition: DenseMap.h:98
Base class for user error types.
Definition: Error.h:355
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
Flags for symbols in the JIT.
Definition: JITSymbol.h:74
Inheritance utility for extensible RTTI.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
A thread-safe version of RefCountedBase.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
size_type size() const
Definition: DenseSet.h:81
A symbol query that returns results via a callback when results are ready.
Definition: Core.h:780
bool isComplete() const
Returns true if all symbols covered by this query have been resolved.
Definition: Core.h:801
void notifySymbolMetRequiredState(const SymbolStringPtr &Name, ExecutorSymbolDef Sym)
Notify the query that a requested symbol has reached the required state.
Definition: Core.cpp:216
friend class JITSymbolResolverAdapter
Definition: Core.h:784
Definition generators can be attached to JITDylibs to generate new definitions for otherwise unresolv...
Definition: Core.h:854
virtual Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &LookupSet)=0
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
An ExecutionSession represents a running JIT program.
Definition: Core.h:1339
Error endSession()
End the session.
Definition: Core.cpp:1602
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Definition: Core.h:1379
unique_function< void(shared::WrapperFunctionResult)> SendResultFunction
Send a result to the remote.
Definition: Core.h:1352
void reportError(Error Err)
Report a error for this execution session.
Definition: Core.h:1474
friend class JITDylib
Definition: Core.h:1342
void setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
Definition: Core.h:1396
const Triple & getTargetTriple() const
Return the triple for the executor.
Definition: Core.h:1382
Platform * getPlatform()
Get the Platform for this session.
Definition: Core.h:1400
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Definition: Core.h:1593
void lookupFlags(LookupKind K, JITDylibSearchOrder SearchOrder, SymbolLookupSet Symbols, unique_function< void(Expected< SymbolFlagsMap >)> OnComplete)
Search the given JITDylibs to find the flags associated with each of the given symbols.
Definition: Core.cpp:1762
shared::WrapperFunctionResult callWrapper(ExecutorAddr WrapperFnAddr, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
Definition: Core.h:1573
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:1393
JITDylib * getJITDylibByName(StringRef Name)
Return a pointer to the "name" JITDylib.
Definition: Core.cpp:1641
void callWrapperAsync(ArgTs &&... Args)
Run a wrapper function in the executor.
Definition: Core.h:1563
static JITDispatchHandlerFunction wrapAsyncWithSPS(ClassT *Instance, void(ClassT::*Method)(MethodArgTs...))
Wrap a class method that takes concrete argument types (and a sender for a concrete return type) to p...
Definition: Core.h:1625
JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
Definition: Core.cpp:1650
static JITDispatchHandlerFunction wrapAsyncWithSPS(HandlerT &&H)
Wrap a handler that takes concrete argument types (and a sender for a concrete return type) to produc...
Definition: Core.h:1607
void callSPSWrapperAsync(ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Definition: Core.h:1581
DenseMap< SymbolStringPtr, JITDispatchHandlerFunction > JITDispatchHandlerAssociationMap
A map associating tag names with asynchronous wrapper function implementations in the JIT.
Definition: Core.h:1363
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Get the SymbolStringPool for this instance.
Definition: Core.h:1388
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:1788
Error registerJITDispatchHandlers(JITDylib &JD, JITDispatchHandlerAssociationMap WFs)
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of...
Definition: Core.cpp:1897
friend class MaterializationResponsibility
Definition: Core.h:1344
void registerResourceManager(ResourceManager &RM)
Register the given ResourceManager with this ExecutionSession.
Definition: Core.cpp:1624
~ExecutionSession()
Destroy an ExecutionSession.
Definition: Core.cpp:1596
void runJITDispatchHandler(SendResultFunction SendResult, ExecutorAddr HandlerFnTagAddr, ArrayRef< char > ArgBuffer)
Run a registered jit-side wrapper function.
Definition: Core.cpp:1936
unique_function< void(SendResultFunction SendResult, const char *ArgData, size_t ArgSize)> JITDispatchHandlerFunction
An asynchronous wrapper-function callable from the executor via jit-dispatch.
Definition: Core.h:1358
void deregisterResourceManager(ResourceManager &RM)
Deregister the given ResourceManager with this ExecutionSession.
Definition: Core.cpp:1628
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Definition: Core.h:1403
void dump(raw_ostream &OS)
Dump the state of all the JITDylibs in this session.
Definition: Core.cpp:1957
friend class ResourceTracker
Definition: Core.h:1345
ExecutionSession & setErrorReporter(ErrorReporter ReportError)
Set the error reporter function.
Definition: Core.h:1466
Error removeJITDylibs(std::vector< JITDylibSP > JDsToRemove)
Removes the given JITDylibs from the ExecutionSession.
Definition: Core.cpp:1667
size_t getPageSize() const
Definition: Core.h:1385
Expected< JITDylib & > createJITDylib(std::string Name)
Add a new JITDylib to this ExecutionSession.
Definition: Core.cpp:1659
void dispatchTask(std::unique_ptr< Task > T)
Materialize the given unit.
Definition: Core.h:1547
unique_function< void(Error)> ErrorReporter
For reporting errors.
Definition: Core.h:1349
Error removeJITDylib(JITDylib &JD)
Calls removeJTIDylibs on the gives JITDylib.
Definition: Core.h:1461
Represents an address in the executor process.
ExecutorProcessControl supports interaction with a JIT target process.
Represents a defining location for a JIT symbol.
Used to notify a JITDylib that the given set of symbols failed to materialize.
Definition: Core.h:439
const SymbolDependenceMap & getSymbols() const
Definition: Core.h:448
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:100
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:104
Represents a JIT'd dynamic library.
Definition: Core.h:897
Error remove(const SymbolNameSet &Names)
Tries to remove the given symbols.
Definition: Core.cpp:1059
Error clear()
Calls remove on all trackers currently associated with this JITDylib.
Definition: Core.cpp:657
JITDylib & operator=(JITDylib &&)=delete
void dump(raw_ostream &OS)
Dump current JITDylib state to OS.
Definition: Core.cpp:1120
friend class AsynchronousSymbolQuery
Definition: Core.h:898
void replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD, JITDylibLookupFlags JDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Replace OldJD with NewJD in the link order if OldJD is present.
Definition: Core.cpp:1035
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:1822
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Definition: Core.h:916
void addToLinkOrder(const JITDylibSearchOrder &NewLinks)
Append the given JITDylibSearchOrder to the link order for this JITDylib (discarding any elements alr...
Definition: Core.cpp:1019
ResourceTrackerSP createResourceTracker()
Create a resource tracker for this JITDylib.
Definition: Core.cpp:681
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
Definition: Core.h:1815
friend class MaterializationResponsibility
Definition: Core.h:901
void removeFromLinkOrder(JITDylib &JD)
Remove the given JITDylib from the link order for this JITDylib if it is present.
Definition: Core.cpp:1047
void setLinkOrder(JITDylibSearchOrder NewSearchOrder, bool LinkAgainstThisJITDylibFirst=true)
Set the link order to be used when fixing up definitions in JITDylib.
Definition: Core.cpp:1004
Expected< std::vector< JITDylibSP > > getReverseDFSLinkOrder()
Rteurn this JITDylib and its transitive dependencies in reverse DFS order based on linkage relationsh...
Definition: Core.cpp:1758
friend class ExecutionSession
Definition: Core.h:899
ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
Definition: Core.cpp:672
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
Definition: Core.h:1805
JITDylib(const JITDylib &)=delete
JITDylib & operator=(const JITDylib &)=delete
JITDylib(JITDylib &&)=delete
void removeGenerator(DefinitionGenerator &G)
Remove a definition generator from this JITDylib.
Definition: Core.cpp:689
Expected< std::vector< JITDylibSP > > getDFSLinkOrder()
Return this JITDylib and its transitive dependencies in DFS order based on linkage relationships.
Definition: Core.cpp:1754
Wraps state for a lookup-in-progress.
Definition: Core.h:829
void continueLookup(Error Err)
Continue the lookup.
Definition: Core.cpp:633
LookupState & operator=(LookupState &&)
LookupState(LookupState &&)
Lookups are usually run on the current thread, but in some cases they may be run as tasks,...
Definition: Core.h:1326
LookupTask(LookupState LS)
Definition: Core.h:1330
void run() override
Definition: Core.cpp:1588
static char ID
Definition: Core.h:1328
void printDescription(raw_ostream &OS) override
Definition: Core.cpp:1586
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:571
MaterializationResponsibility & operator=(MaterializationResponsibility &&)=delete
ExecutionSession & getExecutionSession() const
Returns the ExecutionSession for this instance.
Definition: Core.h:1800
Error notifyResolved(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
Definition: Core.h:1942
~MaterializationResponsibility()
Destruct a MaterializationResponsibility instance.
Definition: Core.h:1934
Error replace(std::unique_ptr< MaterializationUnit > MU)
Transfers responsibility to the given MaterializationUnit for all symbols defined by that Materializa...
Definition: Core.h:1962
Error withResourceKeyDo(Func &&F) const
Runs the given callback under the session lock, passing in the associated ResourceKey.
Definition: Core.h:590
Error defineMaterializing(SymbolFlagsMap SymbolFlags)
Attempt to claim responsibility for new definitions.
Definition: Core.h:1952
SymbolNameSet getRequestedSymbols() const
Returns the names of any symbols covered by this MaterializationResponsibility object that have queri...
Definition: Core.h:1938
Expected< std::unique_ptr< MaterializationResponsibility > > delegate(const SymbolNameSet &Symbols)
Delegates responsibility for the given symbols to the returned materialization responsibility.
Definition: Core.h:1968
const ResourceTrackerSP & getResourceTracker() const
Return the ResourceTracker associated with this instance.
Definition: Core.h:586
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization pseudo-symbol, if any.
Definition: Core.h:610
MaterializationResponsibility(MaterializationResponsibility &&)=delete
Error notifyEmitted(ArrayRef< SymbolDependenceGroup > DepGroups)
Notifies the target JITDylib (and any pending queries on that JITDylib) that all symbols covered by t...
Definition: Core.h:1947
void failMaterialization()
Notify all not-yet-emitted covered by this MaterializationResponsibility instance that an error has o...
Definition: Core.h:1958
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
Definition: Core.h:596
const SymbolFlagsMap & getSymbols() const
Returns the symbol flags map for this responsibility instance.
Definition: Core.h:605
A materialization task.
Definition: Core.h:1308
void printDescription(raw_ostream &OS) override
Definition: Core.cpp:1579
MaterializationTask(std::unique_ptr< MaterializationUnit > MU, std::unique_ptr< MaterializationResponsibility > MR)
Definition: Core.h:1312
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Errors of this type should be returned if a module fails to include definitions that are claimed by t...
Definition: Core.h:515
const SymbolNameVector & getSymbols() const
Definition: Core.h:527
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Definition: Core.h:525
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:163
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:167
MissingSymbolDefinitions(std::shared_ptr< SymbolStringPool > SSP, std::string ModuleName, SymbolNameVector Symbols)
Definition: Core.h:519
const std::string & getModuleName() const
Definition: Core.h:526
Platforms set up standard symbols and mediate interactions between dynamic initializers (e....
Definition: Core.h:1268
virtual Error teardownJITDylib(JITDylib &JD)=0
This method will be called outside the session lock each time a JITDylib is removed to allow the Plat...
static void lookupInitSymbolsAsync(unique_function< void(Error)> OnComplete, ExecutionSession &ES, const DenseMap< JITDylib *, SymbolLookupSet > &InitSyms)
Performs an async lookup for the given symbols in each of the given JITDylibs, calling the given hand...
Definition: Core.cpp:1536
virtual Error notifyRemoving(ResourceTracker &RT)=0
This method will be called under the ExecutionSession lock when a ResourceTracker is removed.
static Expected< DenseMap< JITDylib *, SymbolMap > > lookupInitSymbols(ExecutionSession &ES, const DenseMap< JITDylib *, SymbolLookupSet > &InitSyms)
A utility function for looking up initializer symbols.
Definition: Core.cpp:1487
virtual Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU)=0
This method will be called under the ExecutionSession lock each time a MaterializationUnit is added t...
virtual Error setupJITDylib(JITDylib &JD)=0
This method will be called outside the session lock each time a JITDylib is created (unless it is cre...
A materialization unit for symbol aliases.
Definition: Core.h:706
StringRef getName() const override
Return the name of this materialization unit.
Definition: Core.cpp:307
ReexportsGenerator can be used with JITDylib::addGenerator to automatically re-export a subset of the...
Definition: Core.h:1909
std::function< bool(SymbolStringPtr)> SymbolPredicate
Definition: Core.h:1911
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &LookupSet) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Definition: Core.cpp:598
Listens for ResourceTracker operations.
Definition: Core.h:125
virtual Error handleRemoveResources(JITDylib &JD, ResourceKey K)=0
This function will be called outside the session lock.
virtual void handleTransferResources(JITDylib &JD, ResourceKey DstK, ResourceKey SrcK)=0
This function will be called inside the session lock.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:78
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:74
API to remove / transfer ownership of JIT resources.
Definition: Core.h:77
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
Definition: Core.h:92
ResourceTracker & operator=(const ResourceTracker &)=delete
ResourceKey getKeyUnsafe() const
Returns the key associated with this tracker.
Definition: Core.h:114
void transferTo(ResourceTracker &DstRT)
Transfer all resources associated with this key to the given tracker, which must target the same JITD...
Definition: Core.cpp:59
ResourceTracker & operator=(ResourceTracker &&)=delete
ResourceTracker(const ResourceTracker &)=delete
bool isDefunct() const
Return true if this tracker has become defunct.
Definition: Core.h:109
ResourceTracker(ResourceTracker &&)=delete
Error withResourceKeyDo(Func &&F)
Runs the given callback under the session lock, passing in the associated ResourceKey.
Definition: Core.h:1790
Error remove()
Remove all resources associated with this key.
Definition: Core.cpp:55
A definition of a Symbol within a JITDylib.
Definition: Core.h:55
Expected< ExecutorSymbolDef > lookup() const
Definition: Core.h:1786
SymbolInstance(JITDylibSP JD, SymbolStringPtr Name)
Definition: Core.h:60
void lookupAsync(LookupAsyncOnCompleteFn OnComplete) const
Definition: Core.cpp:181
const JITDylib & getJITDylib() const
Definition: Core.h:63
const SymbolStringPtr & getName() const
Definition: Core.h:64
unique_function< void(Expected< ExecutorSymbolDef >)> LookupAsyncOnCompleteFn
Definition: Core.h:58
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:194
std::pair< SymbolStringPtr, SymbolLookupFlags > value_type
Definition: Core.h:196
const_iterator begin() const
Definition: Core.h:278
void removeDuplicates()
Remove any duplicate elements.
Definition: Core.h:378
UnderlyingVector::const_iterator const_iterator
Definition: Core.h:199
void sortByAddress()
Sort the lookup set by pointer value.
Definition: Core.h:366
SymbolLookupSet(std::initializer_list< SymbolStringPtr > Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from an initializer list of SymbolStringPtrs.
Definition: Core.h:215
UnderlyingVector::size_type size() const
Definition: Core.h:275
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition: Core.h:260
static SymbolLookupSet fromMapKeys(const DenseMap< SymbolStringPtr, ValT > &M, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from DenseMap keys.
Definition: Core.h:248
SymbolLookupSet & append(SymbolLookupSet Other)
Quickly append one lookup set to another.
Definition: Core.h:267
SymbolLookupSet(ArrayRef< SymbolStringPtr > Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from a vector of symbols with the given Flags used for each value.
Definition: Core.h:237
SymbolLookupSet(std::initializer_list< value_type > Elems)
Definition: Core.h:203
void sortByName()
Sort the lookup set lexicographically.
Definition: Core.h:370
void remove(iterator I)
Removes the element pointed to by the given iterator.
Definition: Core.h:289
auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t< std::is_same< decltype(Body(std::declval< const SymbolStringPtr & >(), std::declval< SymbolLookupFlags >())), bool >::value >
Loop over the elements of this SymbolLookupSet, applying the Body function to each one.
Definition: Core.h:311
bool containsDuplicates()
Returns true if this set contains any duplicates.
Definition: Core.h:387
UnderlyingVector::iterator iterator
Definition: Core.h:198
bool empty() const
Definition: Core.h:274
void remove_if(PredFn &&Pred)
Removes all elements matching the given predicate, which must be callable as bool(const SymbolStringP...
Definition: Core.h:293
SymbolLookupSet(const SymbolNameSet &Names, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Construct a SymbolLookupSet from a SymbolNameSet with the given Flags used for each value.
Definition: Core.h:225
SymbolLookupSet(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Definition: Core.h:208
SymbolNameVector getSymbolNames() const
Construct a SymbolNameVector from this instance by dropping the Flags values.
Definition: Core.h:355
const_iterator end() const
Definition: Core.h:279
auto forEachWithRemoval(BodyFn &&Body) -> std::enable_if_t< std::is_same< decltype(Body(std::declval< const SymbolStringPtr & >(), std::declval< SymbolLookupFlags >())), Expected< bool > >::value, Error >
Loop over the elements of this SymbolLookupSet, applying the Body function to each one.
Definition: Core.h:333
void remove(UnderlyingVector::size_type I)
Removes the Ith element of the vector, replacing it with the last element.
Definition: Core.h:282
std::vector< value_type > UnderlyingVector
Definition: Core.h:197
Pointer to a pooled string representing a symbol name.
Used to notify clients that a set of symbols could not be removed.
Definition: Core.h:495
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:155
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:159
const SymbolNameSet & getSymbols() const
Definition: Core.h:504
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Definition: Core.h:503
Used to notify clients when symbols can not be found during a lookup.
Definition: Core.h:477
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:145
const SymbolNameVector & getSymbols() const
Definition: Core.h:487
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:141
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Definition: Core.h:486
Errors of this type should be returned if a module contains definitions for symbols that are not clai...
Definition: Core.h:538
UnexpectedSymbolDefinitions(std::shared_ptr< SymbolStringPool > SSP, std::string ModuleName, SymbolNameVector Symbols)
Definition: Core.h:542
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:172
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:176
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Definition: Core.h:548
const std::string & getModuleName() const
Definition: Core.h:549
const SymbolNameVector & getSymbols() const
Definition: Core.h:550
Used to report failure due to unsatisfiable symbol dependencies.
Definition: Core.h:457
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Core.cpp:120
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Core.cpp:116
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
unique_function is a type-erasing functor similar to std::function.
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:177
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:173
std::function< void(const SymbolDependenceMap &)> RegisterDependenciesFunction
Callback to register the dependencies for a given query.
Definition: Core.h:419
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
Definition: Core.h:745
IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
Definition: Core.h:51
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
Definition: Core.h:156
std::unique_ptr< ReExportsMaterializationUnit > reexports(JITDylib &SourceJD, SymbolAliasMap Aliases, JITDylibLookupFlags SourceJDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Create a materialization unit for re-exporting symbols from another JITDylib with alternative names/f...
Definition: Core.h:754
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition: Core.h:146
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
unique_function< void(Expected< SymbolMap >)> SymbolsResolvedCallback
Callback to notify client that symbols have been resolved.
Definition: Core.h:415
DenseSet< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:168
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
Definition: Core.cpp:38
std::vector< SymbolStringPtr > SymbolNameVector
A vector of symbol names.
SymbolState
Represents the state that a symbol has reached during materialization.
Definition: Core.h:767
@ Materializing
Added to the symbol table, never queried.
@ NeverSearched
No symbol should be in this state.
@ Ready
Emitted to memory, but waiting on transitive dependencies.
@ Emitted
Assigned address, still materializing.
@ Resolved
Queried, materialization begun.
uintptr_t ResourceKey
Definition: Core.h:74
DenseMap< JITDylib *, SymbolNameSet > SymbolDependenceMap
A map from JITDylibs to sets of symbols.
Expected< SymbolAliasMap > buildSimpleReexportsAliasMap(JITDylib &SourceJD, const SymbolNameSet &Symbols)
Build a SymbolAliasMap for the common case where you want to re-export symbols from another JITDylib ...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition: Error.cpp:65
auto unique(Range &&R, Predicate P)
Definition: STLExtras.h:2055
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1664
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ 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:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860
Function object to check whether the first component of a container supported by std::get (like std::...
Definition: STLExtras.h:1467
JITSymbolFlags AliasFlags
Definition: Core.h:408
SymbolAliasMapEntry(SymbolStringPtr Aliasee, JITSymbolFlags AliasFlags)
Definition: Core.h:404
SymbolStringPtr Aliasee
Definition: Core.h:407
A set of symbols and the their dependencies.
Definition: Core.h:559
SymbolDependenceMap Dependencies
Definition: Core.h:561