Skip to content

Commit 3a366cc

Browse files
Stop using --gc-sections for Wasm target to protect metadata sections (#5638)
Now wasm-ld strips data segments referenced through __start/__stop symbols during GC, and it removes Swift metadata sections like swift5_protocols We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain)) to LLVM and wasm-ld. For now, just disable section GC for Wasm target. Context: llvm/llvm-project#55839 https://reviews.llvm.org/D126950#3558050
1 parent 7e61344 commit 3a366cc

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
@@ -1294,6 +1294,15 @@ public final class ProductBuildDescription {
12941294
return ["-Xlinker", "-dead_strip"]
12951295
} else if buildParameters.triple.isWindows() {
12961296
return ["-Xlinker", "/OPT:REF"]
1297+
} else if buildParameters.triple.arch == .wasm32 {
1298+
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
1299+
// during GC, and it removes Swift metadata sections like swift5_protocols
1300+
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
1301+
// to LLVM and wasm-ld
1302+
// This workaround is required for not only WASI but also all WebAssembly archs
1303+
// using wasm-ld (e.g. wasm32-unknown-unknown). So this branch is conditioned by
1304+
// arch == .wasm32
1305+
return []
12971306
} else {
12981307
return ["-Xlinker", "--gc-sections"]
12991308
}

0 commit comments

Comments
 (0)