Skip to content

Revert "Revert "Only add '-fobjc-link-runtime' to the linker invocation when the driver is invoked with '-link-objc-runtime'"" #1227

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
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,14 @@ extension DarwinToolchain {
commandLine.appendPath(VirtualPath.lookup(sdkPath))
}

// -link-objc-runtime also implies -fobjc-link-runtime
if parsedOptions.hasFlag(positive: .linkObjcRuntime,
negative: .noLinkObjcRuntime,
default: false) {
commandLine.appendFlag("-fobjc-link-runtime")
}

commandLine.appendFlags(
"-fobjc-link-runtime",
"-lobjc",
"-lSystem"
)

Expand Down
35 changes: 35 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ final class SwiftDriverTests: XCTestCase {

XCTAssertFalse(cmd.contains(.flag("-static")))
XCTAssertFalse(cmd.contains(.flag("-shared")))
// Handling of '-lobjc' is now in the Clang linker driver.
XCTAssertFalse(cmd.contains(.flag("-lobjc")))
}

do {
Expand Down Expand Up @@ -1728,6 +1730,39 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertFalse(cmd.contains(.flag("-shared")))
}

do {
// -fobjc-link-runtime default
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15"], env: env)
let plannedJobs = try driver.planBuild()
XCTAssertEqual(3, plannedJobs.count)
let linkJob = plannedJobs[2]
XCTAssertEqual(linkJob.kind, .link)
let cmd = linkJob.commandLine
XCTAssertFalse(cmd.contains(.flag("-fobjc-link-runtime")))
}

do {
// -fobjc-link-runtime enable
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-link-objc-runtime"], env: env)
let plannedJobs = try driver.planBuild()
XCTAssertEqual(3, plannedJobs.count)
let linkJob = plannedJobs[2]
XCTAssertEqual(linkJob.kind, .link)
let cmd = linkJob.commandLine
XCTAssertTrue(cmd.contains(.flag("-fobjc-link-runtime")))
}

do {
// -fobjc-link-runtime disable override
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-link-objc-runtime", "-no-link-objc-runtime"], env: env)
let plannedJobs = try driver.planBuild()
XCTAssertEqual(3, plannedJobs.count)
let linkJob = plannedJobs[2]
XCTAssertEqual(linkJob.kind, .link)
let cmd = linkJob.commandLine
XCTAssertFalse(cmd.contains(.flag("-fobjc-link-runtime")))
}

do {
// Xlinker flags
// Ensure that Xlinker flags are passed as such to the clang linker invocation.
Expand Down