Lev Serebryakov
2020-Nov-27 15:03 UTC
12-STABLE try to init thead-using libraries before threads and program crashes
I have locally-built net/samba413 port on 12-STABLE (r367937) which crashes in library initialization code due to wrong library initialization order: (No debugging symbols found in /usr/local/bin/testparm) (gdb) b _libpthread_init Function "_libpthread_init" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (_libpthread_init) pending. (gdb) run Starting program: /usr/local/bin/testparm Program received signal SIGSEGV, Segmentation fault. thr_malloc_lock (curthread=0x801e077d0) at /usr/src/lib/libthr/thread/thr_malloc.c:66 66 curthread->locklevel++; (gdb) bt #0 thr_malloc_lock (curthread=0x801e077d0) at /usr/src/lib/libthr/thread/thr_malloc.c:66 #1 __thr_calloc (num=1, size=96) at /usr/src/lib/libthr/thread/thr_malloc.c:88 #2 0x0000000801474843 in mutex_init (mutex=0x801072008, mutex_attr=<optimized out>, calloc_cb=<optimized out>) at /usr/src/lib/libthr/thread/thr_mutex.c:295 #3 __Tthr_mutex_init (mutex=0x801072008, mutex_attr=<optimized out>) at /usr/src/lib/libthr/thread/thr_mutex.c:395 #4 0x00000008016d62fc in ?? () from /usr/local/lib/libgnutls.so.30 #5 0x00000008016cfcb3 in ?? () from /usr/local/lib/libgnutls.so.30 #6 0x00000008016d0077 in ?? () from /usr/local/lib/libgnutls.so.30 #7 0x000000080103730d in objlist_call_init (list=<optimized out>, lockstate=<optimized out>) at /usr/src/libexec/rtld-elf/rtld.c:2823 #8 0x000000080103603d in _rtld (sp=0x7fffffffeb58, exit_proc=0x7fffffffeb20, objp=0x7fffffffeb28) at /usr/src/libexec/rtld-elf/rtld.c:811 #9 0x00000008010338c9 in rtld_start () at /usr/src/libexec/rtld-elf/amd64/rtld_start.S:39 #10 0x0000000000000000 in ?? () (gdb) Please note, that `_libpthread_init` HAS BEEN NOT CALLED before `_Tthr_mutex_init`. Looks like some corner-case problem in rtld? Link command for this program is: [3517/3660] Linking bin/default/source3/utils/testparm runner ['cc', 'source3/utils/testparm.c.41.o', '-o/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/source3/utils/testparm', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/source4/heimdal_build', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/source4/lib/events', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/tdb_wrap', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/libcli/security', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/librpc', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/libcli/registry', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/dbwrap', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/socket', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/param', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/messaging', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/util', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/libcli/util', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/replace', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/source3', '-L/usr/local/lib', '-L/usr/local/lib', '-L/usr/local/lib', '-L/usr/local/lib', '-L/usr/local/lib', '-L/usr/local/lib', '-lpopt-samba3-samba4', '-lsmbconf', '-lreplace-samba4', '-lsamba-errors', '-lcmdline-contexts-samba4', '-lsamba-util', '-lsamba3-util-samba4', '-lmessages-dgm-samba4', '-lsys-rw-samba4', '-lmessages-util-samba4', '-liov-buf-samba4', '-lsamba-hostconfig', '-lsocket-blocking-samba4', '-linterfaces-samba4', '-ldbwrap-samba4', '-ltevent-util', '-lsamba-sockets-samba4', '-lutil-reg-samba4', '-lutil-tdb-samba4', '-lndr', '-ltalloc-report-printf-samba4', '-lserver-id-db-samba4', '-lsamba-cluster-support-samba4', '-lCHARSET3-samba4', '-lsamba-security-samba4', '-lsmbd-shim-samba4', '-lsamba-debug-samba4', '-lgenrand-samba4', '-ltime-basic-samba4', '-lutil-setid-samba4', '-lmsghdr-samba4', '-lserver-role-samba4', '-ltdb-wrap-samba4', '-levents-samba4', '-lndr-nbt', '-lroken-samba4', '-lexecinfo', '-ltevent', '-ltalloc', '-lpthread', '-lutil', '-lunwind-generic', '-lunwind', '-liconv', '-lz', '-ltdb', '-lpopt', '-lgnutls', '-ltalloc', '-fstack-protector-strong', '-L/usr/local/lib', '-pie', '-Wl,-z,relro,-z,now', '-Wl,-no-undefined', '-Wl,--export-dynamic'] -- // Lev Serebryakov
Konstantin Belousov
2020-Nov-27 17:03 UTC
12-STABLE try to init thead-using libraries before threads and program crashes
On Fri, Nov 27, 2020 at 06:03:13PM +0300, Lev Serebryakov wrote:> > I have locally-built net/samba413 port on 12-STABLE (r367937) which crashes in library initialization code due to wrong library initialization order: > > (No debugging symbols found in /usr/local/bin/testparm) > (gdb) b _libpthread_init > Function "_libpthread_init" not defined. > Make breakpoint pending on future shared library load? (y or [n]) y > Breakpoint 1 (_libpthread_init) pending. > (gdb) run > Starting program: /usr/local/bin/testparm > > Program received signal SIGSEGV, Segmentation fault. > thr_malloc_lock (curthread=0x801e077d0) at /usr/src/lib/libthr/thread/thr_malloc.c:66 > 66 curthread->locklevel++; > (gdb) bt > #0 thr_malloc_lock (curthread=0x801e077d0) at /usr/src/lib/libthr/thread/thr_malloc.c:66 > #1 __thr_calloc (num=1, size=96) at /usr/src/lib/libthr/thread/thr_malloc.c:88 > #2 0x0000000801474843 in mutex_init (mutex=0x801072008, mutex_attr=<optimized out>, calloc_cb=<optimized out>) at /usr/src/lib/libthr/thread/thr_mutex.c:295 > #3 __Tthr_mutex_init (mutex=0x801072008, mutex_attr=<optimized out>) at /usr/src/lib/libthr/thread/thr_mutex.c:395 > #4 0x00000008016d62fc in ?? () from /usr/local/lib/libgnutls.so.30 > #5 0x00000008016cfcb3 in ?? () from /usr/local/lib/libgnutls.so.30 > #6 0x00000008016d0077 in ?? () from /usr/local/lib/libgnutls.so.30 > #7 0x000000080103730d in objlist_call_init (list=<optimized out>, lockstate=<optimized out>) at /usr/src/libexec/rtld-elf/rtld.c:2823 > #8 0x000000080103603d in _rtld (sp=0x7fffffffeb58, exit_proc=0x7fffffffeb20, objp=0x7fffffffeb28) at /usr/src/libexec/rtld-elf/rtld.c:811 > #9 0x00000008010338c9 in rtld_start () at /usr/src/libexec/rtld-elf/amd64/rtld_start.S:39 > #10 0x0000000000000000 in ?? () > (gdb) > > Please note, that `_libpthread_init` HAS BEEN NOT CALLED before `_Tthr_mutex_init`. > > Looks like some corner-case problem in rtld? > > Link command for this program is: > > [3517/3660] Linking bin/default/source3/utils/testparm > runner ['cc', 'source3/utils/testparm.c.41.o', '-o/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/source3/utils/testparm', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/source4/heimdal_build', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/source4/lib/events', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/tdb_wrap', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/libcli/security', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/librpc', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/libcli/registry', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/dbwrap', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/socket', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/param', '-L/wrkdirs/usr/ports/net/sam > ba413/work/samba-4.13.1/bin/default/lib/messaging', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/util', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/libcli/util', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/lib/replace', '-L/wrkdirs/usr/ports/net/samba413/work/samba-4.13.1/bin/default/source3', '-L/usr/local/lib', '-L/usr/local/lib', '-L/usr/local/lib', '-L/usr/local/lib', '-L/usr/local/lib', '-L/usr/local/lib', '-lpopt-samba3-samba4', '-lsmbconf', '-lreplace-samba4', '-lsamba-errors', '-lcmdline-contexts-samba4', '-lsamba-util', '-lsamba3-util-samba4', '-lmessages-dgm-samba4', '-lsys-rw-samba4', '-lmessages-util-samba4', '-liov-buf-samba4', '-lsamba-hostconfig', '-lsocket-blocking-samba4', '-linterfaces-samba4', '-ldbwrap-samba4', '-ltevent-util', '-lsamba-sockets-samba4', '-lutil-reg-samba4', '-lutil-tdb-samba4', '-lndr', '-ltalloc-report-printf-samba4', '-lserver-id-db-samba4', '-lsamba-cluster-support-samba4', '-lC > HARSET3-samba4', '-lsamba-security-samba4', '-lsmbd-s > him-samba4', '-lsamba-debug-samba4', '-lgenrand-samba4', '-ltime-basic-samba4', '-lutil-setid-samba4', '-lmsghdr-samba4', '-lserver-role-samba4', '-ltdb-wrap-samba4', '-levents-samba4', '-lndr-nbt', '-lroken-samba4', '-lexecinfo', '-ltevent', '-ltalloc', '-lpthread', '-lutil', '-lunwind-generic', '-lunwind', '-liconv', '-lz', '-ltdb', '-lpopt', '-lgnutls', '-ltalloc', '-fstack-protector-strong', '-L/usr/local/lib', '-pie', '-Wl,-z,relro,-z,now', '-Wl,-no-undefined', '-Wl,--export-dynamic'] >libthr is cleanly linked too early, it should come after all consumers. Anyway, try this. diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 57984ef6d0e..303386db7fe 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -384,6 +384,8 @@ __Tthr_mutex_init(pthread_mutex_t * __restrict mutex, struct pthread_mutex *pmtx; int ret; + _thr_check_init(); + if (mutex_attr != NULL) { ret = mutex_check_attr(*mutex_attr); if (ret != 0)