mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
ClangImporter: import SwiftShims properly for static linking
When building against the static standard library, we should define `SWIFT_STATIC_STDLIB` to indicate to the shims that the declarations should be giving hidden visibility and default DLL storage. This is required to ensure that these symbols are known to be `dso_local` when compiling to avoid an unnecessary look up through the PLT/GOT or the indirection through the synthesized `__imp_` symbol and the IAT. This corrects a number of incorrect code generation cases on Windows with the static standard library.
This commit is contained in:
@@ -321,6 +321,8 @@ namespace swift {
|
||||
/// Flags for use by tests
|
||||
///
|
||||
|
||||
bool UseStaticStandardLibrary = false;
|
||||
|
||||
/// Enable Objective-C Runtime interop code generation and build
|
||||
/// configuration options.
|
||||
bool EnableObjCInterop = true;
|
||||
|
||||
@@ -682,6 +682,9 @@ void importer::getNormalInvocationArguments(
|
||||
}
|
||||
}
|
||||
|
||||
if (LangOpts.UseStaticStandardLibrary)
|
||||
invocationArgStrs.push_back("-DSWIFT_STATIC_STDLIB");
|
||||
|
||||
// If we support SendingArgsAndResults, set the -D flag to signal that it
|
||||
// is supported.
|
||||
if (LangOpts.hasFeature(Feature::SendingArgsAndResults))
|
||||
|
||||
@@ -1571,6 +1571,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
ModuleInterfaceOpts.PublicFlags.IgnorableFlags +=
|
||||
" " + printFormalCxxInteropVersion(Opts);
|
||||
|
||||
Opts.UseStaticStandardLibrary = Args.hasArg(OPT_use_static_resource_dir);
|
||||
Opts.EnableObjCInterop =
|
||||
Args.hasFlag(OPT_enable_objc_interop, OPT_disable_objc_interop,
|
||||
Target.isOSDarwin() && !Opts.hasFeature(Feature::Embedded));
|
||||
|
||||
5
test/ClangImporter/static_stdlib.swift
Normal file
5
test/ClangImporter/static_stdlib.swift
Normal file
@@ -0,0 +1,5 @@
|
||||
// RUN: %swift_frontend_plain -parse-stdlib -typecheck %s -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-DYNAMIC
|
||||
// RUN: %swift_frontend_plain -parse-stdlib -use-static-resource-dir -typecheck %s -dump-clang-diagnostics 2>&1 | %FileCheck %s -check-prefix CHECK-STATIC
|
||||
|
||||
// CHECK-DYNAMIC-NOT: clang importer cc1 args: {{.*}} '-D' 'SWIFT_STATIC_STDLIB'
|
||||
// CHECK-STATIC: clang importer cc1 args: {{.*}} '-D' 'SWIFT_STATIC_STDLIB'
|
||||
Reference in New Issue
Block a user