Files
swift-mirror/test/IRGen/windows-linking.swift
Saleem Abdulrasool 8da2c377da IRGen: add support for static linking on Windows
This adjusts the IRGen layer to accommodate the Windows linking model.
We assume dynamic linking by default.  The static linking is enabled by
passing `-static` to the driver, which forwards it to the frontend when
building the module statically.  This has already been required when
generating libraries, however, the non-Windows targets are more
forgiving and let it work.  On those platforms, using this hint would
allow for more efficient code generation, reducing load times and some
runtime penalties from the PLT and GOT references formed to symbols
which are module local.

This corrects static linking on Windows, which is one of the last few
items that are missing on Windows.  It also takes advantage of the hint
for the one peculiar difference between Windows and non-Windows:
protocol conformances that span module boundaries are not available as a
constant.  However, when statically linking, we can enable those
conformances to be statically resolved.  This should enable the last
known pattern to work when using static linking.

This support requires further work in the Swift Package Manager to
actually enable building libraries properly.  However, when building
with CMake, this should be sufficient to enable static linking.
2021-05-02 10:02:11 -07:00

66 lines
2.0 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -target x86_64-unknown-windows-msvc -parse-as-library -parse-stdlib -static -emit-module -emit-module-path %t/module.swiftmodule -module-name module -DMODULE %s
// RUN: %target-swift-frontend -target x86_64-unknown-windows-msvc -parse-as-library -parse-stdlib -S -emit-ir %s -module-name main -o - -I%t | %FileCheck %s -check-prefix CHECK-STATIC
// RUN: %target-swift-frontend -target x86_64-unknown-windows-msvc -parse-as-library -parse-stdlib -emit-module -emit-module-path %t/module.swiftmodule -module-name module -DMODULE %s
// RUN: %target-swift-frontend -target x86_64-unknown-windows-msvc -parse-as-library -parse-stdlib -S -emit-ir %s -module-name main -o - -I%t | %FileCheck %s -check-prefix CHECK-SHARED
#if MODULE
public struct S {}
public var value: S {
S()
}
public func f(_ s: S) {}
public protocol P {
}
public enum E: P {
}
#else
import module
protocol Q: P {
}
extension E: Q {
}
@main
struct Entry {
public static func main() {
f(value)
}
}
#endif
// Ensure that static linking does not mark the entries as being indirected
// through the IAT.
// CHECK-STATIC: @"$s6module1EO4main1QADWP" = hidden constant [2 x i8*] [
// CHECK-STATIC-SAME: i8* bitcast (%swift.protocol_conformance_descriptor* @"$s6module1EO4main1QADMc" to i8*),
// CHECK-STATIC-SAME: i8* bitcast (i8** @"$s6module1EOAA1PAAWP" to i8*)
// CHECK-STATIC-SAME: ]
// CHECK-STATIC: declare swiftcc void @"$s6module5valueAA1SVvg"()
// CHECK-STATIC: declare swiftcc void @"$s6module1fyyAA1SVF"()
// Ensure that shared linking does mark the functions as being indirected
// through the IAT.
// CHECK-SHARED: @"$s6module1EO4main1QADWP" = hidden constant [2 x i8*] [
// CHECK-SHARED-SAME: i8* bitcast (%swift.protocol_conformance_descriptor* @"$s6module1EO4main1QADMc" to i8*),
// CHECK-SHARED-SAME: i8* null
// CHECK-SHARED-SAME: ]
// CHECK-SHARED: declare dllimport swiftcc void @"$s6module5valueAA1SVvg"()
// CHECK-SHARED: declare dllimport swiftcc void @"$s6module1fyyAA1SVF"()