summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-04-06 14:52:19 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-04-12 12:00:10 -0400
commita3bed764555f76003bb03c023123846fdff76f1b (patch)
tree4a1f98a61ca08c82bfc839c727f8da9ea81c51f0
parenta812c5c8c9aabf6e0fd934bd55ec553c6dbb60c2 (diff)
downloadbfs-a3bed764555f76003bb03c023123846fdff76f1b.tar.xz
build: Fix tsan
-rw-r--r--Makefile72
-rwxr-xr-xtests/tests.sh11
2 files changed, 45 insertions, 38 deletions
diff --git a/Makefile b/Makefile
index b509065..57ff238 100644
--- a/Makefile
+++ b/Makefile
@@ -65,7 +65,42 @@ MSAN := $(filter msan,$(MAKECMDGOALS))
TSAN := $(filter tsan,$(MAKECMDGOALS))
UBSAN := $(filter ubsan,$(MAKECMDGOALS))
-ifndef MSAN
+ifdef ASAN
+LOCAL_CFLAGS += -fsanitize=address
+SANITIZE := y
+endif
+
+ifdef LSAN
+LOCAL_CFLAGS += -fsanitize=leak
+SANITIZE := y
+endif
+
+ifdef MSAN
+# msan needs all code instrumented
+NOLIBS := y
+LOCAL_CFLAGS += -fsanitize=memory -fsanitize-memory-track-origins
+SANITIZE := y
+endif
+
+ifdef TSAN
+# tsan needs all code instrumented
+NOLIBS := y
+# https://github.com/google/sanitizers/issues/342
+LOCAL_CPPFLAGS += -DBFS_TARGET_CLONES=false
+LOCAL_CFLAGS += -fsanitize=thread
+SANITIZE := y
+endif
+
+ifdef UBSAN
+LOCAL_CFLAGS += -fsanitize=undefined
+SANITIZE := y
+endif
+
+ifdef SANITIZE
+LOCAL_CFLAGS += -fno-sanitize-recover=all
+endif
+
+ifndef NOLIBS
WITH_ONIGURUMA := y
endif
@@ -82,10 +117,10 @@ endif
LOCAL_CFLAGS += $(ONIG_CFLAGS)
LOCAL_LDLIBS += $(ONIG_LDLIBS)
-endif
+endif # WITH_ONIGURUMA
ifeq ($(OS),Linux)
-ifndef MSAN # These libraries are not built with msan
+ifndef NOLIBS
WITH_ACL := y
WITH_ATTR := y
WITH_LIBCAP := y
@@ -111,41 +146,12 @@ endif
LOCAL_LDFLAGS += -Wl,--as-needed
LOCAL_LDLIBS += -lrt
-endif
+endif # Linux
ifeq ($(OS),NetBSD)
LOCAL_LDLIBS += -lutil
endif
-ifdef ASAN
-LOCAL_CFLAGS += -fsanitize=address
-SANITIZE := y
-endif
-
-ifdef LSAN
-LOCAL_CFLAGS += -fsanitize=leak
-SANITIZE := y
-endif
-
-ifdef MSAN
-LOCAL_CFLAGS += -fsanitize=memory -fsanitize-memory-track-origins
-SANITIZE := y
-endif
-
-ifdef TSAN
-LOCAL_CFLAGS += -fsanitize=thread
-SANITIZE := y
-endif
-
-ifdef UBSAN
-LOCAL_CFLAGS += -fsanitize=undefined
-SANITIZE := y
-endif
-
-ifdef SANITIZE
-LOCAL_CFLAGS += -fno-sanitize-recover=all
-endif
-
ifneq ($(filter gcov,$(MAKECMDGOALS)),)
LOCAL_CFLAGS += --coverage
# gcov only intercepts fork()/exec() with -std=gnu*
diff --git a/tests/tests.sh b/tests/tests.sh
index 98d332c..9265481 100755
--- a/tests/tests.sh
+++ b/tests/tests.sh
@@ -9,11 +9,12 @@ umask 022
export LC_ALL=C
export TZ=UTC0
-export ASAN_OPTIONS="abort_on_error=1:log_to_syslog=0"
-export LSAN_OPTIONS="abort_on_error=1:log_to_syslog=0"
-export MSAN_OPTIONS="abort_on_error=1:log_to_syslog=0"
-export TSAN_OPTIONS="abort_on_error=1:log_to_syslog=0"
-export UBSAN_OPTIONS="abort_on_error=1:log_to_syslog=0"
+SAN_OPTIONS="halt_on_error=1:log_to_syslog=0"
+export ASAN_OPTIONS="$SAN_OPTIONS"
+export LSAN_OPTIONS="$SAN_OPTIONS"
+export MSAN_OPTIONS="$SAN_OPTIONS"
+export TSAN_OPTIONS="$SAN_OPTIONS"
+export UBSAN_OPTIONS="$SAN_OPTIONS"
export LS_COLORS=""
unset BFS_COLORS