Skip to content

Static variables are not exported in wasm #67453

Closed
@MaikKlein

Description

Repro https://github.com/EmbarkStudios/missing-symbols rustc 1.40.0 (73528e339 2019-12-16)

// lib.rs
#[no_mangle]
#[used]
pub static FOO: u64 = 4242;

cargo build --release --target wasm32-unknown-unknown, the resulting wasm file doesn't have the symbol FOO.

(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)))

But if we compile with -C link-dead-code, the symbol is correctly exported in the wasm file.

RUSTFLAGS="-C link-dead-code" cargo build --release --target wasm32-unknown-unknown

(module
  (table (;0;) 1 1 funcref)
  (memory (;0;) 17)
  (global (;0;) (mut i32) (i32.const 1048576))
  (global (;1;) i32 (i32.const 1048584))
  (global (;2;) i32 (i32.const 1048584))
  (global (;3;) i32 (i32.const 1048576))
  (export "memory" (memory 0))
  (export "__data_end" (global 1))
  (export "__heap_base" (global 2))
  (export "FOO" (global 3))
  (data (;0;) (i32.const 1048576) "\92\10\00\00\00\00\00\00"))

Expected behavior: Public static variables should get exported by default.

We believe this is a regression from 1.39.0.

rustup override set 1.39.0
cargo build --release --target wasm32-unknown-unknown

Does correctly export static variables.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesO-wasmTarget: WASM (WebAssembly), http://webassembly.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions