Skip to content

Commit db367e9

Browse files
committed
Revert r345077 "[ORC] Change how non-exported symbols are matched during lookup."
Doesn't build on Windows. The call to 'lookup' is ambiguous. Clang and MSVC agree, anyway. http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/787 C:\b\slave\clang-x64-windows-msvc\build\llvm.src\unittests\ExecutionEngine\Orc\CoreAPIsTest.cpp(315): error C2668: 'llvm::orc::ExecutionSession::lookup': ambiguous call to overloaded function C:\b\slave\clang-x64-windows-msvc\build\llvm.src\include\llvm/ExecutionEngine/Orc/Core.h(823): note: could be 'llvm::Expected<llvm::JITEvaluatedSymbol> llvm::orc::ExecutionSession::lookup(llvm::ArrayRef<llvm::orc::JITDylib *>,llvm::orc::SymbolStringPtr)' C:\b\slave\clang-x64-windows-msvc\build\llvm.src\include\llvm/ExecutionEngine/Orc/Core.h(817): note: or 'llvm::Expected<llvm::JITEvaluatedSymbol> llvm::orc::ExecutionSession::lookup(const llvm::orc::JITDylibSearchList &,llvm::orc::SymbolStringPtr)' C:\b\slave\clang-x64-windows-msvc\build\llvm.src\unittests\ExecutionEngine\Orc\CoreAPIsTest.cpp(315): note: while trying to match the argument list '(initializer list, llvm::orc::SymbolStringPtr)' llvm-svn: 345078
1 parent 841796d commit db367e9

File tree

15 files changed

+170
-277
lines changed

15 files changed

+170
-277
lines changed

llvm/include/llvm/ExecutionEngine/JITSymbol.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ class SymbolRef;
4040
/// Represents an address in the target process's address space.
4141
using JITTargetAddress = uint64_t;
4242

43-
/// Convert a JITTargetAddress to a pointer.
44-
template <typename T> T jitTargetAddressToPointer(JITTargetAddress Addr) {
45-
static_assert(std::is_pointer<T>::value, "T must be a pointer type");
46-
uintptr_t IntPtr = static_cast<uintptr_t>(Addr);
47-
assert(IntPtr == Addr && "JITTargetAddress value out of range for uintptr_t");
48-
return reinterpret_cast<T>(IntPtr);
49-
}
50-
51-
template <typename T> JITTargetAddress pointerToJITTargetAddress(T *Ptr) {
52-
return static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(Ptr));
53-
}
54-
5543
/// Flags for symbols in the JIT.
5644
class JITSymbolFlags {
5745
public:

llvm/include/llvm/ExecutionEngine/Orc/Core.h

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ using SymbolFlagsMap = DenseMap<SymbolStringPtr, JITSymbolFlags>;
5454
/// symbols to be obtained for logging.
5555
using SymbolDependenceMap = DenseMap<JITDylib *, SymbolNameSet>;
5656

57-
/// A list of (JITDylib*, bool) pairs.
58-
using JITDylibSearchList = std::vector<std::pair<JITDylib *, bool>>;
57+
/// A list of JITDylib pointers.
58+
using JITDylibList = std::vector<JITDylib *>;
5959

6060
/// Render a SymbolStringPtr.
6161
raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPtr &Sym);
@@ -85,8 +85,8 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolDependenceMap &Deps);
8585
/// Render a MaterializationUnit.
8686
raw_ostream &operator<<(raw_ostream &OS, const MaterializationUnit &MU);
8787

88-
/// Render a JITDylibSearchList.
89-
raw_ostream &operator<<(raw_ostream &OS, const JITDylibSearchList &JDs);
88+
/// Render a JITDylibList.
89+
raw_ostream &operator<<(raw_ostream &OS, const JITDylibList &JDs);
9090

