Skip to content

Commit aa908ad

Browse files
committed
Improve flags usage
1 parent e270919 commit aa908ad

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Sources/SwiftDriver/Jobs/WindowsToolchain+LinkerSupport.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension WindowsToolchain {
2828

2929
switch linkerOutputType {
3030
case .dynamicLibrary:
31-
commandLine.appendFlags("-Xlinker", "-dll")
31+
commandLine.appendFlags("-shared")
3232
fallthrough
3333
case .executable:
3434
if !targetTriple.triple.isEmpty {
@@ -75,6 +75,11 @@ extension WindowsToolchain {
7575
}
7676
commandLine.appendFlag("-fuse-ld=\(linker)")
7777

78+
// Rely on `-libc` to correctly identify the MSVC Runtime Library. We use
79+
// `-nostartfiles` as that limits the difference to just the
80+
// `-defaultlib:libcmt` which is passed unconditionally with the `clang`
81+
// driver rather than the `clang-cl` driver.
82+
commandLine.appendFlag("-nostartfiles")
7883
if let crt = parsedOptions.getLastArgument(.libc) {
7984
switch crt.asSingle {
8085
case "MT": commandLine.appendFlags("-Xlinker", "-defaultlib:libcmt")
@@ -143,9 +148,6 @@ extension WindowsToolchain {
143148
commandLine.appendFlag("-lswiftCore")
144149
}
145150

146-
// Explicitly pass the target to the linker
147-
commandLine.appendFlags("-target", targetTriple.triple)
148-
149151
// Delegate to Clang for sanitizers. It will figure out the correct linker
150152
// options.
151153
if linkerOutputType == .executable && !sanitizers.isEmpty {
@@ -178,6 +180,7 @@ extension WindowsToolchain {
178180
commandLine.appendPath(outputFile)
179181
return clangPath
180182
case .staticLibrary:
183+
commandLine.appendFlags("-nologo")
181184
commandLine.append(.joinedOptionAndPath("-out:", outputFile))
182185
commandLine.append(contentsOf: inputs.map { .path($0.file) })
183186
return try getToolPath(.staticLinker(lto))

0 commit comments

Comments
 (0)