Skip to content

Conversation

alexcrichton
Copy link
Member

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.

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.
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

r? @saethlin

rustbot has assigned @saethlin.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@workingjubilee
Copy link
Member

Should this be done for all wasm targets, or just WASI targets?

@alexcrichton
Copy link
Member Author

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 EmLinker implementation and I think it should be just-as-applicable to other targets.

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.

@bjorn3
Copy link
Member

bjorn3 commented Sep 21, 2025

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.

@saethlin
Copy link
Member

r? bjorn3

@rustbot rustbot assigned bjorn3 and unassigned saethlin Sep 21, 2025
@bjorn3
Copy link
Member

bjorn3 commented Sep 22, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 22, 2025

📌 Commit f354d93 has been approved by bjorn3

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2025
bors added a commit that referenced this pull request Sep 22, 2025
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
@bors bors merged commit dc176bd into rust-lang:master Sep 22, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Sep 22, 2025
rust-timer added a commit that referenced this pull request Sep 22, 2025
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.
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Sep 23, 2025
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
Muscraft pushed a commit to Muscraft/rust that referenced this pull request Sep 24, 2025
…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.
Muscraft pushed a commit to Muscraft/rust that referenced this pull request Sep 24, 2025
…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
github-actions bot pushed a commit to rust-lang/compiler-builtins that referenced this pull request Sep 25, 2025
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
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Oct 9, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants