Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 13 additions & 60 deletions nix-meson-build-support/common/cxa-throw/meson.build
Original file line number Diff line number Diff line change
@@ -1,67 +1,11 @@
have_cxa_throw = false

can_interpose_cxa_throw_test_code = '''
#include <string>
#include <unistd.h>

#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 <string>
#include <unistd.h>

#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',
Expand All @@ -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
Loading