Skip to content

Commit

Permalink
Stop using --gc-sections for Wasm target to protect metadata sectio…
Browse files Browse the repository at this point in the history
…ns (#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
  • Loading branch information
kateinoigakukun authored Jul 10, 2022
1 parent 7e61344 commit 3a366cc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,15 @@ public final class ProductBuildDescription {
return ["-Xlinker", "-dead_strip"]
} else if buildParameters.triple.isWindows() {
return ["-Xlinker", "/OPT:REF"]
} else if buildParameters.triple.arch == .wasm32 {
// FIXME: 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
// This workaround is required for not only WASI but also all WebAssembly archs
// using wasm-ld (e.g. wasm32-unknown-unknown). So this branch is conditioned by
// arch == .wasm32
return []
} else {
return ["-Xlinker", "--gc-sections"]
}
Expand Down

0 comments on commit 3a366cc

Please sign in to comment.