Skip to content

wasi-sdk-33.0 undefined symbols when building with c++ exceptions #639

Description

@VanillaMaster

even though wasi-sdk-33 mentions

Build a sysroot that supports C++ exceptions by default

i was unable to compile c++ that uses exceptions to wasm

source file
__attribute__((import_module("env"), import_name("print")))
extern void print(const char*);

struct base {
    virtual void method() noexcept(false) = 0;
};

struct foo : base {
    void method() override {
        print("foo");
    }
};

struct bar : base {
    void method() override {
        print("bar");
    }
};

void destruct(base* object) {
    try {
        object->method();
    } catch (...) {
        print("error");
    }
}
clang output
vm@Comp:~$ ./wasi-sdk-33.0-x86_64-linux/bin/clang -xc++ -std=c++23 --target=wasm32-wasip1 -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -lunwind -Wl,--export-all -o test.wasm test.cpp
wasm-ld: error: /home/vm/wasi-sdk-33.0-x86_64-linux/bin/../share/wasi-sysroot/lib/wasm32-wasip1/eh/libunwind.a(Unwind-wasm.c.o): undefined symbol: __gxx_personality_wasm0
wasm-ld: error: /tmp/test-d07e2b.o: undefined symbol: __cxa_begin_catch
wasm-ld: error: /tmp/test-d07e2b.o: undefined symbol: print(char const*)
wasm-ld: error: /tmp/test-d07e2b.o: undefined symbol: __cxa_end_catch
wasm-ld: error: /tmp/test-d07e2b.o: undefined symbol: __cxa_end_catch
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions