bdwgc
bdwgc copied to clipboard
SIGSEGV in static multi-threaded build with redirect malloc
Source: master (067ed9b40)
Host: FreeBSD-15.0/aarch64
Compiler: clang
How to reproduce: mkdir out && cd out && cmake -Dbuild_tests=ON -Denable_redirect_malloc=ON -DBUILD_SHARED_LIBS=OFF .. && cmake --build . && ctest
Note: not observed without -DBUILD_SHARED_LIBS=OFF.
gdb output:
Program received signal SIGSEGV, Segmentation fault.
Address not mapped to object.
_thr_setcancelstate (state=state@entry=1, oldstate=oldstate@entry=0xffffffffd66c)
at /usr/src/lib/libthr/thread/thr_cancel.c:88
88 oldval = curthread->cancel_enable;
(gdb) bt
#0 _thr_setcancelstate (state=state@entry=1, oldstate=oldstate@entry=0xffffffffd66c)
at /usr/src/lib/libthr/thread/thr_cancel.c:88
#1 0x000000000022e098 in GC_init () at bdwgc/misc.c:1080
#2 0x0000000000229270 in GC_generic_malloc_inner_small (lb=lb@entry=1664, k=k@entry=1)
at bdwgc/malloc.c:181
#3 0x0000000000229388 in GC_generic_malloc_aligned (lb=1664, k=1, flags=<optimized out>, align_m1=0)
at bdwgc/malloc.c:251
#4 0x000000000022982c in GC_malloc_kind_aligned_global (lb=1664, k=1, align_m1=0) at bdwgc/malloc.c:373
#5 0x00000000402e81f0 in _thr_alloc (curthread=0x0, curthread@entry=0xffffffffd7e0)
at /usr/src/lib/libthr/thread/thr_list.c:153
#6 0x00000000402e6fa0 in _libpthread_init (curthread=0x0) at /usr/src/lib/libthr/thread/thr_init.c:336
#7 0x0000000040271dec in objlist_call_init (list=list@entry=0xffffffffe460, lockstate=<optimized out>,
lockstate@entry=0xffffffffe250) at /usr/src/libexec/rtld-elf/rtld.c:3118
#8 0x0000000040270ae0 in _rtld (sp=<optimized out>, exit_proc=<optimized out>, objp=<optimized out>)
at /usr/src/libexec/rtld-elf/rtld.c:964
#9 0x000000004026dec4 in rtld_start () at /usr/src/libexec/rtld-elf/aarch64/rtld_start.S:41
Note: we cannot redirect GC_malloc (GC_malloc_kind_aligned_global) to sbrk if GC is not initialized because sbrk is not available.
Same observed on CheriBSD.