From 5dfe1937a04cca1d8e087eb89c4ddfa6785dd560 Mon Sep 17 00:00:00 2001 From: bin Date: Fri, 1 May 2026 13:26:28 -0400 Subject: [PATCH] Upgrade to WASI SDK 33 and enable exceptions --- .github/workflows/extra-builds.yml | 4 ++-- Makefile | 7 ++++--- kernel/driver.cc | 13 ------------- passes/techmap/abc.cc | 5 ++++- passes/techmap/abc9_exe.cc | 5 ++++- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/extra-builds.yml b/.github/workflows/extra-builds.yml index d6bf5226c..7209b3645 100644 --- a/.github/workflows/extra-builds.yml +++ b/.github/workflows/extra-builds.yml @@ -79,8 +79,8 @@ jobs: persist-credentials: false - name: Build run: | - WASI_SDK=wasi-sdk-27.0-x86_64-linux - WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-27/wasi-sdk-27.0-x86_64-linux.tar.gz + WASI_SDK=wasi-sdk-33.0-x86_64-linux + WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-33/wasi-sdk-33.0-x86_64-linux.tar.gz if ! [ -d ${WASI_SDK} ]; then curl -L ${WASI_SDK_URL} | tar xzf -; fi FLEX_VER=2.6.4 diff --git a/Makefile b/Makefile index 97e51633b..0a0c65a3e 100644 --- a/Makefile +++ b/Makefile @@ -291,18 +291,19 @@ ifeq ($(WASI_SDK),) CXX = clang++ AR = llvm-ar RANLIB = llvm-ranlib -WASIFLAGS := -target wasm32-wasi $(WASIFLAGS) +WASIFLAGS := -target wasm32-wasip1 $(WASIFLAGS) else CXX = $(WASI_SDK)/bin/clang++ AR = $(WASI_SDK)/bin/ar RANLIB = $(WASI_SDK)/bin/ranlib endif -CXXFLAGS := $(WASIFLAGS) -std=$(CXXSTD) $(OPT_LEVEL) -D_WASI_EMULATED_PROCESS_CLOCKS $(filter-out -fPIC,$(CXXFLAGS)) -LINKFLAGS := $(WASIFLAGS) -Wl,-z,stack-size=1048576 $(filter-out -rdynamic,$(LINKFLAGS)) +CXXFLAGS := $(WASIFLAGS) -std=$(CXXSTD) $(OPT_LEVEL) -D_WASI_EMULATED_PROCESS_CLOCKS -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false $(filter-out -fPIC,$(CXXFLAGS)) +LINKFLAGS := $(WASIFLAGS) -Wl,-z,stack-size=1048576 $(filter-out -rdynamic,$(LINKFLAGS)) -fwasm-exceptions -lunwind LIBS := -lwasi-emulated-process-clocks $(filter-out -lrt,$(LIBS)) ABCMKARGS += AR="$(AR)" RANLIB="$(RANLIB)" ABCMKARGS += ARCHFLAGS="$(WASIFLAGS) -D_WASI_EMULATED_PROCESS_CLOCKS -DABC_USE_STDINT_H -DABC_NO_DYNAMIC_LINKING -DABC_NO_RLIMIT" ABCMKARGS += OPTFLAGS="-Os" +LTOFLAGS = EXE = .wasm DISABLE_SPAWN := 1 diff --git a/kernel/driver.cc b/kernel/driver.cc index d76841909..30c9a285f 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -144,19 +144,6 @@ int yosys_history_offset = 0; std::string yosys_history_file; #endif -#if defined(__wasm) -extern "C" { - // FIXME: WASI does not currently support exceptions. - void* __cxa_allocate_exception(size_t thrown_size) throw() { - return malloc(thrown_size); - } - bool __cxa_uncaught_exception() throw(); - void __cxa_throw(void* thrown_exception, struct std::type_info * tinfo, void (*dest)(void*)) { - std::terminate(); - } -} -#endif - void yosys_atexit() { #if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE) diff --git a/passes/techmap/abc.cc b/passes/techmap/abc.cc index 780df2b23..71c238ec7 100644 --- a/passes/techmap/abc.cc +++ b/passes/techmap/abc.cc @@ -70,6 +70,9 @@ # include # include #endif +#if defined(__wasm) +#include +#endif #include "frontends/blif/blifparse.h" #include "liberty_cache.h" @@ -1382,7 +1385,7 @@ void RunAbcState::run(ConcurrentStack &) FILE *old_stdout = fopen(temp_stdouterr_name.c_str(), "r"); // need any fd for renumbering FILE *old_stderr = fopen(temp_stdouterr_name.c_str(), "r"); // need any fd for renumbering #if defined(__wasm) -#define fd_renumber(from, to) (void)__wasi_fd_renumber(from, to) +#define fd_renumber(from, to) (void)__wasilibc_fd_renumber(from, to) #else #define fd_renumber(from, to) dup2(from, to) #endif diff --git a/passes/techmap/abc9_exe.cc b/passes/techmap/abc9_exe.cc index e4c4e7529..a32816612 100644 --- a/passes/techmap/abc9_exe.cc +++ b/passes/techmap/abc9_exe.cc @@ -30,6 +30,9 @@ # include # include #endif +#if defined(__wasm) +#include +#endif #ifdef YOSYS_LINK_ABC namespace abc { @@ -296,7 +299,7 @@ void abc9_module(RTLIL::Design *design, std::string script_file, std::string exe FILE *old_stdout = fopen(temp_stdouterr_name.c_str(), "r"); // need any fd for renumbering FILE *old_stderr = fopen(temp_stdouterr_name.c_str(), "r"); // need any fd for renumbering #if defined(__wasm) -#define fd_renumber(from, to) (void)__wasi_fd_renumber(from, to) +#define fd_renumber(from, to) (void)__wasilibc_fd_renumber(from, to) #else #define fd_renumber(from, to) dup2(from, to) #endif