Skip to content

Commit e2c5139

Browse files
committed
Frontend: re-serialise static library status
When compiling the swiftmodule from the textual swift interface, ensure that we re-serialise the static or dynamic nature of the module. This is required for proper code generation where the static and dynamic linking is material to symbolic references. This also opens the possibility of optimizations on other platforms via internalisation of the symbols. Fixes: swiftlang#77756
1 parent b13544e commit e2c5139

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
279279
// optimization pipeline.
280280
SerializationOptions SerializationOpts;
281281
std::string OutPathStr = OutputPath.str();
282+
SerializationOpts.StaticLibrary = FEOpts.Static;
282283
SerializationOpts.OutputPath = OutPathStr.c_str();
283284
SerializationOpts.ModuleLinkName = FEOpts.ModuleLinkName;
284285
SerializationOpts.AutolinkForceLoad =
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name dynamic
3+
4+
import Swift
5+
6+
public func f() {}
7+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -static -module-name static
3+
4+
import Swift
5+
6+
public func f() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -module-cache-path %t/mcp -I %S/Inputs -c %s -o /dev/null -D STATIC
3+
// RUN: llvm-bcanalyzer -dump %t/mcp/static-*.swiftmodule | %FileCheck %s -check-prefix CHECK-STATIC
4+
// RUN: %target-swift-frontend -module-cache-path %t/mcp -I %S/Inputs -c %s -o /dev/null
5+
// RUN: llvm-bcanalyzer -dump %t/mcp/dynamic-*.swiftmodule | %FileCheck %s -check-prefix CHECK-DYNAMIC
6+
7+
#if STATIC
8+
import `static`
9+
#else
10+
import `dynamic`
11+
#endif
12+
13+
// CHECK-STATIC: IS_STATIC
14+
// CHECK-DYNAMIC-NOT: IS_STATIC

0 commit comments

Comments
 (0)