Skip to content

Commit ca764e9

Browse files
committed
Only change if -sysroot is specified
1 parent 1a6c835 commit ca764e9

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

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

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

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

0 commit comments

Comments
 (0)