From 6cf255cc2bed26048be3feb9414f5db723d281a4 Mon Sep 17 00:00:00 2001 From: Catherine Date: Fri, 1 May 2026 11:02:06 +0000 Subject: [PATCH 1/2] Remove Wasm exception handling workarounds. --- CMakeLists.txt | 7 ------- common/kernel/nextpnr.cc | 17 ----------------- 2 files changed, 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 957663ba..65f167b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,13 +108,6 @@ endif() if (WASI) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lwasi-emulated-mman") - add_definitions( - -DBOOST_EXCEPTION_DISABLE - -DBOOST_NO_EXCEPTIONS - ) - if (NOT Threads_FOUND) - add_definitions(-DBOOST_NO_CXX11_HDR_MUTEX) - endif() endif() if (STATIC_BUILD) diff --git a/common/kernel/nextpnr.cc b/common/kernel/nextpnr.cc index 8c902d88..b7530642 100644 --- a/common/kernel/nextpnr.cc +++ b/common/kernel/nextpnr.cc @@ -16,20 +16,3 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ - -#if defined(__wasm) -#include -#include -#include "log.h" - -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(); } -} - -namespace boost { -void throw_exception(std::exception const &e) { NEXTPNR_NAMESPACE::log_error("boost::exception(): %s\n", e.what()); } -} // namespace boost -#endif From 1407b3355849be7cc06a0654973a6a8b0fa6c00c Mon Sep 17 00:00:00 2001 From: Catherine Date: Fri, 1 May 2026 11:22:38 +0000 Subject: [PATCH 2/2] Ensure only non-truncating values are returned from `main()`. POSIX allows any `int` value to be returned but specifies that only the low 8 bits are available in some contexts: https://pubs.opengroup.org/onlinepubs/9699919799/functions/_exit.html For reasons that aren't entirely clear, WASI requires the value to be in range [0;126), and this is enforced with an assertion at runtime level in Wasmtime. This should probably be fixed in Wasmtime but until it is done there doesn't seem to be any harm in returning `125` instead of `-1`. This also removes any discrepancy due to truncation. --- common/kernel/command.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/kernel/command.cc b/common/kernel/command.cc index 5493173c..39ad1cea 100644 --- a/common/kernel/command.cc +++ b/common/kernel/command.cc @@ -748,7 +748,7 @@ int CommandHandler::exec() { try { if (!parseOptions()) - return -1; + return 125; if (executeBeforeContext()) return 0; @@ -764,7 +764,7 @@ int CommandHandler::exec() return rc; } catch (log_execution_error_exception) { printFooter(); - return -1; + return 125; } }