Skip to content

Commit 18f669b

Browse files
authored
Revert 'Remove --gc-sections for all targets for now (#5707)' (#5735)
It should work with lld now that the lld flag '-z nostart-stop-gc' was added with swiftlang/swift#60544 and swiftlang/swift-driver#1153.
1 parent 208f929 commit 18f669b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,12 +1334,17 @@ public final class ProductBuildDescription {
13341334
return ["-Xlinker", "-dead_strip"]
13351335
} else if buildParameters.triple.isWindows() {
13361336
return ["-Xlinker", "/OPT:REF"]
1337-
} else {
1338-
// FIXME: wasm-ld / ld.lld strips data segments referenced through __start/__stop symbols
1337+
} else if buildParameters.triple.arch == .wasm32 {
1338+
// FIXME: wasm-ld 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
13421345
return []
1346+
} else {
1347+
return ["-Xlinker", "--gc-sections"]
13431348
}
13441349
}
13451350
}

Tests/BuildTests/BuildPlanTests.swift

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

0 commit comments

Comments
 (0)