Simple program segfaults when ThreadSanitizer is enabled

510 views
Skip to first unread message

Olivier Nicole

unread,
May 12, 2022, 8:11:53 AM5/12/22
to thread-sanitizer
Hi,

I tried out ThreadSanitizer on this simple program that spawns two threads: https://gist.github.com/OlivierNicole/20c6d58de1b773174a9bc093afb0cc09

The program runs fine but segfaults when instrumented by ThreadSanitizer:

    $ clang -Wall -Wextra -pedantic -std=c11 -pthread atomic_race.c
    $ ./a.out
    v = 10
    $ clang -Wall -Wextra -pedantic -std=c11 -pthread -fsanitize=thread atomic_race.c
    $ ./a.out
    ThreadSanitizer:DEADLYSIGNAL
    ==205049==ERROR: ThreadSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000490f8a bp 0x000000000000 sp 0x7f88234bf268 T205050)
    ==205049==The signal is caused by a WRITE memory access.
    ==205049==Hint: address points to the zero page.
    ThreadSanitizer:DEADLYSIGNAL
    ThreadSanitizer:DEADLYSIGNAL
    ThreadSanitizer: nested bug in the same thread, aborting.

Am I missing something?

Thanks,
Olivier

Olivier Nicole

unread,
May 12, 2022, 8:25:56 AM5/12/22
to thread-sanitizer
I forgot to mention that I use clang version 7.1.0 on Linux.

Dmitry Vyukov

unread,
May 12, 2022, 8:33:47 AM5/12/22
to Olivier Nicole, thread-sanitizer, Vitaly Buka, address-sanitizer, memory-s...@googlegroups.com
On Thu, 12 May 2022 at 14:25, Olivier Nicole <oli...@tarides.com> wrote:
>
> I forgot to mention that I use clang version 7.1.0 on Linux.

Hi Olivier,

clang 7 is too old, but this also reproduces with a fresh clang 15.
The root cause is that the C threading library not supported. I think
is equally broken for all sanitizers, they will crash or misbehave on
other programs (maybe during error reporting).

+Vitaly and asan/msan lists
> --
> You received this message because you are subscribed to the Google Groups "thread-sanitizer" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to thread-sanitiz...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/thread-sanitizer/cf72cdb2-20c1-40ce-9829-06f5ba063d5an%40googlegroups.com.

Olivier Nicole

unread,
May 13, 2022, 8:24:30 AM5/13/22
to thread-sanitizer
Hi Dmitry,

Thanks for pointing this out. Are standard C++ threads supported?

Dmitry Vyukov

unread,
May 13, 2022, 8:29:02 AM5/13/22
to Olivier Nicole, thread-sanitizer
On Fri, 13 May 2022 at 14:24, Olivier Nicole <oli...@tarides.com> wrote:
>
> Hi Dmitry,
>
> Thanks for pointing this out. Are standard C++ threads supported?


It seems so:
https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/tsan/compare_exchange.cpp#L66

Though I suspect it may depend on the implementation since sanitizers
only really intercept pthread_* calls.
> To view this discussion on the web visit https://groups.google.com/d/msgid/thread-sanitizer/bbe91ae1-12ee-416f-8d70-841b607a6baen%40googlegroups.com.

Olivier Nicole

unread,
May 13, 2022, 11:53:09 AM5/13/22
to thread-sanitizer
FWIW, the program translated to C++ runs as expected with ThreadSanitizer and the glibc 2.33.
Reply all
Reply to author
Forward
0 new messages