diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2025-09-19 13:16:38 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2025-09-19 13:16:38 -0700 |
| commit | f354d93abe1c404544c18585861518cf03188b0e (patch) | |
| tree | e36b5838d7d0bd955d83c759b5f6ca6f39402f15 /compiler/rustc_codegen_ssa | |
| parent | 59043567a5cf12800e1457c36ad6a6b0fa02c6b6 (diff) | |
| download | rust-f354d93abe1c404544c18585861518cf03188b0e.tar.gz rust-f354d93abe1c404544c18585861518cf03188b0e.zip | |
Enable `limit_rdylib_exports` on wasm targets
This commit updates the target specification of wasm targets to set the `limit_rdylib_exports` value to `true` like it is on other native platforms. This was originally not implemented long ago as `wasm-ld` didn't have options for symbol exports, but since then it's grown a `--export` flag and such to control this. A custom case is needed in the linker implementation to handle wasm targets as `wasm-ld` doesn't support linker scripts used on other targets, but other than that the implementation is straightforward. The goal of this commit is enable building dynamic libraries on `wasm32-wasip2` which don't export every single symbol in the Rust standard library. Currently, without otherwise control over symbol visibility, all symbols end up being exported which generates excessively large binaries because `--gc-sections` ends up doing nothing as it's all exported anyway.
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index a2efd420a32..b90be2faa08 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -845,6 +845,11 @@ impl<'a> Linker for GccLinker<'a> { self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error }); } self.link_arg("--dynamic-list").link_arg(path); + } else if self.sess.target.is_like_wasm { + self.link_arg("--no-export-dynamic"); + for (sym, _) in symbols { + self.link_arg("--export").link_arg(sym); + } } else { // Write an LD version script let res: io::Result<()> = try { |
