Skip to content

[5.7] Work around lld 13+ issue with --gc-sections for ELF by adding -z nostart-stop-gc #1158

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
Aug 23, 2022
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
11 changes: 11 additions & 0 deletions Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ extension GenericUnixToolchain {
#else
commandLine.appendFlag("-fuse-ld=\(linker)")
#endif
// Starting with lld 13, Swift stopped working with the lld
// --gc-sections implementation for ELF, unless -z nostart-stop-gc is
// also passed to lld:
//
// https://reviews.llvm.org/D96914
if linker == "lld" || linker.hasSuffix("ld.lld") {
commandLine.appendFlag(.Xlinker)
commandLine.appendFlag("-z")
commandLine.appendFlag(.Xlinker)
commandLine.appendFlag("nostart-stop-gc")
}
}

// Configure the toolchain.
Expand Down
3 changes: 2 additions & 1 deletion Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,8 @@ final class SwiftDriverTests: XCTestCase {
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
let lastJob = plannedJobs.last!
XCTAssertTrue(lastJob.tool.name.contains("clang"))
XCTAssertTrue(lastJob.commandLine.contains(.flag("-fuse-ld=lld")))
XCTAssertTrue(lastJob.commandLine.contains(subsequence: [.flag("-fuse-ld=lld"),
.flag("-Xlinker"), .flag("-z"), .flag("-Xlinker"), .flag("nostart-stop-gc")]))
}
}

Expand Down