Skip to content

Commit e26fbeb

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

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
@@ -7277,14 +7277,10 @@ final class SwiftDriverTests: XCTestCase {
72777277

72787278
func testRelativeResourceDir() throws {
72797279
do {
7280-
// Reset the environment to avoid 'SDKROOT' influencing the
7281-
// linux driver paths and taking the priority over the resource directory.
7282-
var env = ProcessEnv.block
7283-
env["SDKROOT"] = nil
72847280
var driver = try Driver(args: ["swiftc",
72857281
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
72867282
"foo.swift",
7287-
"-resource-dir", "resource/dir"], env: env)
7283+
"-resource-dir", "resource/dir"])
72887284
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
72897285

72907286
let compileJob = plannedJobs[0]
@@ -7299,7 +7295,7 @@ final class SwiftDriverTests: XCTestCase {
72997295
}
73007296
}
73017297

7302-
func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws {
7298+
func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws {
73037299
do {
73047300
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
73057301
var env = ProcessEnv.block
@@ -7313,7 +7309,7 @@ final class SwiftDriverTests: XCTestCase {
73137309
XCTAssertEqual(compileJob.kind, .compile)
73147310
let linkJob = plannedJobs[1]
73157311
XCTAssertEqual(linkJob.kind, .link)
7316-
try XCTAssertJobInvocationMatches(linkJob, toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false))
7312+
try XCTAssertJobInvocationMatches(linkJob, toPathOption("resource/dir/linux/x86_64/swiftrt.o"))
73177313
}
73187314
}
73197315

0 commit comments

Comments
 (0)