From 20de6d6712d586b7d25624bd836d9f84331b1f23 Mon Sep 17 00:00:00 2001 From: Clemens Lang Date: Mon, 29 Jul 2024 16:01:09 +0200 Subject: [PATCH] tests: Fix ASAN build on macOS On macOS, the variable for library preloading is DYLD_INSERT_LIBRARIES, not LD_PRELOAD. Adjust the CHECKER env variable to use that on macOS machines. Change fake_dlclose to a library rather than a shared module. This doesn't make a difference on Linux, but on macOS, dyld(1) refuses to insert a shared module into a processes address space using DYLD_INSERT_LIBRARIES, but allows a library in the same place. Signed-off-by: Clemens Lang --- tests/meson.build | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/meson.build b/tests/meson.build index 9ec9234a..c6ffb37e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -76,7 +76,7 @@ if get_option('b_sanitize') == 'address' endif # Avoids closing dlopened libraries for ASan to be able to print usable traces - fake_dlclose = shared_module( + fake_dlclose = shared_library( 'fake_dlclose', 'fake_dlclose.c', name_prefix: '', @@ -85,12 +85,18 @@ if get_option('b_sanitize') == 'address' test_env.set('ASAN_OPTIONS', 'fast_unwind_on_malloc=0') test_env.set('LSAN_OPTIONS', 'suppressions=@0@/lsan.supp'.format(meson.current_source_dir())) test_env.set('FAKE_DLCLOSE', fake_dlclose.full_path()) + + preload_env_var = 'LD_PRELOAD' + if host_machine.system() == 'darwin' + preload_env_var = 'DYLD_INSERT_LIBRARIES' + endif + # LD_PRELOAD is needed before invoking openssl as it is not instrumented with # asan and asan needs to be loaded as a first dynamic library of the process. if preload_libasan != 'no' - test_env.set('CHECKER', 'env LD_PRELOAD=@0@:@1@'.format(preload_libasan, fake_dlclose.full_path())) + test_env.set('CHECKER', 'env @0@=@1@:@2@'.format(preload_env_var, preload_libasan, fake_dlclose.full_path())) else - test_env.set('CHECKER', 'env LD_PRELOAD=@0@'.format(fake_dlclose.full_path())) + test_env.set('CHECKER', 'env @0@=@1@'.format(preload_env_var, fake_dlclose.full_path())) endif endif