Skip to content

Commit e9cd5dc

Browse files
authored
Remove --gc-sections for all targets for now (#5707)
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 73133d3 commit e9cd5dc

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,17 +1334,12 @@ public final class ProductBuildDescription {
13341334
return ["-Xlinker", "-dead_strip"]
13351335
} else if buildParameters.triple.isWindows() {
13361336
return ["-Xlinker", "/OPT:REF"]
1337-
} else if buildParameters.triple.arch == .wasm32 {
1338-
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
1337+
} else {
1338+
// FIXME: wasm-ld / ld.lld strips data segments referenced through __start/__stop symbols
13391339
// during GC, and it removes Swift metadata sections like swift5_protocols
13401340
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
13411341
// to LLVM and wasm-ld
1342-
// This workaround is required for not only WASI but also all WebAssembly archs
1343-
// using wasm-ld (e.g. wasm32-unknown-unknown). So this branch is conditioned by
1344-
// arch == .wasm32
13451342
return []
1346-
} else {
1347-
return ["-Xlinker", "--gc-sections"]
13481343
}
13491344
}
13501345
}

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ final class BuildPlanTests: XCTestCase {
446446
"-o", buildPath.appending(components: "exe").pathString,
447447
"-module-name", "exe",
448448
"-emit-executable",
449-
"-Xlinker", "--gc-sections",
450449
"-Xlinker", "-rpath=$ORIGIN",
451450
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
452451
"-target", defaultTargetTriple,

0 commit comments

Comments
 (0)