Skip to content

Commit

Permalink
Work around lld 13+ issue with --gc-sections for ELF by adding -z nos…
Browse files Browse the repository at this point in the history
…tart-stop-gc
  • Loading branch information
finagolfin authored and keith committed Aug 19, 2022
1 parent 21d9350 commit c771555
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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 @@ -2071,7 +2071,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

0 comments on commit c771555

Please sign in to comment.