9191
/// Callback to notify client that symbols have been resolved.
9292
using SymbolsResolvedCallback = std::function<void(Expected<SymbolMap>)>;
@@ -351,15 +351,14 @@ using SymbolAliasMap = DenseMap<SymbolStringPtr, SymbolAliasMapEntry>;
351351
class ReExportsMaterializationUnit : public MaterializationUnit {
352352
public:
353353
/// SourceJD is allowed to be nullptr, in which case the source JITDylib is
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.
354+
/// taken to be whatever JITDylib these definitions are materialized in. This
355+
/// is useful for defining aliases within a JITDylib.
357356
///
358357
/// Note: Care must be taken that no sets of aliases form a cycle, as such
359358
/// a cycle will result in a deadlock when any symbol in the cycle is
360359
/// resolved.
361-
ReExportsMaterializationUnit(JITDylib *SourceJD, bool MatchNonExported,
362-
SymbolAliasMap Aliases, VModuleKey K);
360+
ReExportsMaterializationUnit(JITDylib *SourceJD, SymbolAliasMap Aliases,
361+
VModuleKey K);
363362

364363
StringRef getName() const override;
365364

@@ -369,7 +368,6 @@ class ReExportsMaterializationUnit : public MaterializationUnit {
369368
static SymbolFlagsMap extractFlags(const SymbolAliasMap &Aliases);
370369

371370
JITDylib *SourceJD = nullptr;
372-
bool MatchNonExported = false;
373371
SymbolAliasMap Aliases;
374372
};
375373

@@ -387,19 +385,16 @@ class ReExportsMaterializationUnit : public MaterializationUnit {
387385
inline std::unique_ptr<ReExportsMaterializationUnit>
388386
symbolAliases(SymbolAliasMap Aliases, VModuleKey K = VModuleKey()) {
389387
return llvm::make_unique<ReExportsMaterializationUnit>(
390-
nullptr, true, std::move(Aliases), std::move(K));
388+
nullptr, std::move(Aliases), std::move(K));
391389
}
392390

393391
/// Create a materialization unit for re-exporting symbols from another JITDylib
394392
/// 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.
398393
inline std::unique_ptr<ReExportsMaterializationUnit>
399394
reexports(JITDylib &SourceJD, SymbolAliasMap Aliases,
400-
bool MatchNonExported = false, VModuleKey K = VModuleKey()) {
395+
VModuleKey K = VModuleKey()) {
401396
return llvm::make_unique<ReExportsMaterializationUnit>(
402-
&SourceJD, MatchNonExported, std::move(Aliases), std::move(K));
397+
&SourceJD, std::move(Aliases), std::move(K));
403398
}
404399

405400
/// Build a SymbolAliasMap for the common case where you want to re-export
@@ -416,14 +411,13 @@ class ReexportsGenerator {
416411
/// Create a reexports generator. If an Allow predicate is passed, only
417412
/// symbols for which the predicate returns true will be reexported. If no
418413
/// Allow predicate is passed, all symbols will be exported.
419-
ReexportsGenerator(JITDylib &SourceJD, bool MatchNonExported = false,
414+
ReexportsGenerator(JITDylib &SourceJD,
420415
SymbolPredicate Allow = SymbolPredicate());
421416

422417
SymbolNameSet operator()(JITDylib &JD, const SymbolNameSet &Names);
423418

424419
private:
425420
JITDylib &SourceJD;
426-
bool MatchNonExported = false;
427421
SymbolPredicate Allow;
428422
};
429423

@@ -542,18 +536,16 @@ class JITDylib {
542536
/// as the first in the search order (instead of this dylib) ensures that
543537
/// definitions within this dylib resolve to the lazy-compiling stubs,
544538
/// rather than immediately materializing the definitions in this dylib.
545-
void setSearchOrder(JITDylibSearchList NewSearchOrder,
546-
bool SearchThisJITDylibFirst = true,
547-
bool MatchNonExportedInThisDylib = true);
539+
void setSearchOrder(JITDylibList NewSearchOrder,
540+
bool SearchThisJITDylibFirst = true);
548541

549542
/// Add the given JITDylib to the search order for definitions in this
550543
/// JITDylib.
551-
void addToSearchOrder(JITDylib &JD, bool MatcNonExported = false);
544+
void addToSearchOrder(JITDylib &JD);
552545

553546
/// Replace OldJD with NewJD in the search order if OldJD is present.
554547
/// Otherwise this operation is a no-op.
555-
void replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD,
556-
bool MatchNonExported = false);
548+
void replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD);
557549

