You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WebAssembly ABI mismatch between clang and rust #71871
A-ABIArea: Concerning the application binary interface (ABI)A-FFIArea: Foreign function interface (FFI)C-bugCategory: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
And try link them together, I'm getting linking errors:
= note: lld: error: function signature mismatch: extract_a
>>> defined as (i32, i32) -> i32 in /home/pierre/Projets/wasm-abi-test/target/wasm32-wasi/debug/deps/wasm_abi_test.67xpw7l331r9o5x.rcgu.o
>>> defined as (i32) -> i32 in /home/pierre/Projets/wasm-abi-test/target/wasm32-wasi/debug/build/wasm-abi-test-9c49ce7f6c5ca031/out/libfoo.a(test.o)
It seems that, according to clang, passing a struct by value should inline the fields, while for Rust it should be passed by pointer.
Note that #83763 changed the default, so only wasm32-unknown-unknown uses the mismatched ABI, all other wasm targets (including custom targets) now default to using the ABI that matches clang:
In short, wasm-bindgen needs a consistent C ABI between wasm32-unknown-unknown and wasm32-wasi to support both of them.
Note that #83763 changed the default, so only wasm32-unknown-unknown uses the mismatched ABI, all other wasm targets (including custom targets) now default to using the ABI that matches clang:
The change itself would be removing options.default_adjusted_cabi = Some(Abi::Wasm) from the target spec and that's it. Because it breaks older wasm-bindgen versions it will probably require waiting months to years before we can actually make this change. And preferably we would introduce a future compat warning for this change. Either against older wasm-bindgen versions or against any extern "C" function for which changing the abi actually has any effect.
I don't see why breaking older versions wasm-bindgen is a blocker when there can be a compatibility warning and it'll take over 12 weeks until stable if the change were to be merged today. Updating wasm-bindgen is as simple as just running cargo update -p wasm-bindgen, we can tell users to run it. wasm-bindgen is also semver 0.x so it makes no stability guarantees
It is unfortunate that we have to break code (that we never promised stability for) but the longer we wait, the worse the problem gets.
Reacted by João Matos, Pierre Krieger, Danny Kim, Liam Rosenfeld, Jia Yuan Lo, David A Roberts, NickAc and Philip Dubé
We need to warn because it will breal everyone who uses an older wasm-bindgen version. We have done plenty of warnings and sometimes even crate version specific workaround in the past to avoid breakage even after a fixed crate version exists.
We need to warn because it will breal everyone who uses an older wasm-bindgen version.
May I ask you what things would be broken and users should be aware of?
The reason this discussion started was basically major modules in std are not working in wasm32-unknown-unknown, making various crates be divided into wasm and non-wasm versions. Fixing this fragmentation in Rust ecosystem as soon as possible would be good, in my opinion. Maybe we can use a version-specific workaround as you mentioned.
One thing I'm concerned about is that this issue is being solved too slow. It's older than 3 years. I believe we need some momentum for this issue, or it will just be left unsolved even after 2026 or so..
A-ABIArea: Concerning the application binary interface (ABI)A-FFIArea: Foreign function interface (FFI)C-bugCategory: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
tomaka commentedon May 4, 2020
Apparently this is a known issue:
TheBlueMatt commentedon Jan 9, 2021
This is mostly tracked at rustwasm/team#291 and would be fixed by #79998.
TheBlueMatt commentedon Jan 12, 2021
This should now work for wasm32-wasi (on current git head).
programmerjake commentedon Aug 28, 2022
Note that #83763 changed the default, so only wasm32-unknown-unknown uses the mismatched ABI, all other wasm targets (including custom targets) now default to using the ABI that matches clang:
rust/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs
Lines 22 to 30 in 482a3d0
temeddix commentedon Oct 26, 2023
There are discussions going on at
wasm-bindgento extend the support towasm32-wasiin addition to the currentwasm32-unknown-unknown.In short,
wasm-bindgenneeds a consistent C ABI betweenwasm32-unknown-unknownandwasm32-wasito support both of them.Can we have ABI that matches clang on
wasm32-unknown-unknownas well? I can help with this, but would it be a hard task?bjorn3 commentedon Oct 26, 2023
The change itself would be removing
options.default_adjusted_cabi = Some(Abi::Wasm)from the target spec and that's it. Because it breaks older wasm-bindgen versions it will probably require waiting months to years before we can actually make this change. And preferably we would introduce a future compat warning for this change. Either against older wasm-bindgen versions or against anyextern "C"function for which changing the abi actually has any effect.ranile commentedon Oct 26, 2023
I don't see why breaking older versions wasm-bindgen is a blocker when there can be a compatibility warning and it'll take over 12 weeks until stable if the change were to be merged today. Updating wasm-bindgen is as simple as just running
cargo update -p wasm-bindgen, we can tell users to run it. wasm-bindgen is also semver 0.x so it makes no stability guaranteesIt is unfortunate that we have to break code (that we never promised stability for) but the longer we wait, the worse the problem gets.
temeddix commentedon Oct 26, 2023
I think so too, since the users don't need to refactor their code, this change doesn't need to be warned and waited.
bjorn3 commentedon Oct 26, 2023
We need to warn because it will breal everyone who uses an older wasm-bindgen version. We have done plenty of warnings and sometimes even crate version specific workaround in the past to avoid breakage even after a fixed crate version exists.
temeddix commentedon Oct 26, 2023
May I ask you what things would be broken and users should be aware of?
The reason this discussion started was basically major modules in
stdare not working inwasm32-unknown-unknown, making various crates be divided into wasm and non-wasm versions. Fixing this fragmentation in Rust ecosystem as soon as possible would be good, in my opinion. Maybe we can use a version-specific workaround as you mentioned.One thing I'm concerned about is that this issue is being solved too slow. It's older than 3 years. I believe we need some momentum for this issue, or it will just be left unsolved even after 2026 or so..
28 remaining items
Unrolled build for rust-lang#117918
Require wasm-bindgen >=0.2.88 to work around rust-lang/rust/issues/71871
Require wasm-bindgen >=0.2.88 to work around rust-lang/rust/issues/71871
upgrade `wasm-bindgen` to 0.2.92 (#5056)
Rollup merge of rust-lang#133952 - bjorn3:remove_wasm_legacy_abi, r=a…
Rollup merge of rust-lang#133952 - bjorn3:remove_wasm_legacy_abi, r=a…
Rollup merge of rust-lang#133952 - bjorn3:remove_wasm_legacy_abi, r=a…
Rollup merge of rust-lang#133952 - bjorn3:remove_wasm_legacy_abi, r=a…
Rollup merge of rust-lang#133952 - bjorn3:remove_wasm_legacy_abi, r=a…
Unrolled build for #133952
Rollup merge of rust-lang#133952 - bjorn3:remove_wasm_legacy_abi, r=a…
Rollup merge of #133952 - bjorn3:remove_wasm_legacy_abi, r=alexcrichton