]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Meson: Use builtin feature to handle sanitizers
authorFred Morcos <fred.morcos@open-xchange.com>
Tue, 8 Aug 2023 13:14:30 +0000 (15:14 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Wed, 20 Mar 2024 12:28:33 +0000 (13:28 +0100)
meson.build
meson/sanitizers/address-sanitizer-fiber-switching/meson.build [new file with mode: 0644]
meson/sanitizers/address-sanitizer/meson.build [deleted file]
meson/sanitizers/meson.build
meson_options.txt

index 31a8b0916507ebc090021fe80063a1d75bcda57a..859a92f25d453f632b227d0739d0b532b58dd4d4 100644 (file)
@@ -68,8 +68,7 @@ subdir('meson/ixfrdist')                 # Ixfrdist
 subdir('meson/systemd')                  # Systemd and unit file handling
 subdir('meson/code-coverage')            # Code coverage
 subdir('meson/auto-var-init')            # Automatic Variable Initialization
-# TODO Use meson's -Db_sanitize option?
-# subdir('meson/sanitizers')               # Sanitizers
+subdir('meson/sanitizers')               # Sanitizers
 subdir('meson/malloc-trace')             # Malloc-trace
 # TODO Use meson's -Db_lto* options?
 subdir('meson/lto')                      # Link-time Optimization
diff --git a/meson/sanitizers/address-sanitizer-fiber-switching/meson.build b/meson/sanitizers/address-sanitizer-fiber-switching/meson.build
new file mode 100644 (file)
index 0000000..35cbb31
--- /dev/null
@@ -0,0 +1,48 @@
+# Address Sanitizer Fiber Switching
+# Inputs: conf
+
+prog_single_pointer = '''
+#include <sanitizer/common_interface_defs.h>
+
+int main() {
+  __sanitizer_finish_switch_fiber(nullptr);
+  return 0;
+}
+'''
+
+prog_three_pointers = '''
+#include <sanitizer/common_interface_defs.h>
+
+int main() {
+  __sanitizer_finish_switch_fiber(nullptr, nullptr, nullptr);
+  return 0;
+}
+'''
+
+single_pointer = false
+three_pointers = false
+
+if cxx.check_header('sanitizer/common_interface_defs.h', required: false)
+  if cxx.has_header_symbol('sanitizer/common_interface_defs.h', '__sanitizer_start_switch_fiber', required: false)
+    if cxx.compiles(prog_single_pointer, name: '__sanitizer_finish_switch_fiber with a single pointer')
+      single_pointer = true
+    endif
+
+    if cxx.compiles(prog_three_pointers, name: '__sanitizer_finish_switch_fiber with three pointers')
+      three_pointers = true
+    endif
+  else
+    warning('Address Sanitizer fiber switching is not available')
+  endif
+
+else
+  warning('Address Sanitizer requested but `sanitizer/common_interface_defs.h` is invalid or cannot be found. Address Sanitizer fiber switching is not available')
+endif
+
+if not single_pointer and not three_pointers
+  warning('Address Sanitizer fiber switching is not available due to an unknown API version')
+endif
+
+conf.set10('HAVE_FIBER_SANITIZER', single_pointer or three_pointers, description: 'Address Sanitizer fiber annotation interface is available')
+conf.set10('HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR', single_pointer, description: 'Address Sanitizer: __sanitizer_finish_switch_fiber takes only a pointer')
+conf.set10('HAVE_SANITIZER_FINISH_SWITCH_FIBER_THREE_PTRS', three_pointers, description: 'Address Sanitizer: __sanitizer_finish_switch_fiber takes three pointers')
diff --git a/meson/sanitizers/address-sanitizer/meson.build b/meson/sanitizers/address-sanitizer/meson.build
deleted file mode 100644 (file)
index bf3d30a..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-# Address Sanitizer
-# Inputs: conf
-
-opt_address_sanitizer = get_option('sanitizer-address')
-
-if not opt_address_sanitizer
-  subdir_done()
-endif
-
-if not cxx.has_argument('-fsanitize=address')
-  error('Address Sanitizer requested but compiler does not support `-fsanitize=address`')
-endif
-
-if not cxx.check_header('sanitizer/common_interface_defs.h')
-  error('Address Sanitizer requested but `sanitizer/common_interface_defs.h` is invalid or cannot be found')
-endif
-
-if not cxx.has_header_symbol('sanitizer/common_interface_defs.h', '__sanitizer_start_switch_fiber', required: false)
-  warning('Address Sanitizer fiber switching is not available')
-endif
-
-single_pointer = false
-prog_single_pointer = '''
-#include <sanitizer/common_interface_defs.h>
-
-int main() {
-  __sanitizer_finish_switch_fiber(nullptr);
-  return 0;
-}
-'''
-
-three_pointers = false
-prog_three_pointers = '''
-#include <sanitizer/common_interface_defs.h>
-
-int main() {
-  __sanitizer_finish_switch_fiber(nullptr, nullptr, nullptr);
-  return 0;
-}
-'''
-
-if cxx.compiles(prog_single_pointer, name: '__sanitizer_finish_switch_fiber with a single pointer')
-  single_pointer = true
-endif
-
-if cxx.compiles(prog_three_pointers, name: '__sanitizer_finish_switch_fiber with three pointers')
-  three_pointers = true
-endif
-
-if not single_pointer and not three_pointers
-  warning('Address Sanitizer fiber switching is not available due to an unknown API version')
-endif
-
-conf.set10('HAVE_FIBER_SANITIZER', single_pointer or three_pointers, description: 'Address Sanitizer fiber annotation interface is available')
-conf.set10('HAVE_SANITIZER_FINISH_SWITCH_FIBER_SINGLE_PTR', single_pointer, description: 'Address Sanitizer: __sanitizer_finish_switch_fiber takes only a pointer')
-conf.set10('HAVE_SANITIZER_FINISH_SWITCH_FIBER_THREE_PTRS', three_pointers, description: 'Address Sanitizer: __sanitizer_finish_switch_fiber takes three pointers')
-
-add_global_arguments('-fsanitize=address', language: ['cpp'])
-
-summary('address', opt_address_sanitizer, bool_yn: true, section: 'Sanitizers')
index 3850783e427cdac75038efce21d429968d35fe63..b207ccf03253ce896e64f0846099b864d37850f2 100644 (file)
@@ -1,46 +1,13 @@
 # Sanitizers
 
-subdir('address-sanitizer')
+opt_sanitize = get_option('b_sanitize')
 
-sanitizers = {
-  'memory': 'Memory',
-  'thread': 'Thread',
-  'leak': 'Leak',
-  'undefined': 'Undefined Behavior',
-}
-
-foreach sanitizer, name: sanitizers
-  opt_name = 'opt_' + sanitizer + '_sanitizer'
-  set_variable(opt_name, get_option('sanitizer-' + sanitizer))
-
-  if not get_variable(opt_name)
-    continue
-  endif
-
-  compiler_opt = '-fsanitize=' + sanitizer
-  if not cxx.has_argument(compiler_opt)
-    error(name + ' Sanitizer requested but compiler does not support `' + compiler_opt + '`')
-  endif
-  add_global_arguments(compiler_opt, language: ['cpp'])
-  summary(name, get_variable(opt_name), bool_yn: true, section: 'Sanitizers')
-endforeach
-
-if opt_address_sanitizer and opt_thread_sanitizer
-  error('Address Sanitizer is not compatible with Thread Sanitizer')
+if opt_sanitize == 'address' or opt_sanitize == 'address,undefined'
+  subdir('address-sanitizer-fiber-switching')
 endif
 
-if opt_memory_sanitizer and opt_address_sanitizer
-  error('Memory Sanitizer is not compatible with Address Sanitizer')
+if opt_sanitize != 'none'
+  add_global_arguments('-fno-omit-frame-pointer', language: ['c', 'cpp'])
 endif
 
-if opt_memory_sanitizer and opt_leak_sanitizer
-  error('Memory Sanitizer is not compatible with Leak Sanitizer')
-endif
-
-if opt_memory_sanitizer and opt_thread_sanitizer
-  error('Memory Sanitizer is not compatible with Thread Sanitizer')
-endif
-
-if opt_address_sanitizer or opt_thread_sanitizer or opt_leak_sanitizer or opt_undefined_behavior_sanitizer or opt_memory_sanitizer
-  add_global_arguments('-fno-omit-frame-pointer', language: ['cpp'])
-endif
+summary('Sanitizers', opt_sanitize, bool_yn: true, section: 'Configuration')
index 63de43de5341aa3e0d95e9a4d2a15d5081261f72..d4f14a7a1b3c358ed9974b57b5f1a40590b1566a 100644 (file)
@@ -47,12 +47,6 @@ option('lua-records', type: 'boolean', value: true, description: 'Support Lua re
 option('systemd-service-user', type: 'string', value: 'pdns', description: 'Systemd service user (setuid and unit file; user is not created)')
 option('systemd-service-group', type: 'string', value: 'pdns', description: 'Systemd service group (setgid and unit file; group is not created)')
 option('auto-var-init', type: 'combo', value: 'disabled', choices: ['zero', 'pattern', 'disabled'], description: 'Enable initialization of automatic variables')
-# TODO Use meson's -Db_sanitize option?
-# option('sanitizer-address', type: 'boolean', value: false, description: 'Enable the Address Sanitizer')
-# option('sanitizer-memory', type: 'boolean', value: false, description: 'Enable the Memory Sanitizer')
-# option('sanitizer-thread', type: 'boolean', value: false, description: 'Enable the Thread Sanitizer')
-# option('sanitizer-leak', type: 'boolean', value: false, description: 'Enable the Leak Sanitizer')
-# option('sanitizer-undefined', type: 'boolean', value: false, description: 'Enable the Undefined Behavior Sanitizer')
 option('malloc-trace', type: 'boolean', value: false, description: 'Enable malloc-trace')
 # TODO Use meson's -Db_lto* options?
 option('lto', type: 'combo', choices: ['yes', 'no', 'thin', 'auto'], value: 'no', description: 'Enable link-time optimization')