Skip to content

Commit 6059538

Browse files
committed
[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.
1 parent e1d3bb7 commit 6059538

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ static ValidationInfo validateControlBlock(
309309
case control_block::SDK_NAME: {
310310
result.sdkName = blobData;
311311

312+
// Enable this check for tagged compiler or when the
313+
// env var is set (for testing).
314+
static const char* forceDebugPreSDKRestriction =
315+
::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK");
316+
if (version::Version::getCurrentCompilerVersion().empty() &&
317+
!forceDebugPreSDKRestriction) {
318+
break;
319+
}
320+
312321
// The loaded module was built with a compatible SDK if either:
313322
// * it was the same SDK
314323
// * or one who's name is a prefix of the clients' SDK name. This expects

test/Serialization/restrict-swiftmodule-to-sdk.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,31 @@
66
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -target-sdk-name A -o %t/build -parse-stdlib -module-cache-path %t/cache
77

88
/// Building Client against SDK A should work fine as expected.
9-
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name A -I %t/build -parse-stdlib -module-cache-path %t/cache
9+
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
10+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name A -I %t/build -parse-stdlib -module-cache-path %t/cache
1011

1112
/// Build Client against SDK B, this should fail at loading Lib against a different SDK than A.
12-
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name B -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck %s -check-prefix=CHECK-AvsB
13+
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
14+
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name B -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck %s -check-prefix=CHECK-AvsB
1315
// CHECK-AvsB: cannot load module 'Lib' built with SDK 'A' when using SDK 'B': {{.*}}Lib.swiftmodule
1416

1517
/// Build Client against SDK A.Secret, this should accept the SDK as being a super set of A.
16-
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name A.Secret -I %t/build -parse-stdlib -module-cache-path %t/cache
18+
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
19+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name A.Secret -I %t/build -parse-stdlib -module-cache-path %t/cache
1720

1821
/// Build Lib against SDK C.Secret and Client against SDK C, this should be rejected.
1922
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -target-sdk-name C.Secret -o %t/build -parse-stdlib -module-cache-path %t/cache
20-
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name C -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck %s -check-prefix=CHECK-C
23+
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
24+
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name C -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck %s -check-prefix=CHECK-C
2125
// CHECK-C: cannot load module 'Lib' built with SDK 'C.Secret' when using SDK 'C': {{.*}}Lib.swiftmodule
2226

2327
/// Build a resilient Lib against SDK A, and a client against SDK B.
2428
/// This should succeed after rebuilding from the swiftinterface.
2529
// RUN: %empty-directory(%t/cache)
2630
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -target-sdk-name A -o %t/build -parse-stdlib -module-cache-path %t/cache \
2731
// RUN: -enable-library-evolution -emit-module-interface-path %t/build/Lib.swiftinterface
28-
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name B -I %t/build -parse-stdlib -module-cache-path %t/cache \
32+
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK=true \
33+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -swift-version 5 -target-sdk-name B -I %t/build -parse-stdlib -module-cache-path %t/cache \
2934
// RUN: -Rmodule-interface-rebuild 2>&1 | %FileCheck %s -check-prefix=CHECK-AvsB-REBUILD
3035
// CHECK-AvsB-REBUILD: remark: rebuilding module 'Lib' from interface
3136

0 commit comments

Comments
 (0)