diff --git a/mk/spdk.fio.mk b/mk/spdk.fio.mk index fb393c349..f12b858c6 100644 --- a/mk/spdk.fio.mk +++ b/mk/spdk.fio.mk @@ -48,6 +48,17 @@ CFLAGS += -Wno-error endif LDFLAGS += -shared -rdynamic -Wl,-z,nodelete +# By default, clang uses static sanitizer libraries, which means that the executable needs to have +# them linked in. Since we don't control how the fio binary is compiled, we need to use the shared +# libraries. +ifeq ($(CC_TYPE),clang) +ifneq ($(filter y,$(CONFIG_ASAN) $(CONFIG_UBSAN)),) +LDFLAGS += -shared-libsan +# clang's sanitizers aren't in ld's search path by default, so we need to add it manually +LDFLAGS += -Wl,-rpath=$(shell $(CC) -print-resource-dir)/lib +endif +endif + CLEAN_FILES = $(FIO_PLUGIN) all : $(FIO_PLUGIN) diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index 095b30a14..7728444b9 100755 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -1173,13 +1173,20 @@ EOL function fio_plugin() { # Setup fio binary cmd line local fio_dir=$CONFIG_FIO_SOURCE_DIR + # gcc and clang uses different sanitizer libraries + local sanitizers=(libasan libclang_rt.asan) local plugin=$1 shift - # Preload AddressSanitizer library to fio if fio_plugin was compiled with it - local asan_lib - asan_lib=$(ldd $plugin | grep libasan | awk '{print $3}') + local asan_lib= + for sanitizer in "${sanitizers[@]}"; do + asan_lib=$(ldd $plugin | grep $sanitizer | awk '{print $3}') + if [[ -n "$asan_lib" ]]; then + break + fi + done + # Preload the sanitizer library to fio if fio_plugin was compiled with it LD_PRELOAD="$asan_lib $plugin" "$fio_dir"/fio "$@" }