Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perl5.38.2 crashes if no locales set while using threads::Queue #22195

Open
knst opened this issue May 5, 2024 · 13 comments
Open

perl5.38.2 crashes if no locales set while using threads::Queue #22195

knst opened this issue May 5, 2024 · 13 comments

Comments

@knst
Copy link

knst commented May 5, 2024

Module: threads

Description
If locales are not set perl crashes to segmentation fault

Steps to Reproduce

$ cat crash.pl
#!/usr/bin/perl

require threads;
require Thread::Queue;

$ export LC_ALL= #don't ask me why, it happens after ubuntu 24.04 update
$ perl crash.pl && echo OK
Segmentation fault (core dumped)
$ export LC_ALL=en_US.UTF-8
$ perl crash.pl && echo OK
OK

Backtrace:

(gdb) bt
#0  0x00007ffff7c37ad0 in __freelocale (dataset=0x55555594c3f0) at ./locale/freelocale.c:43
#1  __freelocale (dataset=0x55555594c3f0) at ./locale/freelocale.c:31
#2  0x00005555555be96a in perl_destruct (my_perl=0x55555592f2a0) at /build/perl-OoD1hG/perl-5.38.2/build-static/perl.c:1144
#3  0x0000555555599614 in main (argc=<optimized out>, argv=<optimized out>, env=<optimized out>) at /build/perl-OoD1hG/perl-5.38.2/build-static/perlmain.c:139

Expected behavior
Expected no crash

Perl configuration

Summary of my perl5 (revision 5 version 38 subversion 2) configuration:
   
  Platform:
    osname=linux
    osvers=6.1.0
    archname=x86_64-linux-gnu-thread-multi
    uname='linux localhost 6.1.0 #1 smp debian 6.1.0 x86_64 gnulinux '
    config_args='-Dmksymlinks -Dusethreads -Duselargefiles -Dcc=x86_64-linux-gnu-gcc -Dcpp=x86_64-linux-gnu-cpp -Dld=x86_64-linux-gnu-gcc -Dccflags=-DDEBIAN -Wdate-time -D_FORTIFY_SOURCE=3 -g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/dummy/build/dir=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/dummy/build/dir=/usr/src/perl-5.38.2-3.2build2 -Dldflags= -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -Dlddlflags=-shared -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.38 -Darchlib=/usr/lib/x86_64-linux-gnu/perl/5.38 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/x86_64-linux-gnu/perl5/5.38 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.38.2 -Dsitearch=/usr/local/lib/x86_64-linux-gnu/perl/5.38.2 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Duse64bitint -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Ui_libutil -Ui_xlocale -Uversiononly -Ud_strlcpy -Ud_strlcat -DDEBUGGING=-g -Doptimize=-O2 -dEs -Duseshrplib -Dlibperl=libperl.so.5.38.2'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='x86_64-linux-gnu-gcc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O2 -g'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion=''
    gccversion='13.2.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='x86_64-linux-gnu-gcc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/x86_64-linux-gnu/libc.so.6
    so=so
    useshrplib=true
    libperl=libperl.so.5.38
    gnulibc_version='2.39'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_LONG_DOUBLE
    HAS_STRTOLD
    HAS_TIMES
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
    USE_REENTRANT_API
    USE_THREAD_SAFE_LOCALE
  Locally applied patches:
    DEBPKG:debian/cpan_definstalldirs - Provide a sensible INSTALLDIRS default for modules installed from CPAN.
    DEBPKG:debian/db_file_ver - https://bugs.debian.org/340047 Remove overly restrictive DB_File version check.
    DEBPKG:debian/doc_info - Replace generic man(1) instructions with Debian-specific information.
    DEBPKG:debian/enc2xs_inc - https://bugs.debian.org/290336 Tweak enc2xs to follow symlinks and ignore missing @INC directories.
    DEBPKG:debian/errno_ver - https://bugs.debian.org/343351 Remove Errno version check due to upgrade problems with long-running processes.
    DEBPKG:debian/libperl_embed_doc - https://bugs.debian.org/186778 Note that libperl-dev package is required for embedded linking
    DEBPKG:fixes/respect_umask - Respect umask during installation
    DEBPKG:debian/writable_site_dirs - Set umask approproately for site install directories
    DEBPKG:debian/extutils_set_libperl_path - EU:MM: set location of libperl.a under /usr/lib
    DEBPKG:debian/no_packlist_perllocal - Don't install .packlist or perllocal.pod for perl or vendor
    DEBPKG:debian/fakeroot - Postpone LD_LIBRARY_PATH evaluation to the binary targets.
    DEBPKG:debian/instmodsh_doc - Debian policy doesn't install .packlist files for core or vendor.
    DEBPKG:debian/ld_run_path - Remove standard libs from LD_RUN_PATH as per Debian policy.
    DEBPKG:debian/libnet_config_path - Set location of libnet.cfg to /etc/perl/Net as /usr may not be writable.
    DEBPKG:debian/perlivp - https://bugs.debian.org/510895 Make perlivp skip include directories in /usr/local
    DEBPKG:debian/squelch-locale-warnings - https://bugs.debian.org/508764 Squelch locale warnings in Debian package maintainer scripts
    DEBPKG:debian/patchlevel - https://bugs.debian.org/567489 List packaged patches for 5.38.2-3.2build2 in patchlevel.h
    DEBPKG:fixes/document_makemaker_ccflags - https://bugs.debian.org/628522 [rt.cpan.org #68613] Document that CCFLAGS should include $Config{ccflags}
    DEBPKG:debian/find_html2text - https://bugs.debian.org/640479 Configure CPAN::Distribution with correct name of html2text
    DEBPKG:debian/perl5db-x-terminal-emulator.patch - https://bugs.debian.org/668490 Invoke x-terminal-emulator rather than xterm in perl5db.pl
    DEBPKG:debian/cpan-missing-site-dirs - https://bugs.debian.org/688842 Fix CPAN::FirstTime defaults with nonexisting site dirs if a parent is writable
    DEBPKG:debian/makemaker-pasthru - https://bugs.debian.org/758471 Pass LD settings through to subdirectories
    DEBPKG:debian/makemaker-manext - https://bugs.debian.org/247370 Make EU::MakeMaker honour MANnEXT settings in generated manpage headers
    DEBPKG:debian/kfreebsd-softupdates - https://bugs.debian.org/796798 Work around Debian Bug#796798
    DEBPKG:debian/hurd-softupdates - https://bugs.debian.org/822735 Fix t/op/stat.t failures on hurd
    DEBPKG:fixes/math_complex_doc_great_circle - https://bugs.debian.org/697567 [rt.cpan.org #114104] Math::Trig: clarify definition of great_circle_midpoint
    DEBPKG:fixes/math_complex_doc_angle_units - https://bugs.debian.org/731505 [rt.cpan.org #114106] Math::Trig: document angle units
    DEBPKG:fixes/cpan_web_link - https://bugs.debian.org/367291 CPAN: Add link to main CPAN web site
    DEBPKG:debian/installman-utf8 - https://bugs.debian.org/840211 Generate man pages with UTF-8 characters
    DEBPKG:debian/perldoc-pager - https://bugs.debian.org/870340 [rt.cpan.org #120229] Fix perldoc terminal escapes when sensible-pager is less
    DEBPKG:debian/prune_libs - https://bugs.debian.org/128355 Prune the list of libraries wanted to what we actually need.
    DEBPKG:debian/mod_paths - Tweak @INC ordering for Debian
    DEBPKG:debian/deprecate-with-apt - https://bugs.debian.org/747628 Point users to Debian packages of deprecated core modules
    DEBPKG:debian/disable-stack-check - https://bugs.debian.org/902779 [GH #16607] Disable debugperl stack extension checks for binary compatibility with perl
    DEBPKG:debian/perlbug-editor - https://bugs.debian.org/922609 Use "editor" as the default perlbug editor, as per Debian policy
    DEBPKG:debian/eu-mm-perl-base - https://bugs.debian.org/962138 Suppress an ExtUtils::MakeMaker warning about our non-default @INC
    DEBPKG:fixes/io_socket_ip_ipv6 - Disable getaddrinfo(3) AI_ADDRCONFIG for localhost and IPv4 numeric addresses
    DEBPKG:debian/usrmerge-lib64 - https://bugs.debian.org/914128 Configure / libpth.U: Do not adjust glibpth when /usr/lib64 is present.
    DEBPKG:debian/usrmerge-realpath - https://bugs.debian.org/914128 Configure / libpth.U: use realpath --no-symlinks on Debian
    DEBPKG:fixes/x32-io-msg-skip - https://bugs.debian.org/922609 Skip io/msg.t on x32 due to broken System V message queues
    DEBPKG:debian/configure-regen - https://bugs.debian.org/762638 Regenerate Configure et al. after probe unit changes
    DEBPKG:fixes/bignum-recursion - https://bugs.debian.org/1012704 [rt.cpan.org #146411] Fix CPAN RT #146411
    DEBPKG:fixes/math-bigfloat-subclass - https://bugs.debian.org/1043234 Fix Math::BigFloat subclass numeric comparison
    DEBPKG:fixes/unbreak-locale-initialization - [GH #21366] https://bugs.debian.org/1060679 Revert "locale.c: Do uselocale() earlier in init process"
  Built under linux
  Compiled at Apr  5 2024 19:57:12
  @INC:
    /etc/perl
    /usr/local/lib/x86_64-linux-gnu/perl/5.38.2
    /usr/local/share/perl/5.38.2
    /usr/lib/x86_64-linux-gnu/perl5/5.38
    /usr/share/perl5
    /usr/lib/x86_64-linux-gnu/perl-base
    /usr/lib/x86_64-linux-gnu/perl/5.38
    /usr/share/perl/5.38
    /usr/local/lib/site_perl
@knst knst changed the title perl5.38.2 crashes if no locales set if using threads::Queue perl5.38.2 crashes if no locales set while using threads::Queue May 5, 2024
@jkeenan
Copy link
Contributor

jkeenan commented May 5, 2024

I do not have Ubuntu 24.04; I have Ubuntu 22.04 LTS. So the "vendor perl" (/usr/bin/perl) on this machine is the Ubuntu/Debian build of perl-5.34.0. I tried running the following program (a slight modification of your own) with that perl.

$ cat gh-22195-locale-crash.pl 
#!/usr/bin/perl
# https://github.com/Perl/perl5/issues/22195

require threads;
require Thread::Queue;

print "Done!\n";

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=

$ /usr/bin/perl gh-22195-locale-crash.pl 
Done!

No crash.

I then built a threaded perl at HEAD of blead.

$ $THISPERL -v | head -2 | tail -1
This is perl 5, version 39, subversion 10 (v5.39.10 (v5.39.9-38-ge283461a29*)) built for x86_64-linux-thread-multi
 
$ $THISPERL -V:config_args
config_args='-des -Dusedevel -Dusethreads -Uversiononly -Dprefix=/home/jkeenan/testing/threaded_blead -Dman1dir=none -Dman3dir=none';

$ $THISPERL -V:osvers
osvers='6.5.0-28-generic';

$ $THISPERL -V:archname
archname='x86_64-linux-thread-multi';

$ $THISPERL -V | grep -i LOCALE
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_THREAD_SAFE_LOCALE

I then ran your program with $THISPERL:

$ $THISPERL gh-22195-locale-crash.pl 
Done!

No crash. Within the limitations of the kit available to me, I cannot reproduce your crash.

Whenever someone reports a crash or other bug to us that has been generating by running Debian's perl, we are faced with the problem of the thick forest of configuration switches Debian uses to build its vendor perl. So that's why, when building perl at blead, I began with the absolute minimal number of such switches: -Dusethreads. Could you start there and see if you get a crash, then add configuration switches until you do?

Has this been observed by other users of the Debian build of perl-5.38?

@tonycoz
Copy link
Contributor

tonycoz commented May 6, 2024

$ cat crash.pl
#!/usr/bin/perl

require threads;
require Thread::Queue;

$ export LC_ALL= #don't ask me why, it happens after ubuntu 24.04 update
$ perl crash.pl && echo OK
Segmentation fault (core dumped)
tony@kubunti-2304:~$ grep PRETTY_NAME /etc/os-release 
PRETTY_NAME="Ubuntu 24.04 LTS"
tony@kubunti-2304:~$ perl -v | head -2

This is perl 5, version 38, subversion 2 (v5.38.2) built for x86_64-linux-gnu-thread-multi
tony@kubunti-2304:~$ cat crash.pl
#!/usr/bin/perl

require threads;
require Thread::Queue;

tony@kubunti-2304:~$ set | grep ^LC_
LC_ADDRESS=
LC_ALL=
LC_IDENTIFICATION=
LC_MEASUREMENT=
LC_MONETARY=
LC_NAME=
LC_NUMERIC=
LC_PAPER=
LC_TELEPHONE=
LC_TIME=
tony@kubunti-2304:~$ perl crash.pl && echo OK
OK
tony@kubunti-2304:~$

I can't reproduce this on a fresh 24.04 install.

I tried with my default LC_* values too:

tony@kubunti-2304:~$ export LC_ALL=
tony@kubunti-2304:~$ set | grep ^LC_
LC_ADDRESS=en_AU.UTF-8
LC_ALL=
LC_IDENTIFICATION=en_AU.UTF-8
LC_MEASUREMENT=en_AU.UTF-8
LC_MONETARY=en_AU.UTF-8
LC_NAME=en_AU.UTF-8
LC_NUMERIC=en_AU.UTF-8
LC_PAPER=en_AU.UTF-8
LC_TELEPHONE=en_AU.UTF-8
LC_TIME=en_AU.UTF-8
tony@kubunti-2304:~$ perl crash.pl && echo OK
OK
tony@kubunti-2304:~$

@knst
Copy link
Author

knst commented May 6, 2024

Thanks @tonycoz for posting your locale settings. I tried to use them and crash disappeared:

export LC_ADDRESS=en_AU.UTF-8
export LC_ALL=
export LC_IDENTIFICATION=en_AU.UTF-8
export LC_MEASUREMENT=en_AU.UTF-8
export LC_MONETARY=en_AU.UTF-8
export LC_NAME=en_AU.UTF-8
export LC_NUMERIC=en_AU.UTF-8
export LC_PAPER=en_AU.UTF-8
export LC_TELEPHONE=en_AU.UTF-8
export LC_TIME=en_AU.UTF-8
perl crash.pl && echo "OK"
> OK

So, I reverted my locale settings and got a crash again:

export LC_ADDRESS=vi_VN
export LC_ALL=
export LC_IDENTIFICATION=vi_VN
export LC_MEASUREMENT=vi_VN
export LC_MONETARY=vi_VN
export LC_NAME=vi_VN
export LC_NUMERIC=vi_VN
export LC_PAPER=vi_VN
export LC_TELEPHONE=vi_VN
export LC_TIME=vi_VN
perl crash.pl && echo "OK"
> Segmentation fault (core dumped)

@Leont
Copy link
Contributor

Leont commented May 6, 2024

Can you try to run it in a debugger and get us a backtrace? (E.g. gdb or Devel::cst)

@knst
Copy link
Author

knst commented May 6, 2024

Can you try to run it in a debugger and get us a backtrace? (E.g. gdb or Devel::cst)

Yes, see issue description:

$ gdb -q perl
(gdb) r crash.pl
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
(gdb) bt
#0  0x00007ffff7c37ad0 in __freelocale (dataset=0x55555594c3f0) at ./locale/freelocale.c:43
#1  __freelocale (dataset=0x55555594c3f0) at ./locale/freelocale.c:31
#2  0x00005555555be96a in perl_destruct (my_perl=0x55555592f2a0) at /build/perl-OoD1hG/perl-5.38.2/build-static/perl.c:1144
#3  0x0000555555599614 in main (argc=<optimized out>, argv=<optimized out>, env=<optimized out>) at /build/perl-OoD1hG/perl-5.38.2/build-static/perlmain.c:139

due to this backtrace I even started to look in locales, otherwise it has been a completely unexplainable crash before

@Leont
Copy link
Contributor

Leont commented May 6, 2024

This looks like the kind of issue that requires @khwilliamson 's attention.

@tonycoz
Copy link
Contributor

tonycoz commented May 7, 2024

I managed to reproduce this with the system perl, valgrind provides more information:

==7527== Invalid read of size 8
==7527==    at 0x498EACD: __freelocale (freelocale.c:43)
==7527==    by 0x498EACD: freelocale (freelocale.c:31)
==7527==    by 0x172969: perl_destruct (in /usr/bin/perl)
==7527==    by 0x14D613: main (in /usr/bin/perl)
==7527==  Address 0x4bc5d00 is 0 bytes inside a block of size 316 free'd
==7527==    at 0x484988F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==7527==    by 0x499109C: newlocale (newlocale.c:258)
==7527==    by 0x2D4AEC: ??? (in /usr/bin/perl)
==7527==    by 0x2D748B: ??? (in /usr/bin/perl)
==7527==    by 0x2D7983: ??? (in /usr/bin/perl)
==7527==    by 0x2D7C30: ??? (in /usr/bin/perl)
==7527==    by 0x2D3322: ??? (in /usr/bin/perl)
==7527==    by 0x2DAAAF: Perl_init_i18nl10n (in /usr/bin/perl)
==7527==    by 0x5803F63: boot_threads__shared (in /usr/lib/x86_64-linux-gnu/perl/5.38.2/auto/threads/shared/shared.so)
==7527==    by 0x2441D9: ??? (in /usr/bin/perl)
==7527==    by 0x23970D: Perl_runops_standard (in /usr/bin/perl)
==7527==    by 0x178CF2: Perl_call_sv (in /usr/bin/perl)
==7527==  Block was alloc'd at
==7527==    at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==7527==    by 0x4990CEA: newlocale (newlocale.c:199)
==7527==    by 0x2D4AEC: ??? (in /usr/bin/perl)
==7527==    by 0x2D7CB5: ??? (in /usr/bin/perl)
==7527==    by 0x2D3322: ??? (in /usr/bin/perl)
==7527==    by 0x2DAAAF: Perl_init_i18nl10n (in /usr/bin/perl)
==7527==    by 0x14D52A: main (in /usr/bin/perl)

From this it looks like the initialization of the interpreter that threads::shared creates, uses the main interpreter's locale object as a base to create a new locale (via newlocale()) which frees that locale object. The main thread then (during cleanup) releases its copy of that locale object, producing the crash.

@tonycoz
Copy link
Contributor

tonycoz commented May 7, 2024

With debugperl:

==42359== Invalid read of size 8
==42359==    at 0x498EACD: __freelocale (freelocale.c:43)
==42359==    by 0x498EACD: freelocale (freelocale.c:31)
==42359==    by 0x17FC71: perl_destruct (perl.c:1144)
==42359==    by 0x14F5BE: main (perlmain.c:139)
==42359==  Address 0x4bc6ae0 is 0 bytes inside a block of size 316 free'd
==42359==    at 0x484988F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd
64-linux.so)
==42359==    by 0x499109C: newlocale (newlocale.c:258)
==42359==    by 0x390E8A: S_emulate_setlocale_i.lto_priv.0 (locale.c:1301)
==42359==    by 0x39839A: S_toggle_locale_i.lto_priv.0 (locale.c:6576)
==42359==    by 0x392A40: S_my_langinfo_i (locale.c:4200)
==42359==    by 0x393053: S_new_numeric (locale.c:1950)
==42359==    by 0x390422: S_new_LC_ALL.lto_priv.0 (locale.c:2518)
==42359==    by 0x396B66: Perl_init_i18nl10n (locale.c:5637)
==42359==    by 0x5803F63: UnknownInlinedFun (shared.xs:1295)
==42359==    by 0x5803F63: boot_threads__shared (shared.xs:1783)
==42359==    by 0x2B4DA8: Perl_pp_entersub (pp_hot.c:5555)
==42359==    by 0x258799: Perl_runops_debug (dump.c:2864)
==42359==    by 0x184DC6: Perl_call_sv (perl.c:3150)
==42359==  Block was alloc'd at
==42359==    at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-a
md64-linux.so)
==42359==    by 0x4990CEA: newlocale (newlocale.c:199)
==42359==    by 0x390E8A: S_emulate_setlocale_i.lto_priv.0 (locale.c:1301)
==42359==    by 0x391D77: Perl_set_numeric_standard (locale.c:2031)
==42359==    by 0x390422: S_new_LC_ALL.lto_priv.0 (locale.c:2518)
==42359==    by 0x396B66: Perl_init_i18nl10n (locale.c:5637)
==42359==    by 0x14F4DA: main (perlmain.c:102)

I haven't managed to reproduce this yet when built from source (blead and v5.38.2)

@knst
Copy link
Author

knst commented May 7, 2024

I tried to build perl from tag v5.38.2 (55dd2f7) but I got this error:

$ git checkout v5.38.2
$ ./Configure -des -Dusethreads
$ make
$ ./perl crash.pl
Can't locate threads.pm in @INC (you may need to install the threads module) (@INC entries checked: /usr/local/lib/perl5/site_perl/5.38.2/x86_64-linux /usr/local/lib/perl5/site_perl/5.38.2 /usr/local/lib/perl5/5.38.2/x86_64-linux /usr/local/lib/perl5/5.38.2) at crash.pl line 3.

which step did I miss?

@jkeenan
Copy link
Contributor

jkeenan commented May 7, 2024

I tried to build perl from tag v5.38.2 (55dd2f7) but I got this error:

$ git checkout v5.38.2
$ ./Configure -des -Dusethreads
$ make
$ ./perl crash.pl
Can't locate threads.pm in @INC (you may need to install the threads module) (@INC entries checked: /usr/local/lib/perl5/site_perl/5.38.2/x86_64-linux /usr/local/lib/perl5/site_perl/5.38.2 /usr/local/lib/perl5/5.38.2/x86_64-linux /usr/local/lib/perl5/5.38.2) at crash.pl line 3.

