Skip to content

Commit d52a7f7

Browse files
committed
Only add '-fobjc-link-runtime' to the linker invocation when the driver is invoked with '-link-objc-runtime'
1 parent 590f1d0 commit d52a7f7

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,14 @@ extension DarwinToolchain {
214214
commandLine.appendPath(VirtualPath.lookup(sdkPath))
215215
}
216216

217+
// -link-objc-runtime also implies -fobjc-link-runtime
218+
if parsedOptions.hasFlag(positive: .linkObjcRuntime,
219+
negative: .noLinkObjcRuntime,
220+
default: false) {
221+
commandLine.appendFlag("-fobjc-link-runtime")
222+
}
223+
217224
commandLine.appendFlags(
218-
"-fobjc-link-runtime",
219225
"-lobjc",
220226
"-lSystem"
221227
)

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,39 @@ final class SwiftDriverTests: XCTestCase {
17281728
XCTAssertFalse(cmd.contains(.flag("-shared")))
17291729
}
17301730

1731+
do {
1732+
// -fobjc-link-runtime default
1733+
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15"], env: env)
1734+
let plannedJobs = try driver.planBuild()
1735+
XCTAssertEqual(3, plannedJobs.count)
1736+
let linkJob = plannedJobs[2]
1737+
XCTAssertEqual(linkJob.kind, .link)
1738+
let cmd = linkJob.commandLine
1739+
XCTAssertFalse(cmd.contains(.flag("-fobjc-link-runtime")))
1740+
}
1741+
1742+
do {
1743+
// -fobjc-link-runtime enable
1744+
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-link-objc-runtime"], env: env)
1745+
let plannedJobs = try driver.planBuild()
1746+
XCTAssertEqual(3, plannedJobs.count)
1747+
let linkJob = plannedJobs[2]
1748+
XCTAssertEqual(linkJob.kind, .link)
1749+
let cmd = linkJob.commandLine
1750+
XCTAssertTrue(cmd.contains(.flag("-fobjc-link-runtime")))
1751+
}
1752+
1753+
do {
1754+
// -fobjc-link-runtime disable override
1755+
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-link-objc-runtime", "-no-link-objc-runtime"], env: env)
1756+
let plannedJobs = try driver.planBuild()
1757+
XCTAssertEqual(3, plannedJobs.count)
1758+
let linkJob = plannedJobs[2]
1759+
XCTAssertEqual(linkJob.kind, .link)
1760+
let cmd = linkJob.commandLine
1761+
XCTAssertFalse(cmd.contains(.flag("-fobjc-link-runtime")))
1762+
}
1763+
17311764
do {
17321765
// Xlinker flags
17331766
// Ensure that Xlinker flags are passed as such to the clang linker invocation.

0 commit comments

Comments
 (0)