1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[ORC] Add errors for missing and extraneous symbol definitions.

This patch adds new errors and error checking to the ObjectLinkingLayer to
catch cases where a compiled or loaded object either:
(1) Contains definitions not covered by its responsibility set, or
(2) Is missing definitions that are covered by its responsibility set.

Proir to this patch providing the correct set of definitions was treated as
an API contract requirement, however this requires that the client be confident
in the correctness of the whole compiler / object-cache pipeline and results
in difficult-to-debug assertions upon failure. Treating this as a recoverable
error results in clearer diagnostics.

The performance overhead of this check is one comparison of densemap keys
(symbol string pointers) per linking object, which is minimal. If this overhead
ever becomes a problem we can add the check under a flag that can be turned off
if the client fully trusts the rest of the pipeline.
This commit is contained in:
Lang Hames 2020-02-21 17:38:42 -08:00
parent 8263acd297
commit 46f1687baa
5 changed files with 95 additions and 1 deletions

View File

@ -424,6 +424,44 @@ private:
SymbolNameSet Symbols;
};
/// Errors of this type should be returned if a module fails to include
/// definitions that are claimed by the module's associated
/// MaterializationResponsibility. If this error is returned it is indicative of
/// a broken transformation / compiler / object cache.
class MissingSymbolDefinitions : public ErrorInfo<MissingSymbolDefinitions> {
public:
static char ID;
MissingSymbolDefinitions(std::string ModuleName, SymbolNameVector Symbols)
: ModuleName(std::move(ModuleName)), Symbols(std::move(Symbols)) {}
std::error_code convertToErrorCode() const override;
void log(raw_ostream &OS) const override;
const std::string &getModuleName() const { return ModuleName; }
const SymbolNameVector &getSymbols() const { return Symbols; }
private:
std::string ModuleName;
SymbolNameVector Symbols;
};
/// Errors of this type should be returned if a module contains definitions for
/// symbols that are not claimed by the module's associated
/// MaterializationResponsibility. If this error is returned it is indicative of
/// a broken transformation / compiler / object cache.
class UnexpectedSymbolDefinitions : public ErrorInfo<UnexpectedSymbolDefinitions> {
public:
static char ID;
UnexpectedSymbolDefinitions(std::string ModuleName, SymbolNameVector Symbols)
: ModuleName(std::move(ModuleName)), Symbols(std::move(Symbols)) {}
std::error_code convertToErrorCode() const override;
void log(raw_ostream &OS) const override;
const std::string &getModuleName() const { return ModuleName; }
const SymbolNameVector &getSymbols() const { return Symbols; }
private:
std::string ModuleName;
SymbolNameVector Symbols;
};
/// Tracks responsibility for materialization, and mediates interactions between
/// MaterializationUnits and JDs.
///

View File

@ -37,7 +37,9 @@ enum class OrcErrorCode : int {
UnexpectedRPCCall,
UnexpectedRPCResponse,
UnknownErrorCodeFromRemote,
UnknownResourceHandle
UnknownResourceHandle,
MissingSymbolDefinitions,
UnexpectedSymbolDefinitions,
};
std::error_code orcError(OrcErrorCode ErrCode);

View File

@ -144,6 +144,8 @@ namespace orc {
char FailedToMaterialize::ID = 0;
char SymbolsNotFound::ID = 0;
char SymbolsCouldNotBeRemoved::ID = 0;
char MissingSymbolDefinitions::ID = 0;
char UnexpectedSymbolDefinitions::ID = 0;
RegisterDependenciesFunction NoDependenciesToRegister =
RegisterDependenciesFunction();
@ -352,6 +354,24 @@ void SymbolsCouldNotBeRemoved::log(raw_ostream &OS) const {
OS << "Symbols could not be removed: " << Symbols;
}
std::error_code MissingSymbolDefinitions::convertToErrorCode() const {
return orcError(OrcErrorCode::MissingSymbolDefinitions);
}
void MissingSymbolDefinitions::log(raw_ostream &OS) const {
OS << "Missing definitions in module " << ModuleName
<< ": " << Symbols;
}
std::error_code UnexpectedSymbolDefinitions::convertToErrorCode() const {
return orcError(OrcErrorCode::UnexpectedSymbolDefinitions);
}
void UnexpectedSymbolDefinitions::log(raw_ostream &OS) const {
OS << "Unexpected definitions in module " << ModuleName
<< ": " << Symbols;
}
AsynchronousSymbolQuery::AsynchronousSymbolQuery(
const SymbolLookupSet &Symbols, SymbolState RequiredState,
SymbolsResolvedCallback NotifyComplete)

View File

@ -148,6 +148,36 @@ public:
if (const auto &InitSym = MR.getInitializerSymbol())
InternedResult[InitSym] = JITEvaluatedSymbol();
{
// Check that InternedResult matches up with MR.getSymbols().
// This guards against faulty transformations / compilers / object caches.
if (InternedResult.size() > MR.getSymbols().size()) {
SymbolNameVector ExtraSymbols;
for (auto &KV : InternedResult)
if (!MR.getSymbols().count(KV.first))
ExtraSymbols.push_back(KV.first);
ES.reportError(
make_error<UnexpectedSymbolDefinitions>(G.getName(),
std::move(ExtraSymbols)));
MR.failMaterialization();
return;
}
SymbolNameVector MissingSymbols;
for (auto &KV : MR.getSymbols())
if (!InternedResult.count(KV.first))
MissingSymbols.push_back(KV.first);
if (!MissingSymbols.empty()) {
ES.reportError(
make_error<MissingSymbolDefinitions>(G.getName(),
std::move(MissingSymbols)));
MR.failMaterialization();
return;
}
}
if (auto Err = MR.notifyResolved(InternedResult)) {
Layer.getExecutionSession().reportError(std::move(Err));
MR.failMaterialization();

View File

@ -61,6 +61,10 @@ public:
"(Use StringError to get error message)";
case OrcErrorCode::UnknownResourceHandle:
return "Unknown resource handle";
case OrcErrorCode::MissingSymbolDefinitions:
return "MissingSymbolsDefinitions";
case OrcErrorCode::UnexpectedSymbolDefinitions:
return "UnexpectedSymbolDefinitions";
}
llvm_unreachable("Unhandled error code");
}