From 19b4d6bb428a94359f0aca524867a8066afe8b5c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 2 Jul 2025 10:51:22 -0400 Subject: build: Add support for TySan There are some false positives, so it's not added to distcheck yet. --- build/flags.mk | 9 ++++++--- configure | 6 +++--- src/bfs.h | 5 ++++- src/prelude.h | 3 +++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/build/flags.mk b/build/flags.mk index 3748a8a..d6f9499 100644 --- a/build/flags.mk +++ b/build/flags.mk @@ -26,6 +26,7 @@ _ASAN := ${TRUTHY,${ASAN}} _LSAN := ${TRUTHY,${LSAN}} _MSAN := ${TRUTHY,${MSAN}} _TSAN := ${TRUTHY,${TSAN}} +_TYSAN := ${TRUTHY,${TYSAN}} _UBSAN := ${TRUTHY,${UBSAN}} _GCOV := ${TRUTHY,${GCOV}} _LINT := ${TRUTHY,${LINT}} @@ -38,21 +39,23 @@ ASAN_CFLAGS,y := -fsanitize=address LSAN_CFLAGS,y := -fsanitize=leak MSAN_CFLAGS,y := -fsanitize=memory -fsanitize-memory-track-origins TSAN_CFLAGS,y := -fsanitize=thread +TYSAN_CFLAGS,y := -fsanitize=type UBSAN_CFLAGS,y := -fsanitize=undefined _CFLAGS += ${ASAN_CFLAGS,${_ASAN}} _CFLAGS += ${LSAN_CFLAGS,${_LSAN}} _CFLAGS += ${MSAN_CFLAGS,${_MSAN}} _CFLAGS += ${TSAN_CFLAGS,${_TSAN}} +_CFLAGS += ${TYSAN_CFLAGS,${_TYSAN}} _CFLAGS += ${UBSAN_CFLAGS,${_UBSAN}} SAN_CFLAGS,y := -fno-sanitize-recover=all -INSANE := ${NOT,${_ASAN}${_LSAN}${_MSAN}${_TSAN}${_UBSAN}} +INSANE := ${NOT,${_ASAN}${_LSAN}${_MSAN}${_TSAN}${_TYSAN}${_UBSAN}} SAN := ${NOT,${INSANE}} _CFLAGS += ${SAN_CFLAGS,${SAN}} -# MSAN and TSAN both need all code to be instrumented -YESLIBS := ${NOT,${_MSAN}${_TSAN}} +# MSan, TSan, and TySan need all code to be instrumented +YESLIBS := ${NOT,${_MSAN}${_TSAN}${_TYSAN}} NOLIBS ?= ${NOT,${YESLIBS}} # gcov only intercepts fork()/exec() with -std=gnu* diff --git a/configure b/configure index 7f0bd04..51b543e 100755 --- a/configure +++ b/configure @@ -40,7 +40,7 @@ The default flags result in a plain debug build. Other build profiles include: --enable-release Enable optimizations, disable assertions - --enable-{asan,lsan,msan,tsan,ubsan} + --enable-{asan,lsan,msan,tsan,tysan,ubsan} Enable sanitizers --enable-gcov Enable code coverage instrumentation @@ -164,7 +164,7 @@ for arg; do --enable-*|--disable-*) case "$name" in - release|lto|asan|lsan|msan|tsan|ubsan|lint|gcov) + release|lto|asan|lsan|msan|tsan|tysan|ubsan|lint|gcov) set -- "$@" "$NAME=$yn" ;; *) @@ -197,7 +197,7 @@ for arg; do ;; # Warn about MAKE variables that have documented configure flags - RELEASE=*|LTO=*|ASAN=*|LSAN=*|MSAN=*|TSAN=*|UBSAN=*|LINT=*|GCOV=*) + RELEASE=*|LTO=*|ASAN=*|LSAN=*|MSAN=*|TSAN=*|TYSAN=*|UBSAN=*|LINT=*|GCOV=*) name=$(printf '%s' "$NAME" | tr 'A-Z_' 'a-z-') warn '"%s" is deprecated; use --enable-%s' "$arg" "$name" set -- "$@" "$arg" diff --git a/src/bfs.h b/src/bfs.h index 3cee727..70a7282 100644 --- a/src/bfs.h +++ b/src/bfs.h @@ -202,7 +202,10 @@ extern const char bfs_ldlibs[]; * Disabled on TSan due to https://github.com/google/sanitizers/issues/342. */ #ifndef BFS_USE_TARGET_CLONES -# if __has_attribute(target_clones) && (__GLIBC__ || __FreeBSD__) && !__SANITIZE_THREAD__ +# if __has_attribute(target_clones) \ + && (__GLIBC__ || __FreeBSD__) \ + && !__SANITIZE_THREAD__ \ + && !__SANITIZE_TYPE__ # define BFS_USE_TARGET_CLONES true # else # define BFS_USE_TARGET_CLONES false diff --git a/src/prelude.h b/src/prelude.h index de89a6c..3b1c4e5 100644 --- a/src/prelude.h +++ b/src/prelude.h @@ -126,5 +126,8 @@ #if __has_feature(thread_sanitizer) && !defined(__SANITIZE_THREAD__) # define __SANITIZE_THREAD__ true #endif +#if __has_feature(type_sanitizer) && !defined(__SANITIZE_TYPE__) +# define __SANITIZE_TYPE__ true +#endif #endif // BFS_PRELUDE_H -- cgit v1.2.3