language : 'c'
)
+# Clang as of v18, relies on statically linking the sanitizers. This causes two
+# distinct issues:
+# - the shared library is underlinked, so the build fails
+# - the modules (that we dlopen/ld_preload) are underlinked so the tests fail
+#
+# Force shared libasan (GCC defaults to shared and this toggle doesn't exist),
+# which combined with the LD_PRELOAD in our wrapper makes everything happy.
+if get_option('b_sanitize') != 'none' and cc.get_id() == 'clang'
+ add_project_arguments('-shared-libasan', language : 'c')
+ add_project_link_arguments('-shared-libasan', language : 'c')
+endif
################################################################################
# Options
################################################################################
# set -euo pipefail # don't set these, since this script is sourced
-OUR_PRELOAD=$(gcc -print-file-name=libasan.so)
+if [[ ${CC-} == *gcc* ]]; then
+ OUR_PRELOAD=$("$CC" -print-file-name=libasan.so)
+elif [[ ${CC-} == *clang* ]]; then
+ OUR_PRELOAD=$("$CC" -print-file-name=libclang_rt.asan-x86_64.so)
+else
+ echo "Unknown compiler CC=\"${CC-}\" - gcc and clang are supported."
+ echo "Assuming \"gcc\", manually set the variable and retry if needed."
+ echo
+ OUR_PRELOAD=$(gcc -print-file-name=libasan.so)
+fi
if test -n "$OUR_PRELOAD"; then
# In some cases, like in Fedora, the file is a script which cannot be