From 4a1f400f8b7259db748b311c1441d375e68d76ca Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 10 Sep 2026 09:37:11 -0400 Subject: [PATCH] util: Error out at compile time if KJ_NO_EXCEPTIONS is set libmultiprocess requires capnp/kj to be built with exception support: mp::serverInvoke (proxy-types.h) relies on capnp's RPC layer catching exceptions thrown by server methods and converting them into remote-exception replies for the client, which capnp only does when KJ_NO_EXCEPTIONS is unset. If it's set, that conversion code (kj::getCaughtExceptionAsKj) is compiled out of capnp/kj, and an exception thrown by a server method escapes uncaught instead, crashing the process. This was hit in practice on NetBSD (bitcoin/bitcoin#36058): capnp's kj/common.h exception-support autodetection is fooled there, because NetBSD's defines a dummy __has_feature(x)=0 stub for compilers (GCC<14) that don't natively support __has_feature. capnp reads that as "no exceptions" even though the compiler has exceptions enabled, so NetBSD's prebuilt capnproto package ends up linked without the exception-catching code libmultiprocess needs. Fixed upstream in capnproto/capnproto#2756, but not yet in any capnproto release or in NetBSD's pkgsrc package. Fail the build immediately with an explanatory #error instead of letting this surface later as a runtime crash on the affected platform. Co-Authored-By: Claude Sonnet 5 --- include/mp/proxy-types.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 3a5dd3d8..0c00b825 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -13,6 +13,12 @@ #include #include +// KJ exception support is required, or exceptions thrown in serverInvoke below go uncaught +// and crash the process instead of being returned to the client as errors. +#if KJ_NO_EXCEPTIONS +#error "KJ_NO_EXCEPTIONS=1 is set but libmultiprocess requires support for exceptions. Please check build settings. On NetBSD you may also need to set -DKJ_NO_EXCEPTIONS=0 -DKJ_NO_RTTI=0 explicitly (https://github.com/capnproto/capnproto/pull/2756)" +#endif + namespace mp { template