558550
/// Remove the given JITDylib from the search order for this JITDylib if it is
559551
/// present. Otherwise this operation is a no-op.
@@ -562,7 +554,7 @@ class JITDylib {
562554
/// Do something with the search order (run under the session lock).
563555
template <typename Func>
564556
auto withSearchOrderDo(Func &&F)
565-
-> decltype(F(std::declval<const JITDylibSearchList &>()));
557+
-> decltype(F(std::declval<const JITDylibList &>()));
566558

567559
/// Define all symbols provided by the materialization unit to be part of this
568560
/// JITDylib.
@@ -650,12 +642,12 @@ class JITDylib {
650642
const SymbolNameSet &Names);
651643

652644
void lodgeQuery(std::shared_ptr<AsynchronousSymbolQuery> &Q,
653-
SymbolNameSet &Unresolved, bool MatchNonExported,
654-
MaterializationUnitList &MUs);
645+
SymbolNameSet &Unresolved, JITDylib *MatchNonExportedInJD,
646+
bool MatchNonExported, MaterializationUnitList &MUs);
655647

656648
void lodgeQueryImpl(std::shared_ptr<AsynchronousSymbolQuery> &Q,
657-
SymbolNameSet &Unresolved, bool MatchNonExported,
658-
MaterializationUnitList &MUs);
649+
SymbolNameSet &Unresolved, JITDylib *MatchNonExportedInJD,
650+
bool MatchNonExported, MaterializationUnitList &MUs);
659651

660652
LookupImplActionFlags
661653
lookupImpl(std::shared_ptr<AsynchronousSymbolQuery> &Q,
@@ -690,7 +682,7 @@ class JITDylib {
690682
UnmaterializedInfosMap UnmaterializedInfos;
691683
MaterializingInfosMap MaterializingInfos;
692684
GeneratorFunction DefGenerator;
693-
JITDylibSearchList SearchOrder;
685+
JITDylibList SearchOrder;
694686
};
695687

696688
/// An ExecutionSession represents a running JIT program.
@@ -774,10 +766,6 @@ class ExecutionSession {
774766

775767
/// Search the given JITDylib list for the given symbols.
776768
///
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).
781769
///
782770
/// The OnResolve callback will be called once all requested symbols are
783771
/// resolved, or if an error occurs prior to resolution.
@@ -794,9 +782,19 @@ class ExecutionSession {
794782
/// dependenant symbols for this query (e.g. it is being made by a top level
795783
/// client to get an address to call) then the value NoDependenciesToRegister
796784
/// can be used.
797-
void lookup(const JITDylibSearchList &SearchOrder, SymbolNameSet Symbols,
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,
798794
SymbolsResolvedCallback OnResolve, SymbolsReadyCallback OnReady,
799-
RegisterDependenciesFunction RegisterDependencies);
795+
RegisterDependenciesFunction RegisterDependencies,
796+
JITDylib *MatchNonExportedInJD = nullptr,
797+
bool MatchNonExported = false);
800798

801799
/// Blocking version of lookup above. Returns the resolved symbol map.
802800
/// If WaitUntilReady is true (the default), will not return until all
@@ -805,29 +803,24 @@ class ExecutionSession {
805803
/// or an error occurs. If WaitUntilReady is false and an error occurs
806804
/// after resolution, the function will return a success value, but the
807805
/// error will be reported via reportErrors.
808-
Expected<SymbolMap> lookup(const JITDylibSearchList &SearchOrder,
806+
Expected<SymbolMap> lookup(const JITDylibList &JDs,
809807
const SymbolNameSet &Symbols,
810808
RegisterDependenciesFunction RegisterDependencies =
811809
NoDependenciesToRegister,
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);
810+
bool WaitUntilReady = true,
811+
JITDylib *MatchNonExportedInJD = nullptr,
812+
bool MatchNonExported = false);
819813

820814
/// Convenience version of blocking lookup.
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);
815+
/// Performs a single-symbol lookup.
816+
Expected<JITEvaluatedSymbol> lookup(const JITDylibList &JDs,
817+
SymbolStringPtr Symbol,
818+
bool MatchNonExported = false);
825819

826820
/// Convenience version of blocking lookup.
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);
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);
831824

