diff --git a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift index e130803ff..277ccf74d 100644 --- a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift +++ b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift @@ -168,22 +168,13 @@ extension GenericUnixToolchain { } if !isEmbeddedEnabled && !parsedOptions.hasArgument(.nostartfiles) { - let rsrc: VirtualPath - // Prefer the swiftrt.o runtime file from the SDK if it's specified. - if let sdk = targetInfo.sdkPath { - let swiftDir: String - if staticStdlib || staticExecutable { - swiftDir = "swift_static" - } else { - swiftDir = "swift" - } - rsrc = VirtualPath.lookup(sdk.path).appending(components: "usr", "lib", swiftDir) - } else { - rsrc = VirtualPath.lookup(targetInfo.runtimeResourcePath.path) - } - let platform: String = targetTriple.platformName() ?? "" - let architecture: String = majorArchitectureName(for: targetTriple) - commandLine.appendPath(rsrc.appending(components: platform, architecture, "swiftrt.o")) + let swiftrtPath = VirtualPath.lookup(targetInfo.runtimeResourcePath.path) + .appending( + components: targetTriple.platformName() ?? "", + String(majorArchitectureName(for: targetTriple)), + "swiftrt.o" + ) + commandLine.appendPath(swiftrtPath) } // If we are linking statically, we need to add all diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index dea028256..5beea814c 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -7159,14 +7159,10 @@ final class SwiftDriverTests: XCTestCase { func testRelativeResourceDir() throws { do { - // Reset the environment to avoid 'SDKROOT' influencing the - // linux driver paths and taking the priority over the resource directory. - var env = ProcessEnv.vars - env["SDKROOT"] = nil var driver = try Driver(args: ["swiftc", "-target", "x86_64-unknown-linux", "-lto=llvm-thin", "foo.swift", - "-resource-dir", "resource/dir"], env: env) + "-resource-dir", "resource/dir"]) let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs() let compileJob = plannedJobs[0] @@ -7181,7 +7177,7 @@ final class SwiftDriverTests: XCTestCase { } } - func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws { + func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws { do { let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk") var env = ProcessEnv.vars @@ -7195,7 +7191,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(compileJob.kind, .compile) let linkJob = plannedJobs[1] XCTAssertEqual(linkJob.kind, .link) - try XCTAssertJobInvocationMatches(linkJob, toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false)) + try XCTAssertJobInvocationMatches(linkJob, toPathOption("resource/dir/linux/x86_64/swiftrt.o")) } }