From 995d50b5559e893378012db71aa813d0abcc0046 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 10 Nov 2022 09:39:26 -0500 Subject: [PATCH] MT#55524 work around buggy libasan On bookworm and later, libasan reports a false positive in combination with pthread_cleanup_push() (see [1]). Work around this by not using the thread cleanup handler when running the asan build, and instead use a shorter thread sleep time. [1] https://gcc.gnu.org/bugzilla//show_bug.cgi?id=82109 Change-Id: Ieffdc0b13f470445f1f8e1d2448c6af6d8dd68e0 (cherry picked from commit c9a5714df79d4fefeba70f173a897c7a5c87c787) --- Makefile | 1 + daemon/aux.c | 6 ++++++ include/aux.h | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/Makefile b/Makefile index 9ffb60634..dfa4ed623 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ ifeq ($(DO_ASAN_FLAGS),1) ASAN_FLAGS = -ggdb -O0 -fsanitize=address -fsanitize=leak -fsanitize=undefined CFLAGS ?= -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wstrict-prototypes CFLAGS += $(ASAN_FLAGS) +CFLAGS += -DASAN_BUILD LDFLAGS += $(ASAN_FLAGS) export CFLAGS export LDFLAGS diff --git a/daemon/aux.c b/daemon/aux.c index fb4ebe821..88e68025d 100644 --- a/daemon/aux.c +++ b/daemon/aux.c @@ -246,9 +246,15 @@ static void *thread_detach_func(void *d) { dt->priority, strerror(errno)); } +#ifndef ASAN_BUILD pthread_cleanup_push(thread_detach_cleanup, dt); +#endif dt->func(dt->data); +#ifndef ASAN_BUILD pthread_cleanup_pop(true); +#else + thread_detach_cleanup(dt); +#endif return NULL; } diff --git a/include/aux.h b/include/aux.h index 32126831f..0dffb50f6 100644 --- a/include/aux.h +++ b/include/aux.h @@ -349,9 +349,15 @@ INLINE void thread_create_detach(void (*f)(void *), void *a, const char *name) { thread_create_detach_prio(f, a, NULL, 0, name); } +#ifndef ASAN_BUILD #define thread_cancel_enable() pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) #define thread_cancel_disable() pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) #define thread_sleep_time 10000 /* ms */ +#else +#define thread_cancel_enable() ((void)0) +#define thread_cancel_disable() ((void)0) +#define thread_sleep_time 100 /* ms */ +#endif