Skip to content

Commit 80eac27

Browse files
authored
[5.7] Remove --gc-sections for all targets for now (#5708)
Similar to the comment here about wasm-ld, lld recently switched a default that broke this for all elf targets. This is a low risk fix since we weren't passing this flag before either. People who really need this behavior can still pass something like `-Xlinker --gc-sections -Xlinker -z -Xlinker nostart-stop-gc`
1 parent fba40af commit 80eac27

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,17 +1290,12 @@ public final class ProductBuildDescription {
12901290
return ["-Xlinker", "-dead_strip"]
12911291
} else if buildParameters.triple.isWindows() {
12921292
return ["-Xlinker", "/OPT:REF"]
1293-
} else if buildParameters.triple.arch == .wasm32 {
1294-
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
1293+
} else {
1294+
// FIXME: wasm-ld / ld.lld strips data segments referenced through __start/__stop symbols
12951295
// during GC, and it removes Swift metadata sections like swift5_protocols
12961296
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
12971297
// to LLVM and wasm-ld
1298-
// This workaround is required for not only WASI but also all WebAssembly archs
1299-
// using wasm-ld (e.g. wasm32-unknown-unknown). So this branch is conditioned by
1300-
// arch == .wasm32
13011298
return []
1302-
} else {
1303-
return ["-Xlinker", "--gc-sections"]
13041299
}
13051300
}
13061301
}

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ final class BuildPlanTests: XCTestCase {
402402
XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), [
403403
"/fake/path/to/swiftc", "-g", "-L", "/path/to/build/release",
404404
"-o", "/path/to/build/release/exe", "-module-name", "exe", "-emit-executable",
405-
"-Xlinker", "--gc-sections", "-Xlinker", "-rpath=$ORIGIN",
405+
"-Xlinker", "-rpath=$ORIGIN",
406406
"@/path/to/build/release/exe.product/Objects.LinkFileList",
407407
"-target", defaultTargetTriple,
408408
])

0 commit comments

Comments
 (0)