Skip to content

Rust 1.67.0 stopped initializing the WASI environment for exported functions on target="wasm32-wasi" #107635

Open
@bkolobara

Description

@bkolobara

The code:

fn main() {}

#[export_name="test"]
pub fn test() {}

would produce the following Wasm assembly on Rust 1.66.1 compiled with cargo build --target="wasm32-wasi":

;; ... truncated ...
(func $test.command_export (type 0)
    call $__wasm_call_ctors ;; <- WASI initialized here
;; ... truncated ...
(export "test" (func $test.command_export))
(export "main" (func $main.command_export))
;; ... truncated ...

On 1.67.0 it produces this one:

;; ... truncated ...
(func $test (type 0)
    return)
;; ... truncated ...
(export "test" (func $test))
(export "_start" (func $_start))
;; ... truncated ...

Notice that the call to the $__wasm_call_ctors function is missing in the exported test. This means that when entering the Wasm instance through the exported function, it will not have a correctly set up WASI environment and calls to open files or look up environment variables will fail. The _start function in both versions calls $__wasm_call_ctors and works correctly.

I'm not sure what commit broke this. The only PR that is related to this seems to be this one #105405.

EDIT: Or more likely, this one #105395

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions