Static variables are not exported when targeting wasm32-unknown-unknown
#88092
Description
It appears that #67453 has regressed in nightly, The last working nightly we used was rustc 1.56.0-nightly (0fa319039 2021-08-12)
, every nightly from rustc 1.56.0-nightly (5a19ffe1c 2021-08-13)
to the present has failed.
I tried this code:
// lib.rs
#[no_mangle]
#[used]
pub static FOO: u64 = 4242;
I expected to see this happen:
cargo build --release --target wasm32-unknown-unknown && wasm2wat target/wasm32-unknown-unknown/release/missing_symbols.wasm
In rustc 1.54.0 (a178d0322 2021-07-26)
, this properly exports the FOO
static.
(module
(table (;0;) 1 1 funcref)
(memory (;0;) 17)
(global (;0;) (mut i32) (i32.const 1048576))
(global (;1;) i32 (i32.const 1048576))
(global (;2;) i32 (i32.const 1048584))
(global (;3;) i32 (i32.const 1048584))
(export "memory" (memory 0))
(export "FOO" (global 1))
(export "__data_end" (global 2))
(export "__heap_base" (global 3))
(data (;0;) (i32.const 1048576) "\92\10\00\00\00\00\00\00"))
Instead, this happened:
cargo +nightly build --release --target wasm32-unknown-unknown && wasm2wat target/wasm32-unknown-unknown/release/missing_symbols.wasm
In rustc 1.56.0-nightly (2d2bc94c8 2021-08-15)
, FOO
is not exported.
(module
(table (;0;) 1 1 funcref)
(memory (;0;) 16)
(global (;0;) (mut i32) (i32.const 1048576))
(global (;1;) i32 (i32.const 1048576))
(global (;2;) i32 (i32.const 1048576))
(export "memory" (memory 0))
(export "__data_end" (global 1))
(export "__heap_base" (global 2)))
Note that unlike in the previous bug reported in #67453, using -C link-dead-code
does not export FOO
.
Meta
rustc --version --verbose
:
rustc 1.56.0-nightly (2d2bc94c8 2021-08-15)
binary: rustc
commit-hash: 2d2bc94c8c3aa778e191f80261c726e4777439f1
commit-date: 2021-08-15
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1
Activity