-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Static variables are not exported in wasm #67453
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Symbols for wasm are exported here and it looks like no |
After a some investigation:
Statics are explicitly marked as if is_extern && !std_internal {
let target = &tcx.sess.target.target.llvm_target;
// WebAssembly cannot export data symbols, so reduce their export level
if target.contains("wasm32") || target.contains("emscripten") {
if let Some(Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })) =
tcx.hir().get_if_local(sym_def_id)
{
return SymbolExportLevel::Rust;
}
}
SymbolExportLevel::C
} else {
SymbolExportLevel::Rust
} It is unclear to me how this should be handled. Maybe statics should be exported with I'll make a PR for it, that might be a better place to talk about implementation details. |
Oh good find! I'm not sure about emscripten, but wasm has changed in the meantime so that it can export statics, so the wasm case there I believe can be removed. |
…r=alexcrichton Export public scalar statics in wasm Fixes rust-lang#67453 I am not sure which export level statics should get when exporting them in wasm. This small change fixes the issue that I had, but this might not be the correct way to implement this.
…r=alexcrichton Export public scalar statics in wasm Fixes rust-lang#67453 I am not sure which export level statics should get when exporting them in wasm. This small change fixes the issue that I had, but this might not be the correct way to implement this.
Uh oh!
There was an error while loading. Please reload this page.
Repro https://github.com/EmbarkStudios/missing-symbols
rustc 1.40.0 (73528e339 2019-12-16)
cargo build --release --target wasm32-unknown-unknown
, the resulting wasm file doesn't have the symbolFOO
.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
Expected behavior: Public static variables should get exported by default.
We believe this is a regression from 1.39.0.
Does correctly export static variables.
The text was updated successfully, but these errors were encountered: