On Thu, Jul 13, 2023 at 11:03:35AM +0100, Richard W.M. Jones wrote:
On Thu, Jul 13, 2023 at 10:29:44AM +0100, Richard W.M. Jones wrote:
> It's a crash in Perl code, although called from the nbdkit perl plugin
> (C bindings). Still debugging this ...
>
> Core was generated by `/home/rjones/d/nbdkit/server/nbdkit -U /tmp/nbdkittPN34a/sock
-P /tmp/nbdkittPN'.
> Program terminated with signal SIGSEGV, Segmentation fault.
>
> warning: Section `.reg-xstate/150177' in core file too small.
> #0 Perl_my_snprintf (buffer=0x7f3a1e5fc630 "p\310_\036:\177", len=32,
> format=0x7f3a1ef7e322 "_<(eval %lu)")
> at /usr/src/debug/perl-5.38.0-499.fc39.x86_64/util.c:5248
> Downloading source file /usr/src/debug/perl-5.38.0-499.fc39.x86_64/util.c
> 5248 WITH_LC_NUMERIC_SET_TO_NEEDED(
> [Current thread is 1 (Thread 0x7f3a1e5fd6c0 (LWP 150177))]
> (gdb) bt
> #0 Perl_my_snprintf (buffer=0x7f3a1e5fc630 "p\310_\036:\177", len=32,
> format=0x7f3a1ef7e322 "_<(eval %lu)")
> at /usr/src/debug/perl-5.38.0-499.fc39.x86_64/util.c:5248
https://github.com/Perl/perl5/blob/ff7e37d5ca2e55a1e53e5b375e3cc9aedc9ce4...
Since its hardly obvious from the code, that macro expands to the
monster below. I didn't bother to format it completely ...
# 5245 "util.c"
if (retval == -1) {
do {
void (*_restore_LC_NUMERIC_function)(PerlInterpreter* my_perl __attribute__((unused)))
= ((void *)0);
do {
_Bool _in_lc_numeric = ((( ((
_Bool
) ((my_perl->Icompiling).cop_hints & 0x00000004)) || ( ((_Bool)
((my_perl->Icompiling).cop_hints & 0x00000010)) &&
Perl__is_in_locale_category(my_perl, (1), (
1
)))) || (((my_perl->Icurcop) && (((my_perl->Icurcop))->cop_hints
+ 0) & 0x00000004) || (((my_perl->Icurcop) &&
(((my_perl->Icurcop))->cop_hints + 0) & 0x00000010) &&
Perl__is_in_locale_category(my_perl, (0), (
1
))))));
((void)0);
if (_in_lc_numeric) {
if ((! (my_perl->Inumeric_underlying) &&
(my_perl->Inumeric_standard) < 2)) { Perl_set_numeric_underlying(my_perl);
_restore_LC_NUMERIC_function = &Perl_set_numeric_standard; }
} else {
if ((! (my_perl->Inumeric_standard))) { Perl_set_numeric_standard(my_perl);
_restore_LC_NUMERIC_function = &Perl_set_numeric_underlying; } }
} while (0);
retval = vsnprintf(buffer, len, format, ap);;
do { if (_restore_LC_NUMERIC_function) { _restore_LC_NUMERIC_function(my_perl); }
((void)0); } while (0);
} while (0);
... because the fundamental problem is:
(gdb) print my_perl
$13 = (PerlInterpreter *) 0x0
so that's not gonna work.
It turns out to be a bug in nbdkit! A close reading of the perlembed
man page reveals that we need to set the interpreter context when
calling into Perl from a new thread. The fix is:
https://gitlab.com/nbdkit/nbdkit/-/commit/495708e9d1b396ff450df15d5789b4f...
I'll add this to Rawhide shortly.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
nbdkit - Flexible, fast NBD server with plugins
https://gitlab.com/nbdkit/nbdkit