[Serialization] Allow loading modules built on some SDK variants

When restricting loading swiftmodules to the SDK used to build them,
an exception should be made for modules built against an SDK that is a subset
of the SDK used when loading the module. In such a case, the swiftmodule
file is more reliable.

rdar://92827584
This commit is contained in:
Alexis Laferrière
2022-05-05 16:34:16 -07:00
parent 2266a5705c
commit 1757061342
2 changed files with 18 additions and 3 deletions

View File

@@ -156,11 +156,18 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
return error(status);
}
// The loaded module was built with a compatible SDK if either:
// * it was the same SDK
// * or one who's name is a prefix of the clients' SDK name. This expects
// that a module built with macOS11 can be used with the macOS11.secret SDK.
// This is generally the case as SDKs with suffixes are a superset of the
// short SDK name equivalent. While this is accepted, this is still not a
// recommended configuration and may lead to unreadable swiftmodules.
StringRef moduleSDK = Core->SDKName;
StringRef clientSDK = ctx.LangOpts.SDKName;
if (ctx.SearchPathOpts.EnableSameSDKCheck &&
!moduleSDK.empty() && !clientSDK.empty() &&
moduleSDK != clientSDK) {
!clientSDK.startswith(moduleSDK)) {
status = Status::SDKMismatch;
return error(status);
}