Skip to content

Commit 9abcfa5

Browse files
committed
Don't link with --export-dynamic on wasm32-wasi
Remove --export-dynamic from the link arguments on the wasm32-wasi target, as it emits spurious exports and increases code size. Leave it in place for wasm32-unknown-unknown and wasm32-unknown-emscripten. Even though it isn't a great solution there, users are likely depending on its behavior there.
1 parent 65767e5 commit 9abcfa5

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

compiler/rustc_target/src/spec/wasm32_base.rs

-9
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ pub fn options() -> TargetOptions {
5555
// to do so.
5656
arg("--no-demangle");
5757

58-
// The symbol visibility story is a bit in flux right now with LLD.
59-
// It's... not entirely clear to me what's going on, but this looks to
60-
// make everything work when `export_symbols` isn't otherwise called for
61-
// things like executables.
62-
//
63-
// This is really only here to get things working. If it can be removed and
64-
// basic tests still work, then sounds like it should be removed!
65-
arg("--export-dynamic");
66-
6758
let mut pre_link_args = BTreeMap::new();
6859
pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Wasm), lld_args);
6960
pre_link_args.insert(LinkerFlavor::Gcc, clang_args);

compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ use super::wasm32_base;
22
use super::{LinkArgs, LinkerFlavor, PanicStrategy, Target, TargetOptions};
33

44
pub fn target() -> Target {
5+
let mut options = wasm32_base::options();
6+
7+
let clang_args = options.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap();
8+
9+
// Rust really needs a way for users to specify exports and imports in
10+
// the source code. --export-dynamic isn't the right tool for this job,
11+
// however it does have the side effect of automatically exporting a lot
12+
// of symbols, which approximates what people want when compiling for
13+
// wasm32-unknown-unknown expect, so use it for now.
14+
clang_args.push("--export-dynamic".to_string());
15+
516
let mut post_link_args = LinkArgs::new();
617
post_link_args.insert(
718
LinkerFlavor::Em,
@@ -28,7 +39,7 @@ pub fn target() -> Target {
2839
panic_strategy: PanicStrategy::Unwind,
2940
post_link_args,
3041
os_family: Some("unix".to_string()),
31-
..wasm32_base::options()
42+
..options
3243
};
3344
Target {
3445
llvm_target: "wasm32-unknown-emscripten".to_string(),

compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ pub fn target() -> Target {
2626
// For now this target just never has an entry symbol no matter the output
2727
// type, so unconditionally pass this.
2828
clang_args.push("-Wl,--no-entry".to_string());
29-
options
30-
.pre_link_args
31-
.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm))
32-
.unwrap()
33-
.push("--no-entry".to_string());
29+
30+
// Rust really needs a way for users to specify exports and imports in
31+
// the source code. --export-dynamic isn't the right tool for this job,
32+
// however it does have the side effect of automatically exporting a lot
33+
// of symbols, which approximates what people want when compiling for
34+
// wasm32-unknown-unknown expect, so use it for now.
35+
clang_args.push("-Wl,--export-dynamic".to_string());
36+
37+
// Add the flags to wasm-ld's args too.
38+
let lld_args = options.pre_link_args.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm)).unwrap();
39+
lld_args.push("--no-entry".to_string());
40+
lld_args.push("--export-dynamic".to_string());
3441

3542
Target {
3643
llvm_target: "wasm32-unknown-unknown".to_string(),

0 commit comments

Comments
 (0)