Skip to content

Commit 93c2344

Browse files
Stop using --gc-sections for Wasm target to protect metadata sections (#5638) (#5648)
1 parent 956a01e commit 93c2344

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,15 @@ 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
1295+
// during GC, and it removes Swift metadata sections like swift5_protocols
1296+
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
1297+
// 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
1301+
return []
12931302
} else {
12941303
return ["-Xlinker", "--gc-sections"]
12951304
}

0 commit comments

Comments
 (0)