[Serialization] Restrict loading swiftmodule files to the builder's SDK

Serialize the canonical name of the SDK used when building a swiftmodule
file and use it to ensure that the swiftmodule file is loaded only with
the same SDK. The SDK name must be passed down from the frontend.

This will report unsupported configurations like:

- Installing roots between incompatible SDKs without deleting the
swiftmodule files.
- Having multiple targets in the same project using different SDKs.
- Loading a swiftmodule created with a newer SDK (and stdlib) with an
older SDK.

All of these lead to hard to investigate deserialization failures and
this change should detect them early, before reaching a deserialization
failure.

rdar://78048939
This commit is contained in:
Alexis Laferrière
2021-06-01 16:57:40 -07:00
parent 7c653e4fec
commit c38d1773d2
16 changed files with 85 additions and 3 deletions

View File

@@ -66,7 +66,11 @@ enum class Status {
TargetIncompatible,
/// The module file was built for a target newer than the current target.
TargetTooNew
TargetTooNew,
/// The module file was built with a different SDK than the one in use
/// to build the client.
SDKMismatch
};
/// Returns true if the data looks like it contains a serialized AST.
@@ -80,6 +84,7 @@ struct ValidationInfo {
StringRef miscVersion = {};
version::Version compatibilityVersion = {};
llvm::VersionTuple userModuleVersion;
StringRef sdkName = {};
size_t bytes = 0;
Status status = Status::Malformed;
};