832825
/// Materialize the given unit.
833826
void dispatchMaterialization(JITDylib &JD,
@@ -873,7 +866,7 @@ class ExecutionSession {
873866

874867
template <typename Func>
875868
auto JITDylib::withSearchOrderDo(Func &&F)
876-
-> decltype(F(std::declval<const JITDylibSearchList &>())) {
869+
-> decltype(F(std::declval<const JITDylibList &>())) {
877870
return ES.runSessionLocked([&]() { return F(SearchOrder); });
878871
}
879872

llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class LLLazyJIT : public LLJIT {
144144
/// LLLazyJIT with the given number of compile threads.
145145
static Expected<std::unique_ptr<LLLazyJIT>>
146146
Create(JITTargetMachineBuilder JTMB, DataLayout DL,
147-
JITTargetAddress ErrorAddr, unsigned NumCompileThreads = 0);
147+
unsigned NumCompileThreads = 0);
148148

149149
/// Set an IR transform (e.g. pass manager pipeline) to run on each function
150150
/// when it is compiled.

llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void CompileOnDemandLayer::emit(MaterializationResponsibility R,
157157
return;
158158
}
159159

160-
R.replace(reexports(PDR.getImplDylib(), std::move(NonCallables), true));
160+
R.replace(reexports(PDR.getImplDylib(), std::move(NonCallables)));
161161
R.replace(lazyReexports(LCTMgr, PDR.getISManager(), PDR.getImplDylib(),
162162
std::move(Callables)));
163163
}
@@ -166,17 +166,10 @@ CompileOnDemandLayer::PerDylibResources &
166166
CompileOnDemandLayer::getPerDylibResources(JITDylib &TargetD) {
167167
auto I = DylibResources.find(&TargetD);
168168
if (I == DylibResources.end()) {
169-
auto &ImplD = getExecutionSession().createJITDylib(
170-
TargetD.getName() + ".impl", false);
171-
TargetD.withSearchOrderDo([&](const JITDylibSearchList &TargetSearchOrder) {
172-
auto NewSearchOrder = TargetSearchOrder;
173-
assert(!NewSearchOrder.empty() &&
174-
NewSearchOrder.front().first == &TargetD &&
175-
NewSearchOrder.front().second == true &&
176-
"TargetD must be at the front of its own search order and match "
177-
"non-exported symbol");
178-
NewSearchOrder.insert(std::next(NewSearchOrder.begin()), {&ImplD, true});
179-
ImplD.setSearchOrder(std::move(NewSearchOrder), false);
169+
auto &ImplD =
170+
getExecutionSession().createJITDylib(TargetD.getName() + ".impl");
171+
TargetD.withSearchOrderDo([&](const JITDylibList &TargetSearchOrder) {
172+
ImplD.setSearchOrder(TargetSearchOrder, false);
180173
});
181174
PerDylibResources PDR(ImplD, BuildIndirectStubsManager());
182175
I = DylibResources.insert(std::make_pair(&TargetD, std::move(PDR))).first;

0 commit comments

Comments
 (0)