Skip to content
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

Static variables are not exported when targeting wasm32-unknown-unknown #88092

Closed
Jake-Shadle opened this issue Aug 16, 2021 · 4 comments
Closed
Labels
C-bug Category: This is a bug.

Comments

@Jake-Shadle
Copy link

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
@Jake-Shadle Jake-Shadle added the C-bug Category: This is a bug. label Aug 16, 2021
@Jake-Shadle Jake-Shadle changed the title Static variables are not exported when targetting wasm32-unknown-unknown Static variables are not exported when targeting wasm32-unknown-unknown Aug 16, 2021
@lqd
Copy link
Member

lqd commented Aug 16, 2021

@Jake-Shadle I feel/hope #88032 will fix it. It should be in the next nightly, so please test it out and let us know :)

@Jake-Shadle
Copy link
Author

Jake-Shadle commented Aug 17, 2021

Hah yes, indeed, rustc 1.56.0-nightly (0035d9dce 2021-08-16) made the build go green again, thanks!

I'll close this now, but I guess I am a bit concerned about how this regression could occur since the original PR #67975 included a test specifically for this case, which is still present https://github.com/rust-lang/rust/blob/master/src/test/run-make/wasm-export-all-symbols/verify.js

@lqd
Copy link
Member

lqd commented Aug 17, 2021

@Jake-Shadle wasm32-unknown-unknown is a tier 2 target, IIRC tests are not always run and if they fail, it doesn't stop a nightly from being released.

As anecdote, this issue was noticed not because of the wasm tests, but because of miri's tests: they are executed after PRs land (except during "no breaking the tools"-week before release) because a tool can similarly be temporarily broken, but people are notified when its tests fail.

@Jake-Shadle
Copy link
Author

Ahh right, sorry, forgot wasm32 was still a tier 2, thanks for noticing this and linking the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants