Skip to content

Only link compiler_rt when dynamic linking #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,28 +198,6 @@ extension DarwinToolchain {
sanitizers: Set<Sanitizer>,
targetInfo: FrontendTargetInfo
) throws -> AbsolutePath {

// FIXME: If we used Clang as a linker instead of going straight to ld,
// we wouldn't have to replicate a bunch of Clang's logic here.

// Always link the regular compiler_rt if it's present. Note that the
// regular libclang_rt.a uses a fat binary for device and simulator; this is
// not true for all compiler_rt build products.
//
// Note: Normally we'd just add this unconditionally, but it's valid to build
// Swift and use it as a linker without building compiler_rt.
let targetTriple = targetInfo.target.triple
let darwinPlatformSuffix =
targetTriple.darwinPlatform!.with(.device)!.libraryNameSuffix
let compilerRTPath =
try clangLibraryPath(
for: targetTriple,
parsedOptions: &parsedOptions)
.appending(component: "libclang_rt.\(darwinPlatformSuffix).a")
if try fileSystem.exists(compilerRTPath) {
commandLine.append(.path(compilerRTPath))
}

// Set up for linking.
let linkerTool: Tool
switch linkerOutputType {
Expand All @@ -229,6 +207,28 @@ extension DarwinToolchain {
fallthrough
case .executable:
linkerTool = .dynamicLinker

// FIXME: If we used Clang as a linker instead of going straight to ld,
// we wouldn't have to replicate a bunch of Clang's logic here.

// Always link the regular compiler_rt if it's present. Note that the
// regular libclang_rt.a uses a fat binary for device and simulator; this is
// not true for all compiler_rt build products.
//
// Note: Normally we'd just add this unconditionally, but it's valid to build
// Swift and use it as a linker without building compiler_rt.
let targetTriple = targetInfo.target.triple
let darwinPlatformSuffix =
targetTriple.darwinPlatform!.with(.device)!.libraryNameSuffix
let compilerRTPath =
try clangLibraryPath(
for: targetTriple,
parsedOptions: &parsedOptions)
.appending(component: "libclang_rt.\(darwinPlatformSuffix).a")
if try fileSystem.exists(compilerRTPath) {
commandLine.append(.path(compilerRTPath))
}

let fSystemArgs = parsedOptions.arguments(for: .F, .Fsystem)
for opt in fSystemArgs {
commandLine.appendFlag(.F)
Expand Down