Skip to content

Commit f0e87d2

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

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

+7-16
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,13 @@ extension GenericUnixToolchain {
168168
}
169169

170170
if !isEmbeddedEnabled && !parsedOptions.hasArgument(.nostartfiles) {
171-
let rsrc: VirtualPath
172-
// Prefer the swiftrt.o runtime file from the SDK if it's specified.
173-
if let sdk = targetInfo.sdkPath {
174-
let swiftDir: String
175-
if staticStdlib || staticExecutable {
176-
swiftDir = "swift_static"
177-
} else {
178-
swiftDir = "swift"
179-
}
180-
rsrc = VirtualPath.lookup(sdk.path).appending(components: "usr", "lib", swiftDir)
181-
} else {
182-
rsrc = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
183-
}
184-
let platform: String = targetTriple.platformName() ?? ""
185-
let architecture: String = majorArchitectureName(for: targetTriple)
186-
commandLine.appendPath(rsrc.appending(components: platform, architecture, "swiftrt.o"))
171+
let swiftrtPath = VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
172+
.appending(
173+
components: targetTriple.platformName() ?? "",
174+
String(majorArchitectureName(for: targetTriple)),
175+
"swiftrt.o"
176+
)
177+
commandLine.appendPath(swiftrtPath)
187178
}
188179

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

Tests/SwiftDriverTests/SwiftDriverTests.swift

+3-7
Original file line numberDiff line numberDiff line change
@@ -7159,14 +7159,10 @@ final class SwiftDriverTests: XCTestCase {
71597159

71607160
func testRelativeResourceDir() throws {
71617161
do {
7162-
// Reset the environment to avoid 'SDKROOT' influencing the
7163-
// linux driver paths and taking the priority over the resource directory.
7164-
var env = ProcessEnv.vars
7165-
env["SDKROOT"] = nil
71667162
var driver = try Driver(args: ["swiftc",
71677163
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
71687164
"foo.swift",
7169-
"-resource-dir", "resource/dir"], env: env)
7165+
"-resource-dir", "resource/dir"])
71707166
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
71717167

71727168
let compileJob = plannedJobs[0]
@@ -7181,7 +7177,7 @@ final class SwiftDriverTests: XCTestCase {
71817177
}
71827178
}
71837179

7184-
func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws {
7180+
func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws {
71857181
do {
71867182
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
71877183
var env = ProcessEnv.vars
@@ -7195,7 +7191,7 @@ final class SwiftDriverTests: XCTestCase {
71957191
XCTAssertEqual(compileJob.kind, .compile)
71967192
let linkJob = plannedJobs[1]
71977193
XCTAssertEqual(linkJob.kind, .link)
7198-
try XCTAssertJobInvocationMatches(linkJob, toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false))
7194+
try XCTAssertJobInvocationMatches(linkJob, toPathOption("resource/dir/linux/x86_64/swiftrt.o"))
71997195
}
72007196
}
72017197

0 commit comments

Comments
 (0)