-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Enable limit_rdylib_exports
on wasm targets
#146795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
These commits modify compiler targets. Some changes occurred in compiler/rustc_codegen_ssa |
Should this be done for all wasm targets, or just WASI targets? |
I'd ideally like to have this applied to all wasm targets as I can't think of a reason that WASI would be different than non-WASI here. This is already applied to Emscripten targets, for example, through the That being said I can also say that I'm not confident this won't break someone. In my experience if you change anything about how linking is done it inevitably breaks someone. My hope is that use cases for wasm dynamic libraries are niche-enough in Rust right now that this hypothetical breakage doesn't manifest, but I am not certain of this. I also don't actually know what would break off the top of my head, just that things like this tend to break someone. |
Aside from symbols exported by C static libraries linked into a rust dylib (which likely isn't done by anyone for wasm32-unknown-unknown anyway as until recently C code couldn't be used on that target at all), all symbols this would cause to not be exported are not callable anyway due to having mangled names and Rust never calling them anyway. |
r? bjorn3 |
@bors r+ |
Rollup of 5 pull requests Successful merges: - #146795 (Enable `limit_rdylib_exports` on wasm targets) - #146828 (fix a crash in rustdoc merge finalize without input file) - #146848 (Add x86_64-unknown-motor (Motor OS) tier 3 target) - #146884 (Fix modification check of `rustdoc-json-types`) - #146887 (Remove unused #![feature(get_mut_unchecked)] in Rc and Arc examples) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #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.
Rollup of 5 pull requests Successful merges: - rust-lang/rust#146795 (Enable `limit_rdylib_exports` on wasm targets) - rust-lang/rust#146828 (fix a crash in rustdoc merge finalize without input file) - rust-lang/rust#146848 (Add x86_64-unknown-motor (Motor OS) tier 3 target) - rust-lang/rust#146884 (Fix modification check of `rustdoc-json-types`) - rust-lang/rust#146887 (Remove unused #![feature(get_mut_unchecked)] in Rc and Arc examples) r? `@ghost` `@rustbot` modify labels: rollup
…orts, 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.
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#146795 (Enable `limit_rdylib_exports` on wasm targets) - rust-lang#146828 (fix a crash in rustdoc merge finalize without input file) - rust-lang#146848 (Add x86_64-unknown-motor (Motor OS) tier 3 target) - rust-lang#146884 (Fix modification check of `rustdoc-json-types`) - rust-lang#146887 (Remove unused #![feature(get_mut_unchecked)] in Rc and Arc examples) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 5 pull requests Successful merges: - rust-lang/rust#146795 (Enable `limit_rdylib_exports` on wasm targets) - rust-lang/rust#146828 (fix a crash in rustdoc merge finalize without input file) - rust-lang/rust#146848 (Add x86_64-unknown-motor (Motor OS) tier 3 target) - rust-lang/rust#146884 (Fix modification check of `rustdoc-json-types`) - rust-lang/rust#146887 (Remove unused #![feature(get_mut_unchecked)] in Rc and Arc examples) r? `@ghost` `@rustbot` modify labels: rollup
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#146795 (Enable `limit_rdylib_exports` on wasm targets) - rust-lang#146828 (fix a crash in rustdoc merge finalize without input file) - rust-lang#146848 (Add x86_64-unknown-motor (Motor OS) tier 3 target) - rust-lang#146884 (Fix modification check of `rustdoc-json-types`) - rust-lang#146887 (Remove unused #![feature(get_mut_unchecked)] in Rc and Arc examples) r? `@ghost` `@rustbot` modify labels: rollup
This commit updates the target specification of wasm targets to set the
limit_rdylib_exports
value totrue
like it is on other native platforms. This was originally not implemented long ago aswasm-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 aswasm-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.