Skip to content

Commit 1a6c835

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

2 files changed

Lines changed: 10 additions & 23 deletions

File tree

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,13 @@ extension GenericUnixToolchain {
185185
}
186186

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

206197
// 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
@@ -8147,14 +8147,10 @@ final class SwiftDriverTests: XCTestCase {
81478147

81488148
func testRelativeResourceDir() throws {
81498149
do {
8150-
// Reset the environment to avoid 'SDKROOT' influencing the
8151-
// linux driver paths and taking the priority over the resource directory.
8152-
var env = ProcessEnv.block
8153-
env["SDKROOT"] = nil
81548150
var driver = try Driver(args: ["swiftc",
81558151
"-target", "x86_64-unknown-linux", "-lto=llvm-thin",
81568152
"foo.swift",
8157-
"-resource-dir", "resource/dir"], env: env)
8153+
"-resource-dir", "resource/dir"])
81588154
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
81598155

81608156
let compileJob = plannedJobs[0]
@@ -8169,7 +8165,7 @@ final class SwiftDriverTests: XCTestCase {
81698165
}
81708166
}
81718167

8172-
func testSDKDirLinuxPrioritizedOverRelativeResourceDirForLinkingSwiftRT() throws {
8168+
func testRelativeResourceDirLinuxPrioritizedOverSDKDirForLinkingSwiftRT() throws {
81738169
do {
81748170
let sdkRoot = try testInputsPath.appending(component: "mock-sdk.sdk")
81758171
var env = ProcessEnv.block
@@ -8183,7 +8179,7 @@ final class SwiftDriverTests: XCTestCase {
81838179
XCTAssertEqual(compileJob.kind, .compile)
81848180
let linkJob = plannedJobs[1]
81858181
XCTAssertEqual(linkJob.kind, .link)
8186-
try XCTAssertJobInvocationMatches(linkJob, toPathOption(sdkRoot.pathString + "/usr/lib/swift/linux/x86_64/swiftrt.o", isRelative: false))
8182+
try XCTAssertJobInvocationMatches(linkJob, toPathOption("resource/dir/linux/x86_64/swiftrt.o"))
81878183
}
81888184
}
81898185

0 commit comments

Comments
 (0)