ivmai / bdwgc

The Boehm-Demers-Weiser conservative C/C++ Garbage Collector (bdwgc, also known as bdw-gc, boehm-gc, libgc)
https://www.hboehm.info/gc/
Other
2.87k stars 401 forks source link

Signals delivery fails in gctest on Ubuntu Jammy if compiled with TSan #543

Open ivmai opened 1 year ago

ivmai commented 1 year ago

Source: master (c94898b) Build: https://app.travis-ci.com/github/ivmai/bdwgc/jobs/599165124 Host: Ubuntu 22.04.1 LTS x64 Compiler: Ubuntu clang version 14.0.0-1ubuntu1 How to build: ./configure --enable-static && make -j check CFLAGS_EXTRA="-O3 -fsanitize=thread -fno-omit-frame-pointer"

Output:

$ cat gctest.log
Switched to incremental mode
Reading dirty bits from /proc
Signals delivery fails constantly at GC #54
Signals delivery fails constantly
FAIL gctest (exit status: 134)

Related: #435

ivmai commented 1 year ago

Source: master (6dfd81e) Build: https://app.travis-ci.com/github/ivmai/bdwgc/jobs/599750232

ivmai commented 1 year ago

Reproduced locally: CC=clang ./configure --enable-werror -disable-parallel-mark && make -j check CFLAGS_EXTRA="-fsanitize=thread -fno-omit-frame-pointer -D NTHREADS=10" Output: ./gctest Switched to incremental mode Reading dirty bits from /proc Signals delivery fails constantly at GC #502

ivmai commented 1 year ago

Latest build: https://app.travis-ci.com/github/ivmai/bdwgc/jobs/600058808 Source: master (274e5ce)

ivmai commented 1 year ago

Latest build: https://app.travis-ci.com/github/ivmai/bdwgc/jobs/600864563 Source: master (4bdf9b9)

disclaimtest failed too: Signals delivery fails constantly at GC #10 Signals delivery fails constantly Threaded disclaim test.

Reproduced locally (gctest only).

ivmai commented 1 year ago

gctest crash dump:

(gdb) t 1
[Switching to thread 1 (Thread 0x7f1094dfe640 (LWP 2997247))]
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=139709193905728) at ./nptl/pthread_kill.c:44
44      ./nptl/pthread_kill.c: No such file or directory.
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=139709193905728) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=139709193905728) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=139709193905728, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007f10a1d41476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007f10a1d277f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000055b608f0786b in abort ()
#6  0x00007f10a207a50b in resend_lost_signals_retry (n_live_threads=1, n_live_threads@entry=5, suspend_restart_all=0x7f10a207a0b0 <GC_suspend_all>) at pthread_stop_world.c:445
#7  0x00007f10a207a011 in GC_stop_world () at pthread_stop_world.c:1054
#8  0x00007f10a20529ff in GC_stopped_mark (stop_func=0x7f10a20538d0 <GC_timeout_stop_func>) at alloc.c:820
#9  0x00007f10a2051f5e in GC_maybe_gc () at alloc.c:505
#10 GC_collect_a_little_inner (n=n@entry=2) at alloc.c:736
#11 0x00007f10a205f646 in GC_alloc_large (lb=lb@entry=4576, k=k@entry=1, flags=flags@entry=0, align_m1=align_m1@entry=0) at malloc.c:55
#12 0x00007f10a205fd6a in GC_generic_malloc_aligned (lb=lb@entry=4574, k=k@entry=1, flags=flags@entry=0, align_m1=align_m1@entry=0) at malloc.c:271
#13 0x00007f10a206007d in GC_malloc_kind_global (lb=lb@entry=4574, k=k@entry=1) at malloc.c:344
#14 0x00007f10a20791ad in GC_malloc_kind (bytes=bytes@entry=4574, kind=kind@entry=1) at thread_local_alloc.c:187
#15 0x00007f10a20600ff in GC_malloc (lb=4574) at malloc.c:363
#16 0x000055b608f82cf3 in cons (x=0x7f1093732ae0, y=<optimized out>) at tests/gctest.c:320
#17 reverse1 (x=<optimized out>, y=<optimized out>) at tests/gctest.c:449
#18 reverse (x=<optimized out>) at tests/gctest.c:458
#19 reverse_test_inner (data=<optimized out>) at tests/gctest.c:944
#20 0x00007f10a2076936 in GC_call_with_gc_active (fn=0x55b608f82660 <reverse_test_inner>, client_data=0x2dbb07, client_data@entry=0x1) at pthread_support.c:2021
#21 0x000055b608f83094 in reverse_test_inner (data=0x0) at tests/gctest.c:847
#22 0x00007f10a2076240 in GC_do_blocking_inner (data=data@entry=0x7f1094dfd410 "`&\370\b\266U", context=<optimized out>) at pthread_support.c:1841
#23 0x00007f10a205f508 in GC_with_callee_saves_pushed (fn=0x7f10a20760f0 <GC_do_blocking_inner>, arg=0x7f1094dfd410 "`&\370\b\266U") at mach_dep.c:421
#24 0x00007f10a206b002 in GC_do_blocking (fn=0x55b608f82660 <reverse_test_inner>, client_data=client_data@entry=0x0) at misc.c:2314
#25 0x000055b608f85680 in reverse_test () at tests/gctest.c:979
#26 run_one_test () at tests/gctest.c:1832
#27 0x000055b608f86974 in thr_run_one_test (arg=<optimized out>) at tests/gctest.c:2522
#28 0x00007f10a2074431 in GC_pthread_start_inner (sb=sb@entry=0x7f1094dfd618, arg=arg@entry=0x7ffc27752ba0) at pthread_start.c:55
#29 0x00007f10a206af98 in GC_call_with_stack_base (fn=0x7f10a20743a0 <GC_pthread_start_inner>, arg=arg@entry=0x7ffc27752ba0) at misc.c:2180
#30 0x00007f10a2077c91 in GC_pthread_start (arg=0x7ffc27752ba0) at pthread_support.c:2412
#31 0x000055b608f01f89 in __tsan_thread_start_func ()
#32 0x00007f10a1d93b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#33 0x00007f10a1e25a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

(gdb) t 22
[Switching to thread 22 (Thread 0x7f109452b640 (LWP 2997259))]
#0  0x000055b608edfa9a in __sanitizer::FutexWait(__sanitizer::atomic_uint32_t*, unsigned int) ()
(gdb) bt
#0  0x000055b608edfa9a in __sanitizer::FutexWait(__sanitizer::atomic_uint32_t*, unsigned int) ()
#1  0x000055b608ee0b3a in __sanitizer::Semaphore::Wait() ()
#2  0x000055b608f6560f in __tsan::SlotLock(__tsan::ThreadState*) ()
#3  0x000055b608f75693 in __tsan::Acquire(__tsan::ThreadState*, unsigned long, unsigned long) ()
#4  0x000055b608f08828 in __tsan::CallUserSignalHandler(__tsan::ThreadState*, bool, bool, int, __sanitizer::__sanitizer_siginfo*, void*) ()
#5  0x000055b608f08de1 in sighandler(int, __sanitizer::__sanitizer_siginfo*, void*) ()
#6  <signal handler called>
#7  0x000055b608f7e548 in __tsan::DenseSlabAlloc<__tsan::SyncVar, 1048576ul, 1024ul, 3221225472ull>::Refill(__tsan::DenseSlabAllocCache*) ()
#8  0x000055b608f7db19 in __tsan::MetaMap::GetSync(__tsan::ThreadState*, unsigned long, unsigned long, bool, bool) ()
#9  0x000055b608f4e551 in __tsan_atomic64_store ()
#10 0x00007f10a2073368 in GC_malloc_explicitly_typed (lb=<optimized out>, d=64) at typd_mlc.c:290
#11 GC_calloc_explicitly_typed (n=<optimized out>, n@entry=4, lb=<optimized out>, lb@entry=16, d=d@entry=16) at typd_mlc.c:496
#12 0x000055b608f8445c in typed_test () at tests/gctest.c:1378
#13 0x000055b608f856f7 in run_one_test () at tests/gctest.c:1842
#14 0x000055b608f86974 in thr_run_one_test (arg=<optimized out>) at tests/gctest.c:2522
#15 0x00007f10a2074431 in GC_pthread_start_inner (sb=sb@entry=0x7f109452a618, arg=arg@entry=0x7ffc27752ba0) at pthread_start.c:55
#16 0x00007f10a206af98 in GC_call_with_stack_base (fn=0x7f10a20743a0 <GC_pthread_start_inner>, arg=arg@entry=0x7ffc27752ba0) at misc.c:2180
#17 0x00007f10a2077c91 in GC_pthread_start (arg=0x7ffc27752ba0) at pthread_support.c:2412
#18 0x000055b608f01f89 in __tsan_thread_start_func ()
#19 0x00007f10a1d93b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#20 0x00007f10a1e25a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
ivmai commented 1 year ago

A potential workaround would be to block signals during __tsan_atomic*() calls. But how to?

ivmai commented 1 year ago

TSAN_OPTIONS="report_signal_unsafe=0" does not help.

-D GC_DISABLE_INCREMENTAL passed to CFLAGS does not help.

ivmai commented 1 year ago

As a temporal workaround the TSan build config was reverted to run on older Ubuntu version - commit 7f6736d2b

ivmai commented 10 months ago

Build: https://app.travis-ci.com/github/ivmai/bdwgc/jobs/608786945 Source: master (07a6d0e) Host: Ubuntu 20.04.6 LTS / amd64 Occurrence: ~20/20

ivmai commented 4 months ago

Source: master (c8c9f6d99) Build: https://app.travis-ci.com/github/ivmai/bdwgc/jobs/618332294