Skip to content

Commit 989a078

Browse files
authored
Revert 'Remove --gc-sections for all targets for now (#5708)' (#5738)
1 parent 78b812b commit 989a078

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,12 +1321,17 @@ public final class ProductBuildDescription {
13211321
return ["-Xlinker", "-dead_strip"]
13221322
} else if buildParameters.triple.isWindows() {
13231323
return ["-Xlinker", "/OPT:REF"]
1324-
} else {
1325-
// FIXME: wasm-ld / ld.lld strips data segments referenced through __start/__stop symbols
1324+
} else if buildParameters.triple.arch == .wasm32 {
1325+
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
13261326
// during GC, and it removes Swift metadata sections like swift5_protocols
13271327
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
13281328
// to LLVM and wasm-ld
1329+
// This workaround is required for not only WASI but also all WebAssembly archs
1330+
// using wasm-ld (e.g. wasm32-unknown-unknown). So this branch is conditioned by
1331+
// arch == .wasm32
13291332
return []
1333+
} else {
1334+
return ["-Xlinker", "--gc-sections"]
13301335
}
13311336
}
13321337
}

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", "-rpath=$ORIGIN",
405+
"-Xlinker", "--gc-sections", "-Xlinker", "-rpath=$ORIGIN",
406406
"@/path/to/build/release/exe.product/Objects.LinkFileList",
407407
"-target", defaultTargetTriple,
408408
])

0 commit comments

Comments
 (0)