Skip to content

wasm32-wasip1 depends on libc memset with no_std #130621

Open
@drebbe-intrepid

Description

I've looked high and low between the WASM/WASI specifications and can't find what is the "correct" behavior here but the current rust behavior seems wrong to me.

I don't believe we should be trying to import memset from the "env" module:

(func $import0 (import "env" "memset") (param i32 i32 i32) (result i32))

wasm3 engine can't run this code either due to this:

$ wasm3 target/wasm32-wasip1/release/wasm_br_test.wasm 
Error: missing imported function ('env.memset')

Code

#![no_std]
#![no_main]

#[no_mangle]
pub fn _start() {
    let _asdf = [0; 40];
}

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

Cargo.toml

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

[profile.release]
lto = true
#opt-level = 's'
opt-level = 0
codegen-units = 1
panic = "abort"
strip = true

.cargo/config.toml

[build]
target = "wasm32-wasip1"


[target.wasm32-wasip1]
rustflags = ["-C", "link-arg=-zstack-size=65520",]

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (f79a912d9 2024-09-18)
binary: rustc
commit-hash: f79a912d9edc3ad4db910c0e93672ed5c65133fa
commit-date: 2024-09-18
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

wasm generated binary

(module
  (type $type0 (func (param i32 i32 i32) (result i32)))
  (type $type1 (func))
  (func $import0 (import "env" "memset") (param i32 i32 i32) (result i32))
  (table $table0 1 1 funcref)
  (memory $memory0 1)
  (global $global0 (mut i32) (i32.const 65520))
  (export "memory" (memory $memory0))
  (export "_start" (func $func1))
  (func $func1
    (local $var0 i32) (local $var1 i32) (local $var2 i32) (local $var3 i32) (local $var4 i32) (local $var5 i32) (local $var6 i32)
    global.get $global0
    local.set $var0
    i32.const 160
    local.set $var1
    local.get $var0
    local.get $var1
    i32.sub
    local.set $var2
    local.get $var2
    global.set $global0
    i32.const 160
    local.set $var3
    i32.const 0
    local.set $var4
    local.get $var2
    local.get $var4
    local.get $var3
    call $import0
    drop
    i32.const 160
    local.set $var5
    local.get $var2
    local.get $var5
    i32.add
    local.set $var6
    local.get $var6
    global.set $global0
    return
  )
)

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.O-wasiOperating system: Wasi, Webassembly System InterfaceO-wasmTarget: WASM (WebAssembly), http://webassembly.org/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