[ORC] Hold shared_ptr<SymbolStringPool> in errors containing SymbolStringPtrs.

This allows these error values to remain valid, even if they tear down the JIT
itself.
This commit is contained in:
Lang Hames 2021-09-27 15:25:30 -07:00
parent c42772752a
commit 6fe2e9a9cc
4 changed files with 55 additions and 24 deletions

View File

@ -433,13 +433,16 @@ class SymbolsNotFound : public ErrorInfo<SymbolsNotFound> {
public: public:
static char ID; static char ID;
SymbolsNotFound(SymbolNameSet Symbols); SymbolsNotFound(std::shared_ptr<SymbolStringPool> SSP, SymbolNameSet Symbols);
SymbolsNotFound(SymbolNameVector Symbols); SymbolsNotFound(std::shared_ptr<SymbolStringPool> SSP,
SymbolNameVector Symbols);
std::error_code convertToErrorCode() const override; std::error_code convertToErrorCode() const override;
void log(raw_ostream &OS) const override; void log(raw_ostream &OS) const override;
std::shared_ptr<SymbolStringPool> getSymbolStringPool() { return SSP; }
const SymbolNameVector &getSymbols() const { return Symbols; } const SymbolNameVector &getSymbols() const { return Symbols; }
private: private:
std::shared_ptr<SymbolStringPool> SSP;
SymbolNameVector Symbols; SymbolNameVector Symbols;
}; };
@ -448,12 +451,15 @@ class SymbolsCouldNotBeRemoved : public ErrorInfo<SymbolsCouldNotBeRemoved> {
public: public:
static char ID; static char ID;
SymbolsCouldNotBeRemoved(SymbolNameSet Symbols); SymbolsCouldNotBeRemoved(std::shared_ptr<SymbolStringPool> SSP,
SymbolNameSet Symbols);
std::error_code convertToErrorCode() const override; std::error_code convertToErrorCode() const override;
void log(raw_ostream &OS) const override; void log(raw_ostream &OS) const override;
std::shared_ptr<SymbolStringPool> getSymbolStringPool() { return SSP; }
const SymbolNameSet &getSymbols() const { return Symbols; } const SymbolNameSet &getSymbols() const { return Symbols; }
private: private:
std::shared_ptr<SymbolStringPool> SSP;
SymbolNameSet Symbols; SymbolNameSet Symbols;
}; };
@ -465,13 +471,17 @@ class MissingSymbolDefinitions : public ErrorInfo<MissingSymbolDefinitions> {
public: public:
static char ID; static char ID;
MissingSymbolDefinitions(std::string ModuleName, SymbolNameVector Symbols) MissingSymbolDefinitions(std::shared_ptr<SymbolStringPool> SSP,
: ModuleName(std::move(ModuleName)), Symbols(std::move(Symbols)) {} std::string ModuleName, SymbolNameVector Symbols)
: SSP(std::move(SSP)), ModuleName(std::move(ModuleName)),
Symbols(std::move(Symbols)) {}
std::error_code convertToErrorCode() const override; std::error_code convertToErrorCode() const override;
void log(raw_ostream &OS) const override; void log(raw_ostream &OS) const override;
std::shared_ptr<SymbolStringPool> getSymbolStringPool() { return SSP; }
const std::string &getModuleName() const { return ModuleName; } const std::string &getModuleName() const { return ModuleName; }
const SymbolNameVector &getSymbols() const { return Symbols; } const SymbolNameVector &getSymbols() const { return Symbols; }
private: private:
std::shared_ptr<SymbolStringPool> SSP;
std::string ModuleName; std::string ModuleName;
SymbolNameVector Symbols; SymbolNameVector Symbols;
}; };
@ -484,13 +494,17 @@ class UnexpectedSymbolDefinitions : public ErrorInfo<UnexpectedSymbolDefinitions
public: public:
static char ID; static char ID;
UnexpectedSymbolDefinitions(std::string ModuleName, SymbolNameVector Symbols) UnexpectedSymbolDefinitions(std::shared_ptr<SymbolStringPool> SSP,
: ModuleName(std::move(ModuleName)), Symbols(std::move(Symbols)) {} std::string ModuleName, SymbolNameVector Symbols)
: SSP(std::move(SSP)), ModuleName(std::move(ModuleName)),
Symbols(std::move(Symbols)) {}
std::error_code convertToErrorCode() const override; std::error_code convertToErrorCode() const override;
void log(raw_ostream &OS) const override; void log(raw_ostream &OS) const override;
std::shared_ptr<SymbolStringPool> getSymbolStringPool() { return SSP; }
const std::string &getModuleName() const { return ModuleName; } const std::string &getModuleName() const { return ModuleName; }
const SymbolNameVector &getSymbols() const { return Symbols; } const SymbolNameVector &getSymbols() const { return Symbols; }
private: private:
std::shared_ptr<SymbolStringPool> SSP;
std::string ModuleName; std::string ModuleName;
SymbolNameVector Symbols; SymbolNameVector Symbols;
}; };
@ -1310,6 +1324,11 @@ public:
/// ExecutionSession. /// ExecutionSession.
ExecutorProcessControl &getExecutorProcessControl() { return *EPC; } ExecutorProcessControl &getExecutorProcessControl() { return *EPC; }
/// Get the SymbolStringPool for this instance.
std::shared_ptr<SymbolStringPool> getSymbolStringPool() {
return EPC->getSymbolStringPool();
}
/// Add a symbol name to the SymbolStringPool and return a pointer to it. /// Add a symbol name to the SymbolStringPool and return a pointer to it.
SymbolStringPtr intern(StringRef SymName) { return EPC->intern(SymName); } SymbolStringPtr intern(StringRef SymName) { return EPC->intern(SymName); }

