diff --git a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift index fa2bd8132..3e9382e2a 100644 --- a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift +++ b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift @@ -181,22 +181,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 147e8c5a7..5388afd5b 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -7229,14 +7229,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.block - 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] @@ -7251,7 +7247,7 @@ final class SwiftDriverTests: XCTestCase { } } - func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws { + func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws { do { let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk") var env = ProcessEnv.block @@ -7265,7 +7261,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")) } }