Skip to content

Missing cabi_realloc on wasm-wasip2 with no_std when using exported resource #1680

Description

@Exidex

Reproduction:

Cargo.toml

[package]
name = "cabi-realloc-repro"
version = "0.1.0"
edition = "2021"

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

[dependencies]
wit-bindgen = { version = "0.60.0", default-features = false, features = ["macros", "realloc"] }
dlmalloc = { version = "0.2", features = ["global"] }

src/lib.rs

#![no_std]
extern crate alloc;

use core::panic::PanicInfo;

#[global_allocator]
static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;

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

wit_bindgen::generate!({
    world: "repro",
    inline: r#"
        package test:repro;

        interface foo {
            resource bar {
                constructor(s: string);
            }
        }

        world repro {
            export foo;
        }
    "#,
});

struct Component;

impl exports::test::repro::foo::GuestBar for alloc::string::String {
    fn new(s: alloc::string::String) -> Self {
        s
    }
}

impl exports::test::repro::foo::Guest for Component {
    type Bar = alloc::string::String;
}

export!(Component);

Running:

cargo build --target wasm32-wasip2

returns

> cargo build --target wasm32-wasip2
   Compiling cabi-realloc-repro v0.1.0 (/home/exidex/IdeaProjects/project-fulcrum/repro)
error: linking with `wasm-component-ld` failed: exit status: 1
  |
  = note:  "wasm-component-ld" "-flavor" "wasm" "--export" "test:repro/foo#[constructor]bar" "--export" "test:repro/foo#[dtor]bar" "-z" "stack-size=1048576" "--stack-first" "--no-demangle" "<46 object files omitted>" "/home/exidex/IdeaProjects/project-fulcrum/repro/target/wasm32-wasip2/debug/deps/{libdlmalloc-a964d9799bfd317b,libcfg_if-b8d3e0e0e3728a15,libwit_bindgen-ac7e94936d930589}.rlib" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/{liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-L" "/home/exidex/IdeaProjects/project-fulcrum/repro/target/wasm32-wasip2/debug/build/wit-bindgen-3fa477ffebae6273/out" "-L" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/self-contained" "-o" "/home/exidex/IdeaProjects/project-fulcrum/repro/target/wasm32-wasip2/debug/deps/cabi_realloc_repro.wasm" "--gc-sections" "--no-entry" "-O0"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: error: failed to encode component
          
          Caused by:
              0: module does not export a function named `cabi_realloc`
          

error: could not compile `cabi-realloc-repro` (lib) due to 1 previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-rustRelated to bindings for Rust-compiled-to-WebAssembly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions