diff mbox series

[1/2] selftests/openat2: Run-time check for -fsanitize=undefined

Message ID 20230629162301.1234157-2-bjorn@kernel.org (mailing list archive)
State Handled Elsewhere
Headers show
Series Two cross-compilation kselftest fixes | expand

Checks

Context Check Description
conchuod/cover_letter success Series has a cover letter
conchuod/tree_selection success Guessed tree name to be for-next at HEAD 488833ccdcac
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 6 and now 6
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 8 this patch: 8
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 8 this patch: 8
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 20 this patch: 20
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Björn Töpel June 29, 2023, 4:22 p.m. UTC
From: Björn Töpel <bjorn@rivosinc.com>

Some architectures, e.g. riscv, does not have support for the GCC
option '-fsanitize=undefined'.

Check for '-fsanitize=undefined' support, and only add it to CFLAGS if
supported.

Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
---
 tools/testing/selftests/openat2/Makefile | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/openat2/Makefile b/tools/testing/selftests/openat2/Makefile
index 843ba56d8e49..f13ad02a18ea 100644
--- a/tools/testing/selftests/openat2/Makefile
+++ b/tools/testing/selftests/openat2/Makefile
@@ -1,6 +1,13 @@ 
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined
+# We need this for the "try-run" macro.
+include ../../../build/Build.include
+
+CFLAGS += -Wall -O2 -g -fsanitize=address
+CFLAGS += $(call try-run, \
+	echo 'int main() {}' | $(CC) -fsanitize=undefined -x c - -o /dev/null, \
+	-fsanitize=undefined,)
+
 TEST_GEN_PROGS := openat2_test resolve_test rename_attack_test
 
 include ../lib.mk