@@ -66,6 +66,11 @@ using SymbolDependenceMap = std::map<VSO *, SymbolNameSet>;
66
66
// / Render a SymbolDependendeMap.
67
67
raw_ostream &operator <<(raw_ostream &OS, const SymbolDependenceMap &Deps);
68
68
69
+ // / A list of VSO pointers.
70
+ using VSOList = std::vector<VSO *>;
71
+
72
+ raw_ostream &operator <<(raw_ostream &OS, const VSOList &VSOs);
73
+
69
74
// / Used to notify a VSO that the given set of symbols failed to materialize.
70
75
class FailedToMaterialize : public ErrorInfo <FailedToMaterialize> {
71
76
public:
@@ -471,74 +476,6 @@ class AsynchronousSymbolQuery {
471
476
size_t NotYetReadyCount;
472
477
};
473
478
474
- // / SymbolResolver is a composable interface for looking up symbol flags
475
- // / and addresses using the AsynchronousSymbolQuery type. It will
476
- // / eventually replace the LegacyJITSymbolResolver interface as the
477
- // / stardard ORC symbol resolver type.
478
- // /
479
- // / FIXME: SymbolResolvers should go away and be replaced with VSOs with
480
- // / defenition generators.
481
- class SymbolResolver {
482
- public:
483
- virtual ~SymbolResolver () = default ;
484
-
485
- // / Returns the flags for each symbol in Symbols that can be found,
486
- // / along with the set of symbol that could not be found.
487
- virtual SymbolNameSet lookupFlags (SymbolFlagsMap &Flags,
488
- const SymbolNameSet &Symbols) = 0;
489
-
490
- // / For each symbol in Symbols that can be found, assigns that symbols
491
- // / value in Query. Returns the set of symbols that could not be found.
492
- virtual SymbolNameSet lookup (std::shared_ptr<AsynchronousSymbolQuery> Query,
493
- SymbolNameSet Symbols) = 0;
494
-
495
- private:
496
- virtual void anchor ();
497
- };
498
-
499
- // / Implements SymbolResolver with a pair of supplied function objects
500
- // / for convenience. See createSymbolResolver.
501
- template <typename LookupFlagsFn, typename LookupFn>
502
- class LambdaSymbolResolver final : public SymbolResolver {
503
- public:
504
- template <typename LookupFlagsFnRef, typename LookupFnRef>
505
- LambdaSymbolResolver (LookupFlagsFnRef &&LookupFlags, LookupFnRef &&Lookup)
506
- : LookupFlags(std::forward<LookupFlagsFnRef>(LookupFlags)),
507
- Lookup (std::forward<LookupFnRef>(Lookup)) {}
508
-
509
- SymbolNameSet lookupFlags (SymbolFlagsMap &Flags,
510
- const SymbolNameSet &Symbols) final {
511
- return LookupFlags (Flags, Symbols);
512
- }
513
-
514
- SymbolNameSet lookup (std::shared_ptr<AsynchronousSymbolQuery> Query,
515
- SymbolNameSet Symbols) final {
516
- return Lookup (std::move (Query), std::move (Symbols));
517
- }
518
-
519
- private:
520
- LookupFlagsFn LookupFlags;
521
- LookupFn Lookup;
522
- };
523
-
524
- // / Creates a SymbolResolver implementation from the pair of supplied
525
- // / function objects.
526
- template <typename LookupFlagsFn, typename LookupFn>
527
- std::unique_ptr<LambdaSymbolResolver<
528
- typename std::remove_cv<
529
- typename std::remove_reference<LookupFlagsFn>::type>::type,
530
- typename std::remove_cv<
531
- typename std::remove_reference<LookupFn>::type>::type>>
532
- createSymbolResolver (LookupFlagsFn &&LookupFlags, LookupFn &&Lookup) {
533
- using LambdaSymbolResolverImpl = LambdaSymbolResolver<
534
- typename std::remove_cv<
535
- typename std::remove_reference<LookupFlagsFn>::type>::type,
536
- typename std::remove_cv<
537
- typename std::remove_reference<LookupFn>::type>::type>;
538
- return llvm::make_unique<LambdaSymbolResolverImpl>(
539
- std::forward<LookupFlagsFn>(LookupFlags), std::forward<LookupFn>(Lookup));
540
- }
541
-
542
479
// / A symbol table that supports asynchoronous symbol queries.
543
480
// /
544
481
// / Represents a virtual shared object. Instances can not be copied or moved, so
@@ -578,6 +515,42 @@ class VSO {
578
515
this ->FallbackDefinitionGenerator = std::move (FallbackDefinitionGenerator);
579
516
}
580
517
518
+ // / Set the search order to be used when fixing up definitions in VSO.
519
+ // / This will replace the previous search order, and apply to any symbol
520
+ // / resolutions made for definitions in this VSO after the call to
521
+ // / setSearchOrder (even if the definition itself was added before the
522
+ // / call).
523
+ // /
524
+ // / If SearchThisVSOFirst is set, which by default it is, then this VSO will
525
+ // / add itself to the beginning of the SearchOrder (Clients should *not*
526
+ // / put this VSO in the list in this case, to avoid redundant lookups).
527
+ // /
528
+ // / If SearchThisVSOFirst is false then the search order will be used as
529
+ // / given. The main motivation for this feature is to support deliberate
530
+ // / shadowing of symbols in this VSO by a facade VSO. For example, the
531
+ // / facade may resolve function names to stubs, and the stubs may compile
532
+ // / lazily by looking up symbols in this dylib. Adding the facade dylib
533
+ // / as the first in the search order (instead of this dylib) ensures that
534
+ // / definitions within this dylib resolve to the lazy-compiling stubs,
535
+ // / rather than immediately materializing the definitions in this dylib.
536
+ void setSearchOrder (VSOList NewSearchOrder, bool SearchThisVSOFirst = true );
537
+
538
+ // / Add the given VSO to the search order for definitions in this VSO.
539
+ void addToSearchOrder (VSO &V);
540
+
541
+ // / Replace OldV with NewV in the search order if OldV is present. Otherwise
542
+ // / this operation is a no-op.
543
+ void replaceInSearchOrder (VSO &OldV, VSO &NewV);
544
+
545
+ // / Remove the given VSO from the search order for this VSO if it is
546
+ // / present. Otherwise this operation is a no-op.
547
+ void removeFromSearchOrder (VSO &V);
548
+
549
+ // / Do something with the search order (run under the session lock).
550
+ template <typename Func> void withSearchOrderDo (Func F) {
551
+ ES.runSessionLocked ([&]() { F (SearchOrder); });
552
+ }
553
+
581
554
// / Define all symbols provided by the materialization unit to be part
582
555
// / of the given VSO.
583
556
template <typename UniquePtrToMaterializationUnit>
@@ -649,8 +622,7 @@ class VSO {
649
622
LLVM_MARK_AS_BITMASK_ENUM (NotifyFullyReady)
650
623
};
651
624
652
- VSO (ExecutionSessionBase &ES, std::string Name)
653
- : ES(ES), VSOName(std::move(Name)) {}
625
+ VSO (ExecutionSessionBase &ES, std::string Name);
654
626
655
627
Error defineImpl (MaterializationUnit &MU);
656
628
@@ -692,6 +664,7 @@ class VSO {
692
664
UnmaterializedInfosMap UnmaterializedInfos;
693
665
MaterializingInfosMap MaterializingInfos;
694
666
FallbackDefinitionGeneratorFunction FallbackDefinitionGenerator;
667
+ VSOList SearchOrder;
695
668
696
669
// FIXME: Remove this (and runOutstandingMUs) once the linking layer works
697
670
// with callbacks from asynchronous queries.
@@ -729,8 +702,6 @@ Expected<SymbolMap> blockingLookup(ExecutionSessionBase &ES,
729
702
SymbolNameSet Names, bool WaiUntilReady,
730
703
MaterializationResponsibility *MR = nullptr );
731
704
732
- using VSOList = std::vector<VSO *>;
733
-
734
705
// / Look up the given names in the given VSOs.
735
706
// / VSOs will be searched in order and no VSO pointer may be null.
736
707
// / All symbols must be found within the given VSOs or an error
0 commit comments