From 1c2aa6f5c34ffe389e34032b18987c2ec927473a Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Thu, 21 Aug 2025 12:06:21 +0200 Subject: [PATCH] meson: check for no_sanitize function attributes Meson doesn't support for checking no_sanitize attributes, so we do it manually through testing. Signed-off-by: Juan A. Suarez Romero Reviewed-by: Yonggang Luo Part-of: --- meson.build | 16 ++++++++++++++++ src/util/macros.h | 6 ++++++ 2 files changed, 22 insertions(+) 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