diff --git a/meson.build b/meson.build index 173c4f007d9..b03df2879b9 100644 --- a/meson.build +++ b/meson.build @@ -1047,6 +1047,22 @@ endforeach if cc.has_function_attribute('visibility:hidden') pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISIBILITY' endif + +_no_sanitize_flags = [] +if ['address', 'address,undefined'].contains(get_option('b_sanitize')) + _no_sanitize_flags += ['address'] +endif +if ['undefined', 'address,undefined'].contains(get_option('b_sanitize')) + _no_sanitize_flags += ['vptr'] +endif +foreach flag: _no_sanitize_flags + if cc.compiles('__attribute__((no_sanitize("@0@"))) int foo(void) { return 0; }'.format(flag), + name : 'no_sanitize(@0@)'.format(flag), + werror: true) + pre_args += '-DHAVE_FUNC_ATTRIBUTE_NO_SANITIZE_@0@'.format(flag.to_upper()) + endif +endforeach + if cc.compiles('__uint128_t foo(void) { return 0; }', name : '__uint128_t') pre_args += '-DHAVE_UINT128' diff --git a/src/util/macros.h b/src/util/macros.h index 538d10fe4a1..97efb0272d4 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -253,6 +253,12 @@ do { \ #define ATTRIBUTE_OPTIMIZE(flags) #endif +#ifdef HAVE_FUNC_ATTRIBUTE_NO_SANITIZE_VPTR +#define ATTRIBUTE_NO_SANITIZE_VPTR __attribute__((no_sanitize(("vptr")))) +#else +#define ATTRIBUTE_NO_SANITIZE_VPTR +#endif + #ifdef __cplusplus /** * Macro function that evaluates to true if T is a trivially