Skip to content

Commit b94e899

Browse files
committed
[Unix] Go back to only checking the runtime resource path for swiftrt.o
1 parent 82510b8 commit b94e899

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,13 @@ extension GenericUnixToolchain {
181181
}
182182

183183
if !isEmbeddedEnabled && !parsedOptions.hasArgument(.nostartfiles) {
184-
let rsrc: VirtualPath
185-
// Prefer the swiftrt.o runtime file from the SDK if it's specified.
186-
if let sdk = targetInfo.sdkPath {
187-
let swiftDir: String
188-
if staticStdlib || staticExecutable {
189-
swiftDir = "swift_static"
190-
} else {
191-
swiftDir = "swift"
192-
}
193-
rsrc = VirtualPath.lookup(sdk.path).appending(components: "usr", "lib", swiftDir)
194-
} else {
195-
rsrc = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
196-
}
197-
let platform: String = targetTriple.platformName() ?? ""
198-
let architecture: String = majorArchitectureName(for: targetTriple)
199-
commandLine.appendPath(rsrc.appending(components: platform, architecture, "swiftrt.o"))
184+
let swiftrtPath = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
185+
.appending(
186+
components: targetTriple.platformName() ?? "",
187+
String(majorArchitectureName(for: targetTriple)),
188+
"swiftrt.o"
189+
)
190+
commandLine.appendPath(swiftrtPath)
200191
}
201192

202193
// If we are linking statically, we need to add all

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7390,14 +7390,10 @@ final class SwiftDriverTests: XCTestCase {
73907390

73917391
func testRelativeResourceDir() throws {
73927392
do {
7393-
// Reset the environment to avoid 'SDKROOT' influencing the
7394-
// linux driver paths and taking the priority over the resource directory.
7395-
var env = ProcessEnv.vars
7396-
env["SDKROOT"] = nil
73977393
var driver = try Driver(args: ["swiftc",
73987394
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
73997395
"foo.swift",
7400-
"-resource-dir", "resource/dir"], env: env)
7396+
"-resource-dir", "resource/dir"])
74017397
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
74027398

74037399
let compileJob = plannedJobs[0]
@@ -7412,7 +7408,7 @@ final class SwiftDriverTests: XCTestCase {
74127408
}
74137409
}
74147410

7415-
func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws {
7411+
func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws {
74167412
do {
74177413
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
74187414
var env = ProcessEnv.vars
@@ -7426,7 +7422,7 @@ final class SwiftDriverTests: XCTestCase {
74267422
XCTAssertEqual(compileJob.kind, .compile)
74277423
let linkJob = plannedJobs[1]
74287424
XCTAssertEqual(linkJob.kind, .link)
7429-
try XCTAssertJobInvocationMatches(linkJob, toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false))
7425+
try XCTAssertJobInvocationMatches(linkJob, toPathOption("resource/dir/linux/x86_64/swiftrt.o"))
74307426
}
74317427
}
74327428

0 commit comments

Comments
 (0)