From b660d20c853f1d222402135d2021efff8a02f610 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 27 Nov 2024 09:58:36 -0800 Subject: [PATCH] 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: #77756 --- lib/Frontend/ModuleInterfaceBuilder.cpp | 1 + .../Inputs/SR77756/dynamic.swiftinterface | 7 +++++++ .../Inputs/SR77756/static.swiftinterface | 6 ++++++ test/ModuleInterface/swift-interface-compile.swift | 14 ++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 test/ModuleInterface/Inputs/SR77756/dynamic.swiftinterface create mode 100644 test/ModuleInterface/Inputs/SR77756/static.swiftinterface create mode 100644 test/ModuleInterface/swift-interface-compile.swift diff --git a/lib/Frontend/ModuleInterfaceBuilder.cpp b/lib/Frontend/ModuleInterfaceBuilder.cpp index aedf96593c893..0a1236511acd7 100644 --- a/lib/Frontend/ModuleInterfaceBuilder.cpp +++ b/lib/Frontend/ModuleInterfaceBuilder.cpp @@ -279,6 +279,7 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface( // optimization pipeline. SerializationOptions SerializationOpts; std::string OutPathStr = OutputPath.str(); + SerializationOpts.StaticLibrary = FEOpts.Static; SerializationOpts.OutputPath = OutPathStr.c_str(); SerializationOpts.ModuleLinkName = FEOpts.ModuleLinkName; SerializationOpts.AutolinkForceLoad = diff --git a/test/ModuleInterface/Inputs/SR77756/dynamic.swiftinterface b/test/ModuleInterface/Inputs/SR77756/dynamic.swiftinterface new file mode 100644 index 0000000000000..3d142ff015d51 --- /dev/null +++ b/test/ModuleInterface/Inputs/SR77756/dynamic.swiftinterface @@ -0,0 +1,7 @@ +// swift-interface-format-version: 1.0 +// swift-module-flags: -module-name dynamic + +import Swift + +public func f() {} + diff --git a/test/ModuleInterface/Inputs/SR77756/static.swiftinterface b/test/ModuleInterface/Inputs/SR77756/static.swiftinterface new file mode 100644 index 0000000000000..2d07d768f0db4 --- /dev/null +++ b/test/ModuleInterface/Inputs/SR77756/static.swiftinterface @@ -0,0 +1,6 @@ +// swift-interface-format-version: 1.0 +// swift-module-flags: -static -module-name static + +import Swift + +public func f() {} diff --git a/test/ModuleInterface/swift-interface-compile.swift b/test/ModuleInterface/swift-interface-compile.swift new file mode 100644 index 0000000000000..ab562e18b5cc2 --- /dev/null +++ b/test/ModuleInterface/swift-interface-compile.swift @@ -0,0 +1,14 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend -module-cache-path %t/mcp -I %S/Inputs/SR77756 -c %s -o /dev/null -D STATIC +// RUN: llvm-bcanalyzer -dump %t/mcp/static-*.swiftmodule | %FileCheck %s -check-prefix CHECK-STATIC +// RUN: %target-swift-frontend -module-cache-path %t/mcp -I %S/Inputs/SR77756 -c %s -o /dev/null +// RUN: llvm-bcanalyzer -dump %t/mcp/dynamic-*.swiftmodule | %FileCheck %s -check-prefix CHECK-DYNAMIC + +#if STATIC +import `static` +#else +import `dynamic` +#endif + +// CHECK-STATIC: IS_STATIC +// CHECK-DYNAMIC-NOT: IS_STATIC