From e0a3a5f2267b28b242c5e2fbaca261b0bbd607c0 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Tue, 18 Jun 2024 16:31:58 -0700 Subject: [PATCH] build: make UBSan work :) This is really just a question of turning off the production sanitizer configuration so we get nice diagnostics. Not much else to say. Change-Id: I76bd6d225320056ed95bd89955f00beff2db0d2f --- meson.build | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 672db4ddf..e6151e0a2 100644 --- a/meson.build +++ b/meson.build @@ -437,7 +437,9 @@ add_project_arguments( language : 'cpp', ) -if cxx.get_id() in ['gcc', 'clang'] +# We turn off the production UBSan if the slower dev UBSan is requested, to +# give better diagnostics. +if cxx.get_id() in ['gcc', 'clang'] and 'undefined' not in get_option('b_sanitize') # 2024-03-24: jade benchmarked the default sanitize reporting in clang and got # a regression of about 10% on hackage-packages.nix with clang. So we are trapping instead. # @@ -452,6 +454,11 @@ if cxx.get_id() in ['gcc', 'clang'] add_project_arguments(sanitize_args, language: 'cpp') add_project_link_arguments(sanitize_args, language: 'cpp') endif +# Clang's default of -no-shared-libsan on Linux causes link errors; on macOS it defaults to shared. +# GCC defaults to shared libsan so is fine. +if cxx.get_id() == 'clang' and get_option('b_sanitize') != '' + add_project_link_arguments('-shared-libsan', language : 'cpp') +endif add_project_link_arguments('-pthread', language : 'cpp') if cxx.get_linker_id() in ['ld.bfd', 'ld.gold']