Skip to content

Commit c085564

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

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

72307230
func testRelativeResourceDir() throws {
72317231
do {
7232-
// Reset the environment to avoid 'SDKROOT' influencing the
7233-
// linux driver paths and taking the priority over the resource directory.
7234-
var env = ProcessEnv.block
7235-
env["SDKROOT"] = nil
72367232
var driver = try Driver(args: ["swiftc",
72377233
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
72387234
"foo.swift",
7239-
"-resource-dir", "resource/dir"], env: env)
7235+
"-resource-dir", "resource/dir"])
72407236
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
72417237

72427238
let compileJob = plannedJobs[0]
@@ -7251,7 +7247,7 @@ final class SwiftDriverTests: XCTestCase {
72517247
}
72527248
}
72537249

7254-
func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws {
7250+
func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws {
72557251
do {
72567252
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
72577253
var env = ProcessEnv.block
@@ -7265,7 +7261,7 @@ final class SwiftDriverTests: XCTestCase {
72657261
XCTAssertEqual(compileJob.kind, .compile)
72667262
let linkJob = plannedJobs[1]
72677263
XCTAssertEqual(linkJob.kind, .link)
7268-
try XCTAssertJobInvocationMatches(linkJob, toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false))
7264+
try XCTAssertJobInvocationMatches(linkJob, toPathOption("resource/dir/linux/x86_64/swiftrt.o"))
72697265
}
72707266
}
72717267

0 commit comments

Comments
 (0)