[Serialization] Limit per-SDK swiftmodule restriction to tagged compilers

Only production compilers should apply the per-SDK restriction on
loading swiftmodules. Use the "is the compiler tagged" information over
a release build to align with the other main swiftmodule loading
restriction accepting only swiftmodules built by the same tag.

Also use an env var SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK to enable
testing this feature in any compilers.
This commit is contained in:
Alexis Laferrière
2022-05-16 10:32:27 -07:00
parent c8059a09e9
commit 3523adbb53
2 changed files with 19 additions and 5 deletions

View File

@@ -309,6 +309,15 @@ static ValidationInfo validateControlBlock(
case control_block::SDK_NAME: {
result.sdkName = blobData;
// Enable this check for tagged compiler or when the
// env var is set (for testing).
static const char* forceDebugPreSDKRestriction =
::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK");
if (version::Version::getCurrentCompilerVersion().empty() &&
!forceDebugPreSDKRestriction) {
break;
}
// 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