Skip to content

Commit dc176bd

Browse files
Rollup merge of rust-lang#146795 - alexcrichton:wasm-limit-rdylib-exports, r=bjorn3
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.
2 parents 29005cb + f354d93 commit dc176bd

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,11 @@ impl<'a> Linker for GccLinker<'a> {
845845
self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error });
846846
}
847847
self.link_arg("--dynamic-list").link_arg(path);
848+
} else if self.sess.target.is_like_wasm {
849+
self.link_arg("--no-export-dynamic");
850+
for (sym, _) in symbols {
851+
self.link_arg("--export").link_arg(sym);
852+
}
848853
} else {
849854
// Write an LD version script
850855
let res: io::Result<()> = try {

compiler/rustc_target/src/spec/base/wasm.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ pub(crate) fn options() -> TargetOptions {
8181
// threaded model which will legalize atomics to normal operations.
8282
singlethread: true,
8383

84-
// Symbol visibility takes care of this for the WebAssembly.
85-
// Additionally the only known linker, LLD, doesn't support the script
86-
// arguments just yet
87-
limit_rdylib_exports: false,
88-
8984
// we use the LLD shipped with the Rust toolchain by default
9085
linker: Some("rust-lld".into()),
9186
linker_flavor: LinkerFlavor::WasmLld(Cc::No),

0 commit comments

Comments
 (0)