@@ -54,8 +54,8 @@ using SymbolFlagsMap = DenseMap<SymbolStringPtr, JITSymbolFlags>;
54
54
// / symbols to be obtained for logging.
55
55
using SymbolDependenceMap = DenseMap<JITDylib *, SymbolNameSet>;
56
56
57
- // / A list of JITDylib pointers .
58
- using JITDylibList = std::vector<JITDylib *>;
57
+ // / A list of ( JITDylib*, bool) pairs .
58
+ using JITDylibSearchList = std::vector<std::pair< JITDylib *, bool > >;
59
59
60
60
// / Render a SymbolStringPtr.
61
61
raw_ostream &operator <<(raw_ostream &OS, const SymbolStringPtr &Sym);
@@ -85,8 +85,8 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolDependenceMap &Deps);
85
85
// / Render a MaterializationUnit.
86
86
raw_ostream &operator <<(raw_ostream &OS, const MaterializationUnit &MU);
87
87
88
- // / Render a JITDylibList .
89
- raw_ostream &operator <<(raw_ostream &OS, const JITDylibList &JDs);
88
+ // / Render a JITDylibSearchList .
89
+ raw_ostream &operator <<(raw_ostream &OS, const JITDylibSearchList &JDs);
90
90
91
91
// / Callback to notify client that symbols have been resolved.
92
92
using SymbolsResolvedCallback = std::function<void (Expected<SymbolMap>)>;
@@ -351,14 +351,15 @@ using SymbolAliasMap = DenseMap<SymbolStringPtr, SymbolAliasMapEntry>;
351
351
class ReExportsMaterializationUnit : public MaterializationUnit {
352
352
public:
353
353
// / SourceJD is allowed to be nullptr, in which case the source JITDylib is
354
- // / taken to be whatever JITDylib these definitions are materialized in. This
355
- // / is useful for defining aliases within a JITDylib.
354
+ // / taken to be whatever JITDylib these definitions are materialized in (and
355
+ // / MatchNonExported has no effect). This is useful for defining aliases
356
+ // / within a JITDylib.
356
357
// /
357
358
// / Note: Care must be taken that no sets of aliases form a cycle, as such
358
359
// / a cycle will result in a deadlock when any symbol in the cycle is
359
360
// / resolved.
360
- ReExportsMaterializationUnit (JITDylib *SourceJD, SymbolAliasMap Aliases ,
361
- VModuleKey K);
361
+ ReExportsMaterializationUnit (JITDylib *SourceJD, bool MatchNonExported ,
362
+ SymbolAliasMap Aliases, VModuleKey K);
362
363
363
364
StringRef getName () const override ;
364
365
@@ -368,6 +369,7 @@ class ReExportsMaterializationUnit : public MaterializationUnit {
368
369
static SymbolFlagsMap extractFlags (const SymbolAliasMap &Aliases);
369
370
370
371
JITDylib *SourceJD = nullptr ;
372
+ bool MatchNonExported = false ;
371
373
SymbolAliasMap Aliases;
372
374
};
373
375
@@ -385,16 +387,19 @@ class ReExportsMaterializationUnit : public MaterializationUnit {
385
387
inline std::unique_ptr<ReExportsMaterializationUnit>
386
388
symbolAliases (SymbolAliasMap Aliases, VModuleKey K = VModuleKey()) {
387
389
return llvm::make_unique<ReExportsMaterializationUnit>(
388
- nullptr , std::move (Aliases), std::move (K));
390
+ nullptr , true , std::move (Aliases), std::move (K));
389
391
}
390
392
391
393
// / Create a materialization unit for re-exporting symbols from another JITDylib
392
394
// / with alternative names/flags.
395
+ // / If MatchNonExported is true then non-exported symbols from SourceJD can be
396
+ // / re-exported. If it is false, attempts to re-export a non-exported symbol
397
+ // / will result in a "symbol not found" error.
393
398
inline std::unique_ptr<ReExportsMaterializationUnit>
394
399
reexports (JITDylib &SourceJD, SymbolAliasMap Aliases,
395
- VModuleKey K = VModuleKey()) {
400
+ bool MatchNonExported = false , VModuleKey K = VModuleKey()) {
396
401
return llvm::make_unique<ReExportsMaterializationUnit>(
397
- &SourceJD, std::move (Aliases), std::move (K));
402
+ &SourceJD, MatchNonExported, std::move (Aliases), std::move (K));
398
403
}
399
404
400
405
// / Build a SymbolAliasMap for the common case where you want to re-export
@@ -411,13 +416,14 @@ class ReexportsGenerator {
411
416
// / Create a reexports generator. If an Allow predicate is passed, only
412
417
// / symbols for which the predicate returns true will be reexported. If no
413
418
// / Allow predicate is passed, all symbols will be exported.
414
- ReexportsGenerator (JITDylib &SourceJD,
419
+ ReexportsGenerator (JITDylib &SourceJD, bool MatchNonExported = false ,
415
420
SymbolPredicate Allow = SymbolPredicate());
416
421
417
422
SymbolNameSet operator ()(JITDylib &JD, const SymbolNameSet &Names);
418
423
419
424
private:
420
425
JITDylib &SourceJD;
426
+ bool MatchNonExported = false ;
421
427
SymbolPredicate Allow;
422
428
};
423
429
@@ -536,16 +542,18 @@ class JITDylib {
536
542
// / as the first in the search order (instead of this dylib) ensures that
537
543
// / definitions within this dylib resolve to the lazy-compiling stubs,
538
544
// / rather than immediately materializing the definitions in this dylib.
539
- void setSearchOrder (JITDylibList NewSearchOrder,
540
- bool SearchThisJITDylibFirst = true );
545
+ void setSearchOrder (JITDylibSearchList NewSearchOrder,
546
+ bool SearchThisJITDylibFirst = true ,
547
+ bool MatchNonExportedInThisDylib = true );
541
548
542
549
// / Add the given JITDylib to the search order for definitions in this
543
550
// / JITDylib.
544
- void addToSearchOrder (JITDylib &JD);
551
+ void addToSearchOrder (JITDylib &JD, bool MatcNonExported = false );
545
552
546
553
// / Replace OldJD with NewJD in the search order if OldJD is present.
547
554
// / Otherwise this operation is a no-op.
548
- void replaceInSearchOrder (JITDylib &OldJD, JITDylib &NewJD);
555
+ void replaceInSearchOrder (JITDylib &OldJD, JITDylib &NewJD,
556
+ bool MatchNonExported = false );
549
557
550
558
// / Remove the given JITDylib from the search order for this JITDylib if it is
551
559
// / present. Otherwise this operation is a no-op.
@@ -554,7 +562,7 @@ class JITDylib {
554
562
// / Do something with the search order (run under the session lock).
555
563
template <typename Func>
556
564
auto withSearchOrderDo (Func &&F)
557
- -> decltype(F(std::declval<const JITDylibList &>()));
565
+ -> decltype(F(std::declval<const JITDylibSearchList &>()));
558
566
559
567
// / Define all symbols provided by the materialization unit to be part of this
560
568
// / JITDylib.
@@ -642,12 +650,12 @@ class JITDylib {
642
650
const SymbolNameSet &Names);
643
651
644
652
void lodgeQuery (std::shared_ptr<AsynchronousSymbolQuery> &Q,
645
- SymbolNameSet &Unresolved, JITDylib *MatchNonExportedInJD ,
646
- bool MatchNonExported, MaterializationUnitList &MUs);
653
+ SymbolNameSet &Unresolved, bool MatchNonExported ,
654
+ MaterializationUnitList &MUs);
647
655
648
656
void lodgeQueryImpl (std::shared_ptr<AsynchronousSymbolQuery> &Q,
649
- SymbolNameSet &Unresolved, JITDylib *MatchNonExportedInJD ,
650
- bool MatchNonExported, MaterializationUnitList &MUs);
657
+ SymbolNameSet &Unresolved, bool MatchNonExported ,
658
+ MaterializationUnitList &MUs);
651
659
652
660
LookupImplActionFlags
653
661
lookupImpl (std::shared_ptr<AsynchronousSymbolQuery> &Q,
@@ -682,7 +690,7 @@ class JITDylib {
682
690
UnmaterializedInfosMap UnmaterializedInfos;
683
691
MaterializingInfosMap MaterializingInfos;
684
692
GeneratorFunction DefGenerator;
685
- JITDylibList SearchOrder;
693
+ JITDylibSearchList SearchOrder;
686
694
};
687
695
688
696
// / An ExecutionSession represents a running JIT program.
@@ -766,6 +774,10 @@ class ExecutionSession {
766
774
767
775
// / Search the given JITDylib list for the given symbols.
768
776
// /
777
+ // / SearchOrder lists the JITDylibs to search. For each dylib, the associated
778
+ // / boolean indicates whether the search should match against non-exported
779
+ // / (hidden visibility) symbols in that dylib (true means match against
780
+ // / non-exported symbols, false means do not match).
769
781
// /
770
782
// / The OnResolve callback will be called once all requested symbols are
771
783
// / resolved, or if an error occurs prior to resolution.
@@ -782,19 +794,9 @@ class ExecutionSession {
782
794
// / dependenant symbols for this query (e.g. it is being made by a top level
783
795
// / client to get an address to call) then the value NoDependenciesToRegister
784
796
// / can be used.
785
- // /
786
- // / If the MatchNonExportedInJD pointer is non-null, then the lookup will find
787
- // / non-exported symbols defined in the JITDylib pointed to by
788
- // / MatchNonExportedInJD.
789
- // / If MatchNonExported is true the lookup will find non-exported symbols in
790
- // / any JITDylib (setting MatchNonExportedInJD is redundant in such cases).
791
- // / If MatchNonExported is false and MatchNonExportedInJD is null,
792
- // / non-exported symbols will never be found.
793
- void lookup (const JITDylibList &JDs, SymbolNameSet Symbols,
797
+ void lookup (const JITDylibSearchList &SearchOrder, SymbolNameSet Symbols,
794
798
SymbolsResolvedCallback OnResolve, SymbolsReadyCallback OnReady,
795
- RegisterDependenciesFunction RegisterDependencies,
796
- JITDylib *MatchNonExportedInJD = nullptr ,
797
- bool MatchNonExported = false );
799
+ RegisterDependenciesFunction RegisterDependencies);
798
800
799
801
// / Blocking version of lookup above. Returns the resolved symbol map.
800
802
// / If WaitUntilReady is true (the default), will not return until all
@@ -803,24 +805,29 @@ class ExecutionSession {
803
805
// / or an error occurs. If WaitUntilReady is false and an error occurs
804
806
// / after resolution, the function will return a success value, but the
805
807
// / error will be reported via reportErrors.
806
- Expected<SymbolMap> lookup (const JITDylibList &JDs ,
808
+ Expected<SymbolMap> lookup (const JITDylibSearchList &SearchOrder ,
807
809
const SymbolNameSet &Symbols,
808
810
RegisterDependenciesFunction RegisterDependencies =
809
811
NoDependenciesToRegister,
810
- bool WaitUntilReady = true ,
811
- JITDylib *MatchNonExportedInJD = nullptr ,
812
- bool MatchNonExported = false );
812
+ bool WaitUntilReady = true );
813
+
814
+ // / Convenience version of blocking lookup.
815
+ // / Searches each of the JITDylibs in the search order in turn for the given
816
+ // / symbol.
817
+ Expected<JITEvaluatedSymbol> lookup (const JITDylibSearchList &SearchOrder,
818
+ SymbolStringPtr Symbol);
813
819
814
820
// / Convenience version of blocking lookup.
815
- // / Performs a single-symbol lookup.
816
- Expected<JITEvaluatedSymbol> lookup ( const JITDylibList &JDs,
817
- SymbolStringPtr Symbol ,
818
- bool MatchNonExported = false );
821
+ // / Searches each of the JITDylibs in the search order in turn for the given
822
+ // / symbol. The search will not find non-exported symbols.
823
+ Expected<JITEvaluatedSymbol> lookup (ArrayRef<JITDylib *> SearchOrder ,
824
+ SymbolStringPtr Symbol );
819
825
820
826
// / Convenience version of blocking lookup.
821
- // / Performs a single-symbol lookup, auto-interning the given symbol name.
822
- Expected<JITEvaluatedSymbol> lookup (const JITDylibList &JDs, StringRef Symbol,
823
- bool MatchNonExported = false );
827
+ // / Searches each of the JITDylibs in the search order in turn for the given
828
+ // / symbol. The search will not find non-exported symbols.
829
+ Expected<JITEvaluatedSymbol> lookup (ArrayRef<JITDylib *> SearchOrder,
830
+ StringRef Symbol);
824
831
825
832
// / Materialize the given unit.
826
833
void dispatchMaterialization (JITDylib &JD,
@@ -866,7 +873,7 @@ class ExecutionSession {
866
873
867
874
template <typename Func>
868
875
auto JITDylib::withSearchOrderDo (Func &&F)
869
- -> decltype(F(std::declval<const JITDylibList &>())) {
876
+ -> decltype(F(std::declval<const JITDylibSearchList &>())) {
870
877
return ES.runSessionLocked ([&]() { return F (SearchOrder); });
871
878
}
872
879
0 commit comments