From 06fdd44c5d3f4ecdad6b453124ad6bc2e9e9c39c Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Thu, 10 Feb 2022 12:56:40 +0100 Subject: [PATCH] mk/fio: link shared sanitizers for clang builds 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. This patch fixes ubsan, but there are still some issues with clang's address sanitizer. It seems as if the address sanitizer ignored some/all of the suppression rules, but in the interest of fixing the ubsan build, this will be fixed by a separate patch at a later time. Fixes #2367 Signed-off-by: Konrad Sztyber Change-Id: I416a410214826b4ef8c25eeeef95272ef1742d7e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11662 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Dong Yi Reviewed-by: Jun Wen --- mk/spdk.fio.mk | 11 +++++++++++ test/common/autotest_common.sh | 13 ++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) 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 "$@" }