https://bugs.openldap.org/show_bug.cgi?id=8591
--- Comment #2 from Ryan Tandy ryan@openldap.org --- Created attachment 720 --> https://bugs.openldap.org/attachment.cgi?id=720&action=edit backtrace
Reproduced on Debian unstable (sid) with OpenLDAP 2.4.49 and Perl 5.30. Attaching a better backtrace.
I note that it doesn't happen every time, sometimes it does start up fine.
So the crash is here:
https://sources.debian.org/src/perl/5.30.0-10/util.c/#L5415
(gdb) p my_perl $1 = (PerlInterpreter *) 0x0 (gdb) p &my_perl->Ixsubfilename $2 = (const char **) 0x5d8
When it doesn't crash, my_perl is equal to PL_curinterp.
(gdb) p my_perl $1 = (PerlInterpreter *) 0x7fffa8106560 (gdb) p PL_curinterp $2 = (PerlInterpreter *) 0x7fffa8106560 (gdb) p my_perl == PL_curinterp $3 = 1
my_perl seems to come from Perl_get_context():
https://sources.debian.org/src/perl/5.30.0-10/util.c/?hl=3339#L3339
The corresponding pthread_setspecific() happens inside perl_back_initialize.
#0 __GI___pthread_setspecific (key=3, value=value@entry=0x7fffa8106560) at pthread_setspecific.c:33 #1 0x00007fffb5aac68e in S_init_tls_and_interp (my_perl=0x7fffa8106560) at perl.c:92 #2 perl_alloc () at perl.c:200 #3 0x00007ffff71aa70a in perl_back_initialize (bi=0x7ffff71b1220 <bi>)
Later, Perl_eval_pv invokes a DynaLoader to load the eval'ed code. This module's startup is where Perl_xs_handshake is called, to check for compatibility between the library's global Perl context (Perl_get_context()) and the one passed in from the application (implicit argument to Perl_eval_pv()). Normally these would just be the same.
Anyway, this looks like a pretty simple bug in back_perl: we're just missing a PERL_SET_CONTEXT() in perl_cf(), so it crashes if called from a different thread than perl_back_initialize(). We should audit and make sure every back_perl entry point calls it.