[libvirt PATCH 5/7] Meson: Define "DYNAMIC_ANALYSIS" if built with sanitizers enabled

Tim Wiederhake twiederh at redhat.com
Thu Aug 5 13:08:49 UTC 2021


This is complementary to the "STATIC_ANALYSIS" macro defined in
"internal.h", but not as straight-forward to detect:

clang defines "__has_feature(address_sanitizer)" if the address
sanitizer is enabled. "__has_feature" is clang specific and does not
exist in gcc (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60512)

gcc, depending on the version, defines "__SANITIZE_ADDRESS__ 1" if
compiled with the address sanitizer enabled. No similar macro is
defined for the undefined behavior sanitizer.

Instead, let meson set this symbol.

Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 meson.build | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/meson.build b/meson.build
index e25dc17fc8..2c424076ba 100644
--- a/meson.build
+++ b/meson.build
@@ -224,6 +224,10 @@ alloc_max = run_command(
   'print(min(2**(@0@ * 8 - 1) - 1, 2**(@1@ * 8) - 1))'.format(ptrdiff_max, size_max),
 )
 
+if (get_option('b_sanitize') != 'none')
+  conf.set('DYNAMIC_ANALYSIS', 1)
+endif
+
 # sanitizer instrumentation may enlarge stack frames
 stack_frame_size = get_option('b_sanitize') == 'none' ? 4096 : 8192
 
-- 
2.31.1




More information about the libvir-list mailing list