Commit 06fdd44c authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

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: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I416a410214826b4ef8c25eeeef95272ef1742d7e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11662


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDong Yi <dongx.yi@intel.com>
Reviewed-by: default avatarJun Wen <junx.wen@intel.com>
parent 24d34ac7
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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)
+10 −3
Original line number Diff line number Diff line
@@ -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 "$@"
}