From 5a970390109de41eb65cb456037359ed39a29fa0 Mon Sep 17 00:00:00 2001 From: Kirk Shoop Date: Wed, 15 Jan 2020 12:42:28 -0800 Subject: [PATCH] prevent asan failures in SingletonThreadLocal Summary: I have been encountering ``` AddressSanitizer:DEADLYSIGNAL ================================================================= ==937752==ERROR: AddressSanitizer: SEGV on unknown address 0x24a12000e4f18 (pc 0x7f3902a6e696 bp 0x7f37bc5e4380 sp 0x7f37bc5e42a0 T107) ==937752==The signal is caused by a READ memory access. SCARINESS: 20 (wild-addr-read) #0 0x7f3902a6e695 in folly::ThreadLocalPtr, void, folly::detail::DefaultMake >, void>::Wrapper, void, void>::get() const folly/ThreadLocal.h:160 #1 0x7f3902a6d600 in get folly/ThreadLocal.h:69 #2 0x7f3902a6d600 in folly::ThreadLocal, void, folly::detail::DefaultMake >, void>::Wrapper, void, void>::operator*() const folly/ThreadLocal.h:78 #3 0x7f3902a6ca1b in folly::SingletonThreadLocal, void, folly::detail::DefaultMake >, void>::getWrapper() folly/SingletonThreadLocal.h:149 #4 0x7f3902a6cbe5 in folly::SingletonThreadLocal, void, folly::detail::DefaultMake >, void>::LocalLifetime::~LocalLifetime() folly/SingletonThreadLocal.h:121 #5 0x7f38f04d9fd5 in (anonymous namespace)::run(void*) /data/users/kirkshoop/gcc/trunk/libstdc++-v3/libsupc++/atexit_thread.cc:75:16 #6 0x7f38ef9ee551 in __nptl_deallocate_tsd.part.8 /home/engshare/third-party2/glibc/2.26/src/glibc-2.26/nptl/pthread_create.c:301:8 #7 0x7f38ef9ef7c8 in __nptl_deallocate_tsd /home/engshare/third-party2/glibc/2.26/src/glibc-2.26/sysdeps/nptl/futex-internal.h:200:3 #8 0x7f38ef9ef7c8 in start_thread /home/engshare/third-party2/glibc/2.26/src/glibc-2.26/nptl/pthread_create.c:475:3 ``` I tried using a unique Tag for the SingletonThreadLocal for debugging purposes and this seemed to fix the issue. Reviewed By: magedm Differential Revision: D19356179 fbshipit-source-id: a18c6b02f0a40e0509753075614eeff71d859bf7 --- folly/synchronization/HazptrThrLocal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/folly/synchronization/HazptrThrLocal.h b/folly/synchronization/HazptrThrLocal.h index 0bed75e7ca9..1f0c2aa70da 100644 --- a/folly/synchronization/HazptrThrLocal.h +++ b/folly/synchronization/HazptrThrLocal.h @@ -149,10 +149,11 @@ class hazptr_tc { } }; // hazptr_tc +struct hazptr_tc_tls_tag {}; /** hazptr_tc_tls */ template