-
Notifications
You must be signed in to change notification settings - Fork 992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SEGFAULT when using C11 threading primitives #1195
Comments
Clang 7 is very old, the master is at 11.0.0 right now. |
I'm seeing this exact thing both with clang 11.0.0 and gcc 10.2.1. With clang it always happens up, but with gcc it only shows up if my thread does work.
#include <threads.h>
static int s_foo;
static int thread(void* p)
{
s_foo = 1; // Without this it won't SIGSEGV with gcc
return 0;
}
int main(int argc, char** argv)
{
thrd_t thrd;
thrd_create(&thrd, &thread, NULL);
thrd_join(thrd, NULL);
} Compiled with: Outputs:
Exact same backtrace and instruction as the original report. But with symbols:
|
Sanitizers don't have interceptors for C threading primitives, and somehow they don't call pthread functions (or call via internal uninterceptable symbols). If that's the case, I guess sanitizers would need interceptors for C threading primitives. However, we somehow need to make sure we don't intercept both C and pthread primitives for the same function. |
Hi, exactly the same segfault is reproducing in our CI with Clang 13.0.1 and it does not seem to be related to C11 threading primitives: ClickHouse/ClickHouse#36547 (comment) |
It looks like thread sanitizer does not support C11 threads [1]. To run with thread sanitizer, one hence needs to build with -D__STDC_NO_THREADS__=1 to use the fallback threads implementation in this source tree. [1]: google/sanitizers#1195 (comment) Alyssa Ross reported in issue #95 that FreeBSD defines PTHREAD_MUTEX_NORMAL as enum and not as macro, so we'd redefine it as macro with a value that does not exist on FreeBSD. Check for the existence of PTHREAD_MUTEX_TIMED_NP as macro before redefining PTHREAD_MUTEX_NORMAL to it. This should leave things as they are on FreeBSD and use the PTHREAD_MUTEX_NORMAL enum. Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
It looks like thread sanitizer does not support C11 threads [1]. To run with thread sanitizer, one hence needs to build with -D__STDC_NO_THREADS__=1 to use the fallback threads implementation in this source tree. [1]: google/sanitizers#1195 (comment) Alyssa Ross reported in issue #95 that FreeBSD defines PTHREAD_MUTEX_NORMAL as enum and not as macro, so we'd redefine it as macro with a value that does not exist on FreeBSD. Check for the existence of PTHREAD_MUTEX_TIMED_NP as macro before redefining PTHREAD_MUTEX_NORMAL to it. This should leave things as they are on FreeBSD and use the PTHREAD_MUTEX_NORMAL enum. Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
Hi,
I'm playing around with TSAN and the C11 threading primitives in <threads.h>. If I modify one of the example data-race programs I get a segfault in both clang and GCC when I run with TSAN enabled. This is using Debian 10, clang version 7.0.1-8
Compiled with
clang -fsanitize=thread -g -O1 new-main.c -o c11
outputs
GDB backtrace
GDB Dissassembly
The text was updated successfully, but these errors were encountered: