Skip to content

Commit 7890466

Browse files
committed
Only link compiler_rt when dynamic linking
1 parent df4b912 commit 7890466

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,6 @@ extension DarwinToolchain {
198198
sanitizers: Set<Sanitizer>,
199199
targetInfo: FrontendTargetInfo
200200
) throws -> AbsolutePath {
201-
202-
// FIXME: If we used Clang as a linker instead of going straight to ld,
203-
// we wouldn't have to replicate a bunch of Clang's logic here.
204-
205-
// Always link the regular compiler_rt if it's present. Note that the
206-
// regular libclang_rt.a uses a fat binary for device and simulator; this is
207-
// not true for all compiler_rt build products.
208-
//
209-
// Note: Normally we'd just add this unconditionally, but it's valid to build
210-
// Swift and use it as a linker without building compiler_rt.
211-
let targetTriple = targetInfo.target.triple
212-
let darwinPlatformSuffix =
213-
targetTriple.darwinPlatform!.with(.device)!.libraryNameSuffix
214-
let compilerRTPath =
215-
try clangLibraryPath(
216-
for: targetTriple,
217-
parsedOptions: &parsedOptions)
218-
.appending(component: "libclang_rt.\(darwinPlatformSuffix).a")
219-
if try fileSystem.exists(compilerRTPath) {
220-
commandLine.append(.path(compilerRTPath))
221-
}
222-
223201
// Set up for linking.
224202
let linkerTool: Tool
225203
switch linkerOutputType {
@@ -229,6 +207,28 @@ extension DarwinToolchain {
229207
fallthrough
230208
case .executable:
231209
linkerTool = .dynamicLinker
210+
211+
// FIXME: If we used Clang as a linker instead of going straight to ld,
212+
// we wouldn't have to replicate a bunch of Clang's logic here.
213+
214+
// Always link the regular compiler_rt if it's present. Note that the
215+
// regular libclang_rt.a uses a fat binary for device and simulator; this is
216+
// not true for all compiler_rt build products.
217+
//
218+
// Note: Normally we'd just add this unconditionally, but it's valid to build
219+
// Swift and use it as a linker without building compiler_rt.
220+
let targetTriple = targetInfo.target.triple
221+
let darwinPlatformSuffix =
222+
targetTriple.darwinPlatform!.with(.device)!.libraryNameSuffix
223+
let compilerRTPath =
224+
try clangLibraryPath(
225+
for: targetTriple,
226+
parsedOptions: &parsedOptions)
227+
.appending(component: "libclang_rt.\(darwinPlatformSuffix).a")
228+
if try fileSystem.exists(compilerRTPath) {
229+
commandLine.append(.path(compilerRTPath))
230+
}
231+
232232
let fSystemArgs = parsedOptions.arguments(for: .F, .Fsystem)
233233
for opt in fSystemArgs {
234234
commandLine.appendFlag(.F)

0 commit comments

Comments
 (0)