which step did I miss?

Generally speaking, when working with a particular git checkout (as you are here), we don't bother to install the executable. So we would say:

 $  git checkout v5.38.2
 $  ./Configure -des -Dusedevel -Duseithreads && make test_prep
 $  ./perl -Ilib /tmp/gh-22195-locale-crash.pl 

The make test_prep step gets all the .pm files into the proper staging area, ./lib. The -Ilib then tells the executable where those modules (which of course includes threads and threads::Queue) are to be found.

@knst
Copy link
Author

knst commented May 7, 2024

$ ./perl -I lib ~/tmp/autoauto/crash.pl && echo "OK"
OK
$ perl -I lib ~/tmp/autoauto/crash.pl  && echo "OK"
Segmentation fault (core dumped)

The issue doesn't reproduce for me on the fresh build from v5.38.2.

@ntyni
Copy link
Contributor

ntyni commented May 7, 2024

Hi, I can reproduce this on Debian unstable too, although it does seem a bit nondeterministic and doesn't crash on every run of the test script.

I haven't had the time to test this yet, but if it's indeed Ubuntu/Debian specific as comments indicate, I expect it's caused by

https://sources.debian.org/src/perl/5.38.2-4/debian/patches/fixes/unbreak-locale-initialization.diff/

which was a reversion of 7af2d20 due to #21366 / https://bugs.debian.org/1060679

Presumably I should have backported bf38d1c instead. Apologies for the trouble I seem to have caused.

I'll try to fix this for Debian unstable/testing soon, but getting a fix into Ubuntu 24.04 is a whole different matter.

@ntyni
Copy link
Contributor

ntyni commented May 20, 2024

Just a note that this is now tracked on the Debian side as https://bugs.debian.org/1071129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants