From 2e8c23ba8f1749e07849f5d056927a54e2bf5faf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 15 May 2026 10:48:39 +0200 Subject: [PATCH] cxa-throw: Don't auto-detect This speeds up running meson (re)configuration from 16.6s to 2.9s. More importantly though, it's better to just specify that we expect this to work rather than try to compile something, since that can silently mask errors and disable this feature. --- .../common/cxa-throw/meson.build | 73 ++++--------------- 1 file changed, 13 insertions(+), 60 deletions(-) diff --git a/nix-meson-build-support/common/cxa-throw/meson.build b/nix-meson-build-support/common/cxa-throw/meson.build index a20438059b95..e9947766cd40 100644 --- a/nix-meson-build-support/common/cxa-throw/meson.build +++ b/nix-meson-build-support/common/cxa-throw/meson.build @@ -1,67 +1,11 @@ have_cxa_throw = false -can_interpose_cxa_throw_test_code = ''' -#include -#include - -#define CXA_THROW_ON_LOGIC_ERROR() _exit(0) -#include "interpose-cxa-throw.cc" - -int main() -{ - const char * volatile p = nullptr; - std::string s(p); - return 1; -} -''' - -can_interpose_cxa_throw_result = cxx.run( - can_interpose_cxa_throw_test_code, - args : [ '-ldl' ], - include_directories : include_directories('.'), - name : 'can interpose __cxa_throw (catches libstdc++ throws)', -) -can_interpose_cxa_throw = can_interpose_cxa_throw_result.compiled() and can_interpose_cxa_throw_result.returncode() == 0 - -if can_interpose_cxa_throw - interpose_cxa_throw_lib = static_library( - 'interpose-cxa-throw', - 'interpose-cxa-throw.cc', - dependencies : cxx.find_library('dl', required : false), - ) - - cxa_throw_dep = declare_dependency( - link_whole : interpose_cxa_throw_lib, - ) - +if host_machine.system() == 'linux' have_cxa_throw = true -else - can_wrap_cxa_throw_test_code = ''' - #include - #include - - #define CXA_THROW_ON_LOGIC_ERROR() _exit(0) - #include "wrap-cxa-throw.cc" - int main() - { - const char * volatile p = nullptr; - std::string s(p); - return 1; - } - ''' + if get_option('default_library') == 'static' + wrap_cxa_throw_args = [ '-Wl,--wrap=__cxa_throw' ] - wrap_cxa_throw_args = [ '-Wl,--wrap=__cxa_throw' ] - - can_wrap_cxa_throw_result = cxx.run( - can_wrap_cxa_throw_test_code, - args : wrap_cxa_throw_args, - include_directories : include_directories('.'), - name : 'can wrap __cxa_throw (catches libstdc++ throws)', - ) - can_wrap_cxa_throw = can_wrap_cxa_throw_result.compiled() and can_wrap_cxa_throw_result.returncode() == 0 - - if can_wrap_cxa_throw wrap_cxa_throw_lib = static_library( 'wrap-cxa-throw', 'wrap-cxa-throw.cc', @@ -72,6 +16,15 @@ else link_args : wrap_cxa_throw_args + [ '-Wl,-u,__wrap___cxa_throw' ], ) - have_cxa_throw = true + else + interpose_cxa_throw_lib = static_library( + 'interpose-cxa-throw', + 'interpose-cxa-throw.cc', + dependencies : cxx.find_library('dl', required : false), + ) + + cxa_throw_dep = declare_dependency( + link_whole : interpose_cxa_throw_lib, + ) endif endif