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

rust-lld: error: --shared-memory is disallowed #308

Closed
m-haisham opened this issue Dec 15, 2021 · 7 comments
Closed

rust-lld: error: --shared-memory is disallowed #308

m-haisham opened this issue Dec 15, 2021 · 7 comments

Comments

@m-haisham
Copy link

I'm getting linking errors when trying to compile parking_lot to wasm32

error: linking with `rust-lld` failed: exit code: 1
...
= note: rust-lld: error: mutable global exported but 'mutable-globals' feature not present in inputs: `__tls_base`. Use --no-check-features to suppress.
          rust-lld: error: mutable global exported but 'mutable-globals' feature not present in inputs: `__tls_size`. Use --no-check-features to suppress.
          rust-lld: error: mutable global exported but 'mutable-globals' feature not present in inputs: `__tls_align`. Use --no-check-features to suppress.
          rust-lld: error: --shared-memory is disallowed by parking_lot-895c1fa325be9efc.parking_lot.9358177a-cgu.5.rcgu.o because it was not compiled with 'atomics' or 'bulk-memory' features.
          rust-lld: error: 'bulk-memory' feature must be used in order to use shared memory

Build

rustflags = "-Ctarget-feature=+atomics"
version = rustc 1.59.0-nightly (404c8471a 2021-12-14)

@bjorn3
Copy link
Contributor

bjorn3 commented Dec 15, 2021

You must always combine the atomics target feature with the mutable-globals and bulk-memory target features, so -Ctarget-feature=+atomics,+mutable-globals,+bulk-memory. Also make sure to enable them for all crates including the standard library if you don't already do this. Doing this requires -Zbuild-std. Not doing this may cause corruption due to the standard library thinking that it will only run single threaded and thus not using atomics where necessary.

@m-haisham
Copy link
Author

m-haisham commented Dec 15, 2021

Using those flags gave me a bunch of errors saying doesn't have a size known at compile-time, this includes structs with wasm_bindgen macro.

Do you perhaps know why that is?

@bjorn3
Copy link
Contributor

bjorn3 commented Dec 15, 2021

Can you link to the full compilation log somewhere? That may make it easier to find the issue.

@m-haisham
Copy link
Author

Command

cargo build --lib --target wasm32-unknown-unknown -Z build-std

Config

Cargo.toml
[package]
name = "chapturn-sources-wasm"
version = "0.1.0"
authors = ["Mensch272 <47662901+mensch272@users.noreply.github.com>"]
edition = "2021"

[lib]
crate-type = ["cdylib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = { version = "0.2.78", features = ["serde-serialize"] }
chapturn-sources = { path = "../chapturn-sources" }
chrono = { version = "0.4.19", features = ["serde", "wasmbind"] }
serde = "1.0.130"

parking_lot = { version = "0.11", features = ["nightly"] }

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.6", optional = true }

# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.5", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.13"

[profile.dev]
opt-level = 2
incremental = true

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
lto = true
.cargo/config.toml
[build]
rustflags = ["-Ctarget-feature=+atomics,+mutable-globals,+bulk-memory"]

output.txt

@bjorn3
Copy link
Contributor

bjorn3 commented Dec 15, 2021

This is the issue:

error: duplicate lang item in crate `core`: `bool`.
  |
  = note: the lang item is first defined in crate `core` (which `std` depends on)
  = note: first definition in `core` loaded from \\?\C:\Users\User\Documents\Projects\Rust\chapturn-sources-wasm\target\wasm32-unknown-unknown\debug\deps\libcore-6fe30f0fbc5b5f52.rlib, \\?\C:\Users\User\Documents\Projects\Rust\chapturn-sources-wasm\target\wasm32-unknown-unknown\debug\deps\libcore-6fe30f0fbc5b5f52.rmeta
  = note: second definition in `core` loaded from \\?\C:\Users\User\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\wasm32-unknown-unknown\lib\libcore-3365b6c50e94718e.rlib

for some reason it ends up loading two copies of libcore. Could you open an issue on https://github.com/rust-lang/cargo?

@m-haisham
Copy link
Author

Oh ok, thank you.

@m-haisham
Copy link
Author

I was able to compile it by following this issue wg-cargo-std-aware#50.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants