Skip to content

Static variables are not exported on multiple platforms. #99596

Closed
@Jake-Shadle

Description

@Jake-Shadle

It appears that #88092 has regressed in nightly, The last working nightly we used was rustc 1.64.0-nightly (d68e7ebc3 2022-07-20), rustc 1.64.0-nightly (62b272d25 2022-07-21) was the first nightly that stopped working correctly.

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.62.0 (a8314ef7d 2022-06-27), this properly exports the FOO static.

(module
  (table (;0;) 1 1 funcref)
  (memory (;0;) 17)
  (global $__stack_pointer (mut i32) (i32.const 1048576))
  (global (;1;) i32 (i32.const 1048576))
  (global (;2;) i32 (i32.const 1048584))
  (global (;3;) i32 (i32.const 1048592))
  (export "memory" (memory 0))
  (export "FOO" (global 1))
  (export "__data_end" (global 2))
  (export "__heap_base" (global 3))
  (data $.rodata (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.64.0-nightly (62b272d25 2022-07-21), FOO is not exported.

(module
  (table (;0;) 1 1 funcref)
  (memory (;0;) 16)
  (global $__stack_pointer (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)))

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (62b272d25 2022-07-21)
binary: rustc
commit-hash: 62b272d25c5bb8b6bb8ac73797d82b8b9a1eabda
commit-date: 2022-07-21
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.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