Skip to content

util: Error out at compile time if KJ_NO_EXCEPTIONS is set - #364

Open
ryanofsky wants to merge 1 commit into
bitcoin-core:masterfrom
ryanofsky:pr/noex
Open

util: Error out at compile time if KJ_NO_EXCEPTIONS is set#364
ryanofsky wants to merge 1 commit into
bitcoin-core:masterfrom
ryanofsky:pr/noex

Conversation

@ryanofsky

Copy link
Copy Markdown
Collaborator

Cap'n Proto has a bug on netbsd where it incorrectly detects compiler does not support exceptions (reported and fixed in capnproto/capnproto#2756) causing exceptions thrown from bitcoin core IPC methods not be caught and leading to the CI failure reported bitcoin/bitcoin#36058.

Failure can be worked around by adding `-DKJ_NO_EXCEPTIONS=0`` to the build configuration so add an error message to detect when it would happen and suggest this.

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 <sys/cdefs.h> 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 <noreply@anthropic.com>
@DrahtBot

DrahtBot commented Sep 10, 2026

Copy link
Copy Markdown

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK hebasto, xyzconstant

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 4a1f400, I have reviewed the code and it looks OK.

Comment thread include/mp/proxy-types.h
// 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)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the comment about -DKJ_NO_RTTI=0 is technically correct, setting the flag isn't necessary in practice.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the comment about -DKJ_NO_RTTI=0 is technically correct, setting the flag isn't necessary in practice.

Thanks, I only saw the failing CI run in bitcoin/bitcoin#36058 and wasn't sure what was needed to make CI pass. I believe KJ_NO_RTTI is good to set though to improve exception error messages.

@hebasto

hebasto commented Sep 10, 2026

Copy link
Copy Markdown
Member

Error out at compile time if KJ_NO_EXCEPTIONS is set

Why not check earlier, at configure time?

Related: bitcoin/bitcoin#36058.

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #364 (comment)

Why not check earlier, at configure time?

This seems less reliable because the header is installed and can be compiled with different flags after being installed. I wouldn't object to another change adding a cmake check though if it would be helpful.

Comment thread include/mp/proxy-types.h
// 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)"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the comment about -DKJ_NO_RTTI=0 is technically correct, setting the flag isn't necessary in practice.

Thanks, I only saw the failing CI run in bitcoin/bitcoin#36058 and wasn't sure what was needed to make CI pass. I believe KJ_NO_RTTI is good to set though to improve exception error messages.

@xyzconstant

Copy link
Copy Markdown
Contributor

LGTM. ACK 4a1f400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants