|
| 1 | +have_cxa_throw = false |
| 2 | + |
| 3 | +can_interpose_cxa_throw_test_code = ''' |
| 4 | +#include <string> |
| 5 | +#include <unistd.h> |
| 6 | +
|
| 7 | +#define CXA_THROW_ON_LOGIC_ERROR() _exit(0) |
| 8 | +#include "interpose-cxa-throw.cc" |
| 9 | +
|
| 10 | +int main() |
| 11 | +{ |
| 12 | + const char * volatile p = nullptr; |
| 13 | + std::string s(p); |
| 14 | + return 1; |
| 15 | +} |
| 16 | +''' |
| 17 | + |
| 18 | +can_interpose_cxa_throw_result = cxx.run( |
| 19 | + can_interpose_cxa_throw_test_code, |
| 20 | + args : [ '-ldl' ], |
| 21 | + include_directories : include_directories('.'), |
| 22 | + name : 'can interpose __cxa_throw (catches libstdc++ throws)', |
| 23 | +) |
| 24 | +can_interpose_cxa_throw = can_interpose_cxa_throw_result.compiled() and can_interpose_cxa_throw_result.returncode() == 0 |
| 25 | + |
| 26 | +if can_interpose_cxa_throw |
| 27 | + interpose_cxa_throw_lib = static_library( |
| 28 | + 'interpose-cxa-throw', |
| 29 | + 'interpose-cxa-throw.cc', |
| 30 | + dependencies : cxx.find_library('dl', required : false), |
| 31 | + ) |
| 32 | + |
| 33 | + cxa_throw_dep = declare_dependency( |
| 34 | + link_whole : interpose_cxa_throw_lib, |
| 35 | + ) |
| 36 | + |
| 37 | + have_cxa_throw = true |
| 38 | +else |
| 39 | + can_wrap_cxa_throw_test_code = ''' |
| 40 | + #include <string> |
| 41 | + #include <unistd.h> |
| 42 | +
|
| 43 | + #define CXA_THROW_ON_LOGIC_ERROR() _exit(0) |
| 44 | + #include "wrap-cxa-throw.cc" |
| 45 | +
|
| 46 | + int main() |
| 47 | + { |
| 48 | + const char * volatile p = nullptr; |
| 49 | + std::string s(p); |
| 50 | + return 1; |
| 51 | + } |
| 52 | + ''' |
| 53 | + |
| 54 | + wrap_cxa_throw_args = [ '-Wl,--wrap=__cxa_throw' ] |
| 55 | + |
| 56 | + can_wrap_cxa_throw_result = cxx.run( |
| 57 | + can_wrap_cxa_throw_test_code, |
| 58 | + args : wrap_cxa_throw_args, |
| 59 | + include_directories : include_directories('.'), |
| 60 | + name : 'can wrap __cxa_throw (catches libstdc++ throws)', |
| 61 | + ) |
| 62 | + can_wrap_cxa_throw = can_wrap_cxa_throw_result.compiled() and can_wrap_cxa_throw_result.returncode() == 0 |
| 63 | + |
| 64 | + if can_wrap_cxa_throw |
| 65 | + wrap_cxa_throw_lib = static_library( |
| 66 | + 'wrap-cxa-throw', |
| 67 | + 'wrap-cxa-throw.cc', |
| 68 | + ) |
| 69 | + |
| 70 | + cxa_throw_dep = declare_dependency( |
| 71 | + link_whole : wrap_cxa_throw_lib, |
| 72 | + link_args : wrap_cxa_throw_args + [ '-Wl,-u,__wrap___cxa_throw' ], |
| 73 | + ) |
| 74 | + |
| 75 | + have_cxa_throw = true |
| 76 | + endif |
| 77 | +endif |
0 commit comments