View File

@ -90,14 +90,17 @@ void FailedToMaterialize::log(raw_ostream &OS) const {
OS << "Failed to materialize symbols: " << *Symbols; OS << "Failed to materialize symbols: " << *Symbols;
} }
SymbolsNotFound::SymbolsNotFound(SymbolNameSet Symbols) { SymbolsNotFound::SymbolsNotFound(std::shared_ptr<SymbolStringPool> SSP,
SymbolNameSet Symbols)
: SSP(std::move(SSP)) {
for (auto &Sym : Symbols) for (auto &Sym : Symbols)
this->Symbols.push_back(Sym); this->Symbols.push_back(Sym);
assert(!this->Symbols.empty() && "Can not fail to resolve an empty set"); assert(!this->Symbols.empty() && "Can not fail to resolve an empty set");
} }
SymbolsNotFound::SymbolsNotFound(SymbolNameVector Symbols) SymbolsNotFound::SymbolsNotFound(std::shared_ptr<SymbolStringPool> SSP,
: Symbols(std::move(Symbols)) { SymbolNameVector Symbols)
: SSP(std::move(SSP)), Symbols(std::move(Symbols)) {
assert(!this->Symbols.empty() && "Can not fail to resolve an empty set"); assert(!this->Symbols.empty() && "Can not fail to resolve an empty set");
} }
@ -109,8 +112,9 @@ void SymbolsNotFound::log(raw_ostream &OS) const {
OS << "Symbols not found: " << Symbols; OS << "Symbols not found: " << Symbols;
} }
SymbolsCouldNotBeRemoved::SymbolsCouldNotBeRemoved(SymbolNameSet Symbols) SymbolsCouldNotBeRemoved::SymbolsCouldNotBeRemoved(
: Symbols(std::move(Symbols)) { std::shared_ptr<SymbolStringPool> SSP, SymbolNameSet Symbols)
: SSP(std::move(SSP)), Symbols(std::move(Symbols)) {
assert(!this->Symbols.empty() && "Can not fail to resolve an empty set"); assert(!this->Symbols.empty() && "Can not fail to resolve an empty set");
} }
@ -1333,11 +1337,13 @@ Error JITDylib::remove(const SymbolNameSet &Names) {
// If any of the symbols are not defined, return an error. // If any of the symbols are not defined, return an error.
if (!Missing.empty()) if (!Missing.empty())
return make_error<SymbolsNotFound>(std::move(Missing)); return make_error<SymbolsNotFound>(ES.getSymbolStringPool(),
std::move(Missing));
// If any of the symbols are currently materializing, return an error. // If any of the symbols are currently materializing, return an error.
if (!Materializing.empty()) if (!Materializing.empty())
return make_error<SymbolsCouldNotBeRemoved>(std::move(Materializing)); return make_error<SymbolsCouldNotBeRemoved>(ES.getSymbolStringPool(),
std::move(Materializing));
// Remove the symbols. // Remove the symbols.
for (auto &SymbolMaterializerItrPair : SymbolsToRemove) { for (auto &SymbolMaterializerItrPair : SymbolsToRemove) {
@ -2234,7 +2240,8 @@ Error ExecutionSession::IL_updateCandidatesFor(
// weakly referenced" specific error here to reduce confusion. // weakly referenced" specific error here to reduce confusion.
if (SymI->second.getFlags().hasMaterializationSideEffectsOnly() && if (SymI->second.getFlags().hasMaterializationSideEffectsOnly() &&
SymLookupFlags != SymbolLookupFlags::WeaklyReferencedSymbol) SymLookupFlags != SymbolLookupFlags::WeaklyReferencedSymbol)
return make_error<SymbolsNotFound>(SymbolNameVector({Name})); return make_error<SymbolsNotFound>(getSymbolStringPool(),
SymbolNameVector({Name}));
// If we matched against this symbol but it is in the error state // If we matched against this symbol but it is in the error state
// then bail out and treat it as a failure to materialize. // then bail out and treat it as a failure to materialize.
@ -2422,7 +2429,7 @@ void ExecutionSession::OL_applyQueryPhase1(
} else { } else {
LLVM_DEBUG(dbgs() << "Phase 1 failed with unresolved symbols.\n"); LLVM_DEBUG(dbgs() << "Phase 1 failed with unresolved symbols.\n");
IPLS->fail(make_error<SymbolsNotFound>( IPLS->fail(make_error<SymbolsNotFound>(
IPLS->DefGeneratorCandidates.getSymbolNames())); getSymbolStringPool(), IPLS->DefGeneratorCandidates.getSymbolNames()));
} }
} }
@ -2492,7 +2499,8 @@ void ExecutionSession::OL_completeLookup(
dbgs() << "error: " dbgs() << "error: "
"required, but symbol is has-side-effects-only\n"; "required, but symbol is has-side-effects-only\n";
}); });
return make_error<SymbolsNotFound>(SymbolNameVector({Name})); return make_error<SymbolsNotFound>(getSymbolStringPool(),
SymbolNameVector({Name}));
} }
// If we matched against this symbol but it is in the error state // If we matched against this symbol but it is in the error state
@ -2606,7 +2614,8 @@ void ExecutionSession::OL_completeLookup(
if (!IPLS->LookupSet.empty()) { if (!IPLS->LookupSet.empty()) {
LLVM_DEBUG(dbgs() << "Failing due to unresolved symbols\n"); LLVM_DEBUG(dbgs() << "Failing due to unresolved symbols\n");
return make_error<SymbolsNotFound>(IPLS->LookupSet.getSymbolNames()); return make_error<SymbolsNotFound>(getSymbolStringPool(),
IPLS->LookupSet.getSymbolNames());
} }
// Record whether the query completed. // Record whether the query completed.
@ -2733,7 +2742,8 @@ void ExecutionSession::OL_completeLookupFlags(
if (!IPLS->LookupSet.empty()) { if (!IPLS->LookupSet.empty()) {
LLVM_DEBUG(dbgs() << "Failing due to unresolved symbols\n"); LLVM_DEBUG(dbgs() << "Failing due to unresolved symbols\n");
return make_error<SymbolsNotFound>(IPLS->LookupSet.getSymbolNames()); return make_error<SymbolsNotFound>(getSymbolStringPool(),
IPLS->LookupSet.getSymbolNames());
} }
LLVM_DEBUG(dbgs() << "Succeded, result = " << Result << "\n"); LLVM_DEBUG(dbgs() << "Succeded, result = " << Result << "\n");

View File

@ -93,7 +93,7 @@ SelfExecutorProcessControl::lookupSymbols(ArrayRef<LookupRequest> Request) {
// FIXME: Collect all failing symbols before erroring out. // FIXME: Collect all failing symbols before erroring out.
SymbolNameVector MissingSymbols; SymbolNameVector MissingSymbols;
MissingSymbols.push_back(Sym); MissingSymbols.push_back(Sym);
return make_error<SymbolsNotFound>(std::move(MissingSymbols)); return make_error<SymbolsNotFound>(SSP, std::move(MissingSymbols));
} }
R.back().push_back(pointerToJITTargetAddress(Addr)); R.back().push_back(pointerToJITTargetAddress(Addr));
} }

View File

@ -279,8 +279,9 @@ public:
// If there were missing symbols then report the error. // If there were missing symbols then report the error.
if (!MissingSymbols.empty()) if (!MissingSymbols.empty())
return make_error<MissingSymbolDefinitions>(G.getName(), return make_error<MissingSymbolDefinitions>(
std::move(MissingSymbols)); Layer.getExecutionSession().getSymbolStringPool(), G.getName(),
std::move(MissingSymbols));
// If there are more definitions than expected, add them to the // If there are more definitions than expected, add them to the
// ExtraSymbols vector. // ExtraSymbols vector.
@ -293,8 +294,9 @@ public:
// If there were extra definitions then report the error. // If there were extra definitions then report the error.
if (!ExtraSymbols.empty()) if (!ExtraSymbols.empty())
return make_error<UnexpectedSymbolDefinitions>(G.getName(), return make_error<UnexpectedSymbolDefinitions>(
std::move(ExtraSymbols)); Layer.getExecutionSession().getSymbolStringPool(), G.getName(),
std::move(ExtraSymbols));
} }
if (auto Err = MR->notifyResolved(InternedResult)) if (auto Err = MR->notifyResolved(InternedResult))