Skip to content

Commit 481991a

Browse files
committed
SwiftDriver: use swiftrtT.obj for static linking on Windows
Use the PIE registrar on Windows when building with the static standard library. This is important as we will have a loaclly defined implementation of `swift_addNewDSOImage` and thus cannot use the PIC version which expects that to be dynamically linked (imported).
1 parent 75d47e4 commit 481991a

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

Sources/SwiftDriver/Jobs/WindowsToolchain+LinkerSupport.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ extension WindowsToolchain {
192192
.appending(components: targetTriple.platformName() ?? "",
193193
architecture(for: targetTriple))
194194
}
195-
commandLine.appendPath(rsrc.appending(component: "swiftrt.obj"))
195+
196+
if parsedOptions.hasArgument(.staticStdlib) {
197+
commandLine.appendPath(rsrc.appending(component: "swiftrtT.obj"))
198+
} else {
199+
commandLine.appendPath(rsrc.appending(component: "swiftrt.obj"))
200+
}
196201
}
197202

198203
commandLine.append(contentsOf: inputs.compactMap { (input: TypedVirtualPath) -> Job.ArgTemplate? in

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8706,6 +8706,21 @@ final class SwiftDriverTests: XCTestCase {
87068706
XCTAssertJobInvocationMatches(job, .path(.absolute(SDKROOT.appending(components: "usr", "lib", "swift", platform, arch, "swiftrt.obj"))))
87078707
}
87088708

8709+
do {
8710+
var env = ProcessEnv.block
8711+
env["SDKROOT"] = SDKROOT.nativePathString(escaped: false)
8712+
8713+
var driver = try Driver(args: [
8714+
"swiftc", "-emit-library", "-o", "library.dll", "library.obj", "-static-stdlib",
8715+
], env: env)
8716+
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
8717+
XCTAssertEqual(jobs.count, 1)
8718+
let job = jobs.first!
8719+
XCTAssertEqual(job.kind, .link)
8720+
XCTAssertJobInvocationMatches(job, .path(.absolute(SDKROOT.appending(components: "usr", "lib", "swift", platform, arch, "swiftrtT.obj"))))
8721+
XCTAssertFalse(job.commandLine.contains(.path(.absolute(SDKROOT.appending(components: "usr", "lib", "swift", platform, arch, "swiftrt.obj")))))
8722+
}
8723+
87098724
do {
87108725
var env = ProcessEnv.block
87118726
env["SDKROOT"] = SDKROOT.nativePathString(escaped: false)

0 commit comments

Comments
 (0)