Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 811237 - dev-lang/perl: all versions of perl segfault when cross-compiled ("Attempt to free unreferenced scalar")
Summary: dev-lang/perl: all versions of perl segfault when cross-compiled ("Attempt to...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Perl team
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2021-08-31 08:43 UTC by Jeremi Piotrowski
Modified: 2021-09-01 00:52 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremi Piotrowski 2021-08-31 08:43:26 UTC
Cross-compiled perl fails due to missing '-fwrapv -fno-strict-aliasing' flags during cross-compilation. These should be appended by the cross build system but due to the parameters that the perl ebuild passes this is not done.

Reproducible: Always

Steps to Reproduce:
1. emerge crossdev
2. crossdev -t x86_64-cros-linux-gnu
3. echo 'sys-libs/glibc-2.33' >/usr/x86_64-cros-linux-gnu/etc/portage/profile/package.provided
4. emerge-x86_64-cros-linux-gnu perl
5. mount --bind /dev /usr/x86_64-cros-linux-gnu/dev
6. chroot /usr/x86_64-cros-linux-gnu perl -V
Actual Results:  
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "C.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Attempt to free unreferenced scalar: SV 0x563f6520c708 at /usr/lib/perl5/5.34/strict.pm line 38.
Segmentation fault (core dumped)

Expected Results:  
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "C.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Summary of my perl5 (revision 5 version 34 subversion 0) configuration:

  Platform:
    osname=linux
    osvers=current
    archname=x86_64-linux
    uname=''
    config_args='--target=x86_64-cros-linux-gnu --build=x86_64-pc-linux-gnu -Dinstallprefix= -Dinstallusrbinperl=undef -Dusevendorprefix=define -Ui_xlocale -Ui_ndbm -Ui_gdbm -Ui_db -DDEBUGGING=none -Dnoextensions=ODBM_File GDBM_File NDBM_File -Duseshrplib -Darchname=x86_64-linux -Dcc=x86_64-cros-linux-gnu-gcc -Dar=x86_64-cros-linux-gnu-ar -Dnm=x86_64-cros-linux-gnu-nm -Dcpp=x86_64-cros-linux-gnu-gcc -E -Dranlib=x86_64-cros-linux-gnu-ranlib -Doptimize=-O2 -pipe -fomit-frame-pointer -fwrapv -fno-strict-aliasing -Dldflags= -Dprefix=/usr -Dsiteprefix=/usr/local -Dvendorprefix=/usr -Dscriptdir=/usr/bin -Dprivlib=/usr/lib/perl5/5.34 -Darchlib=/usr/lib/perl5/5.34/x86_64-linux -Dsitelib=/usr/local/lib/perl5/5.34 -Dsitearch=/usr/local/lib/perl5/5.34/x86_64-linux -Dvendorlib=/usr/lib/perl5/vendor_perl/5.34 -Dvendorarch=/usr/lib/perl5/vendor_perl/5.34/x86_64-linux -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dvendorman1dir=/usr/share/man/man1 -Dvendorman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3pm -Dlibperl=libperl.so.5.34.0 -Dlocincpth=/usr/include  -Dglibpth=/lib /usr/lib  -Duselargefiles -Dd_semctl_semun -Dcf_by=Gentoo -Dmyhostname=localhost -Dperladmin=root@localhost -Ud_csh -Dsh=/bin/sh -Dtargetsh=/bin/sh -Uusenm -Ui_xlocale -Ui_ndbm -Ui_gdbm -Ui_db -DDEBUGGING=none -Dnoextensions=ODBM_File GDBM_File NDBM_File --keeplog --mode=target --target=x86_64-cros-linux-gnu --targetarch=x86_64-cros-linux-gnu'
    hint=default
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=undef
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='x86_64-cros-linux-gnu-gcc'
    ccflags ='-O2 -pipe -fomit-frame-pointer -fwrapv -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O2 -pipe -fomit-frame-pointer -fwrapv -fno-strict-aliasing'
    cppflags=''
    ccversion='9.4.0'
    gccversion='9.4.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=0
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='x86_64-cros-linux-gnu-gcc'
    ldflags =''
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lm -lcrypt -lpthread -ldl
    perllibs=-lm -lcrypt -ldl
    libc=
    so=so
    useshrplib=true
    libperl=libperl.so.5.34.0
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC -Wno-unused-function'
    lddlflags='-shared'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Locally applied patches:
    0001-Fix-hpux-hints.patch
    - Fix hpux hints
    0002-aix-gcc-detection-and-shared-library-soname-support.patch
    - aix gcc detection and shared library soname support
    0003-cpan-ExtUtils-MakeMaker-drop-PORTAGE_TMPDIR-from-LD_.patch
    - cpan/ExtUtils-MakeMaker: drop $PORTAGE_TMPDIR from LD_RUN_PATH
    - Bug: https://bugs.gentoo.org/105054
    0004-Remove-rpath-and-append-LDFLAGS-to-lddlflags.patch
    - Remove -rpath and append LDFLAGS to lddlflags
    0005-Add-headers-for-opensolaris.patch
    - Add headers for opensolaris
    0006-List-packaged-patches-in-patchlevel.h.patch
    - List packaged patches for perl-5.34.0-r2(perl-5.34.0-patches-1) in patchlevel.h
    - Bug: https://bugs.debian.org/567489
    0007-Cleanup-PATH-and-shrpenv.patch
    - Cleanup PATH and shrpenv
    0008-Tweak-enc2xs-to-follow-symlinks-and-ignore-missing-I.patch
    - Tweak enc2xs to follow symlinks and ignore missing @INC directories.
    - Bug: https://bugs.debian.org/290336
    0009-darwin-Use-CC-to-link.patch
    - darwin: Use $CC to link
    - Bug: https://bugs.gentoo.org/297751
    0010-Provide-a-sensible-INSTALLDIRS-default-for-modules-i.patch
    - Provide a sensible INSTALLDIRS default for modules installed from CPAN.
    0011-Fix-interix-hints.patch
    - Fix interix hints
    0012-Set-libperl-soname.patch
    - Set libperl soname
    - Bug: https://bugs.gentoo.org/286840
    0013-Add-etc-perl-to-INC.patch
    - Add /etc/perl to @INC
    0014-cpan-ExtUtils-MakeMaker-remove-targets-that-generate.patch
    - cpan/ExtUtils-MakeMaker: remove targets that generate perllocal.pod
    0015-Don-t-force-fstack-protector-on-everyone.patch
    - Don't force -fstack-protector on everyone
    - Bug: https://bugs.gentoo.org/348557
    0016-Do-not-set-custom-CFLAGS-in-cpan-Digest-SHA.patch
    - Do not set custom CFLAGS in cpan/Digest-SHA
    - Bug: https://bugs.gentoo.org/506818
    0017-Configure-Don-t-include-sources-in-usr-local-for-com.patch
    - Configure: Don't include sources in /usr/local/ for compiling perl
    0018-cpan-IO-Socket-IP-Disable-network-tests.patch
    - cpan/IO-Socket-IP: Disable network tests
    0019-Fix-EUMM-podlocal-tests.patch
    - Fix EUMM podlocal tests
    0020-Skip-auto-linking-nsl-and-cl.patch
    - Skip auto-linking nsl and cl
    - Bug: https://rt.perl.org/Public/Bug/Display.html?id=13148
    0021-Disable-porting-tests-which-create-fun-false-failure.patch
    - Disable porting tests which create fun false-failures all over travis
    0022-Disable-PathTools-tests-which-fails-under-sandboxing.patch
    - Disable PathTools tests which fails under sandboxing
    - Bug: https://bugs.gentoo.org/645084
    0023-Fix-CPAN-FirstTime-defaults-with-nonexisting-site-di.patch
    - Fix CPAN::FirstTime defaults with nonexisting site dirs if a parent is writable
    - Bug: https://bugs.debian.org/688842
    0024-Pass-LD-settings-through-to-subdirectories.patch
    - Pass LD settings through to subdirectories
    - Bug: https://bugs.debian.org/758471
    0025-Memoize-Storable-respect-nstore-option-not-respected.patch
    - Memoize::Storable: respect 'nstore' option not respected
    - Bug: https://bugs.debian.org/587650
    - Bug: https://rt.cpan.org/Public/Bug/Display.html?id=77790
    0026-Better-errors-for-man-pages-from-standard-input.patch
    - Better errors for man pages from standard input
    - Bug: https://bugs.debian.org/777405
    0027-Respect-umask-during-installation.patch
    - Respect umask during installation
    0028-Document-that-CCFLAGS-should-include-Config-ccflags.patch
    - Document that CCFLAGS should include $Config{ccflags}
    - Bug: https://bugs.debian.org/628522
    - Bug: https://rt.cpan.org/Public/Bug/Display.html?id=68613
    0029-Fix-parallel-building.patch
    - Fix parallel building
    0030-Add-support-for-Dgentoolibdirs.patch
    - Add support for -Dgentoolibdirs
  Built under linux
  Compiled at Aug 31 2021 08:28:01
  @INC:
    /etc/perl
    /usr/local/lib/perl5/5.34/x86_64-linux
    /usr/local/lib/perl5/5.34
    /usr/lib/perl5/vendor_perl/5.34/x86_64-linux
    /usr/lib/perl5/vendor_perl/5.34
    /usr/lib/perl5/5.34/x86_64-linux
    /usr/lib/perl5/5.34

This

https://github.com/arsv/perl-cross/blob/master/cnf/configure_tool.sh#L317

should be responsible for adding the optimize flag, but this

https://github.com/arsv/perl-cross/blob/master/cnf/configure__f.sh#L133-L143

causes it to be skipped if optimize is not of the predefined value (empty "").

The config.log shows the following output:

Skipping optimize <= -fwrapv -fno-strict-aliasing (args: -O2 -pipe -fomit-frame-pointer -fwrapv -fno-strict-aliasing)
Skipping optimize (args: -O2 -pipe -fomit-frame-pointer -fwrapv -fno-strict-aliasing)

This is after I already added the correct flags in my CFLAGS; they don't get added as long as CFLAGS is not empty.
Comment 1 Larry the Git Cow gentoo-dev 2021-09-01 00:49:02 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=176c1daa9c86574370fdf5ebfd23dd0edd163bdd

commit 176c1daa9c86574370fdf5ebfd23dd0edd163bdd
Author:     Jeremi Piotrowski <jpiotrowski@microsoft.com>
AuthorDate: 2021-08-31 08:49:06 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2021-09-01 00:48:55 +0000

    dev-lang/perl: append required cflags when x-compiling
    
    The cross-build system wants to append cflags required by the build to the
    'optimize' variable, but doesn't touch the variable when the user overrides it.
    Since the ebuild passes '-Doptimize="${CFLAGS}"', we are responsible for
    passing the correct flags, so append '-fwrapv -fno-strict-aliasing' to cflags
    when we are cross-compiling.
    
    Bug: https://bugs.gentoo.org/811237
    Reported-by: Github User DRKV333
    Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
    Closes: https://github.com/gentoo/gentoo/pull/22167
    Signed-off-by: Sam James <sam@gentoo.org>

 dev-lang/perl/perl-5.32.1.ebuild    | 5 +++++
 dev-lang/perl/perl-5.34.0-r1.ebuild | 5 +++++
 dev-lang/perl/perl-5.34.0-r2.ebuild | 5 +++++
 dev-lang/perl/perl-5.34.0.ebuild    | 5 +++++
 4 files changed, 20 insertions(+)
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-09-01 00:52:06 UTC
Thanks!