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

Broken WASM codegen with u128 and wasm_abi #88207

Closed
kostko opened this issue Aug 21, 2021 · 5 comments
Closed

Broken WASM codegen with u128 and wasm_abi #88207

kostko opened this issue Aug 21, 2021 · 5 comments
Labels
A-ABI Area: Concerning the application binary interface (ABI) A-FFI Area: Foreign function interface (FFI) A-LTO Area: Link-time optimization (LTO) C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@kostko
Copy link

kostko commented Aug 21, 2021

It seems that the following code:

#![feature(wasm_abi)]

#[no_mangle]
pub extern "wasm" fn test() {
    format!("boom: {}", 0u128);
}

can result in invalid WASM being generated in case it is compiled with lto = true. I've created a repository with the minimal example that reproduces the issue when built with (tested on rustc 1.56.0-nightly (0035d9dce 2021-08-16)):

cargo build --target wasm32-unknown-unknown --release

Parsing the generated WASM will produce an error similar to the following:

[parse exception: attempted pop from empty stack / beyond block start boundary at 536 (at 0:536)]
Fatal: error parsing wasm

Using an argument of type u64 or disabling lto or using the C ABI instead of wasm ABI (which enables LLVM's multivalue feature) works.

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (0035d9dce 2021-08-16)
binary: rustc
commit-hash: 0035d9dcecee49d1f7349932bfa52c05a6f83641
commit-date: 2021-08-16
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1
@memoryruins
Copy link
Contributor

memoryruins commented Jul 20, 2022

@rustbot label: +O-wasm +A-abi +A-ffi +A-lto

@rustbot rustbot added A-ABI Area: Concerning the application binary interface (ABI) A-FFI Area: Foreign function interface (FFI) O-wasm Target: WASM (WebAssembly), http://webassembly.org/ A-LTO Area: Link-time optimization (LTO) labels Jul 20, 2022
@Jules-Bertholet
Copy link
Contributor

@rustbot label I-unsound

@rustbot rustbot added I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 18, 2023
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 19, 2023
@bjorn3
Copy link
Member

bjorn3 commented Dec 16, 2024

extern "wasm" has been removed. Can't reproduce with

echo '#[no_mangle]
pub extern "C" fn test() {
    format!("boom: {}", 0u128);
}' | rustc +nightly - --target wasm32-unknown-unknown --crate-type cdylib -Clto=yes -Copt-level=3

@kostko
Copy link
Author

kostko commented Dec 16, 2024

Yeah as mentioned in the original issue:

Using an argument of type u64 or disabling lto or using the C ABI instead of wasm ABI (which enables LLVM's multivalue feature) works.

If the wasm ABI was removed, then this issue is likely no longer relevant.

@nikic
Copy link
Contributor

nikic commented Dec 16, 2024

Right, there should no longer be any way to expose this from Rust anymore. There is an upstream LLVM issue tracking i128 with multi-value here: llvm/llvm-project#98323

@nikic nikic closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ABI Area: Concerning the application binary interface (ABI) A-FFI Area: Foreign function interface (FFI) A-LTO Area: Link-time optimization (LTO) C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

7 participants