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

Missing feature flag -D_GNU_SOURCE on Linux/musl #16156

Open
p5pRT opened this issue Sep 19, 2017 · 4 comments
Open

Missing feature flag -D_GNU_SOURCE on Linux/musl #16156

p5pRT opened this issue Sep 19, 2017 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 19, 2017

Migrated from rt.perl.org#132131 (status was 'open')

Searchable as RT132131$

@p5pRT
Copy link
Author

p5pRT commented Sep 19, 2017

From @leahneukirchen

Created by @leahneukirchen

(Please note that this bug report applies to perl 5.26.0 on
a Linux 4.12 x86_64 system with musl libc 1.1.6.)

Perl 5.26.0 uses memmem in fbm_instr via ninstr if available,
but this function can be defined only when a feature flag like
_GNU_SOURCE is set.

Currently, perl detects memmem on musl (because the symbol is there),
but doesn't define _GNU_SOURCE, so no prototype is declared and the
return value is assumed to be an int, thus line 951 of util.c
will truncate the pointer into a 32-bit value, and
little_p - big_p in pp_index is suddenly very big. ;)

This resulted in the following script

my $fn = 'Class/Inspector.pm';
print index('lib/Class/Inspector.pm', $fn);
print "\n";
print index('lib/Class/Inspector.pm', 'Class/Inspector.pm');

printing

% perl /tmp/foo.pl
-94012539142140
4

Forcing the use of _GNU_SOURCE (as seen below in ccflags) fixes the issue,
perhaps there is a better test.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.26.0:

Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=current
    archname=x86_64-linux
    uname=''
    config_args='--prefix=/usr -Dusethreads -Duseshrplib -Dusesoname -Dusevendorprefix -Dprefix=/usr -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl -Darchlib=/usr/lib/perl5/core_perl -Dsitelib=/usr/share/perl5/site_perl -Dsitearch=/usr/lib/perl5/site_perl -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib/perl5/vendor_perl -Dscriptdir=/usr/bin -Dvendorscript=/usr/bin -Dinc_version_list=none -Dman1ext=1p -Dman3ext=3p -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dd_sockaddr_in6=define -Dcccdlflags=-fPIC -Doptimize= -Wall  -Wl,-z,relro -Wl,-z,now -Wl,--as-needed	-Dperl_static_inline=static __inline__ -Dd_static_inline'
    hint=default
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=undef
    use64bitint=undef
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=undef
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='	 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mtune=generic -O2 -pipe	  -D_GNU_SOURCE '
    optimize=' -Wall   -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mtune=generic -O2 -pipe	-D_GNU_SOURCE '
    cppflags=''
    ccversion=''
    gccversion='0.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='cc'
    ldflags =' -Wl,-z,relro -Wl,-z,now -Wl,--as-needed	  '
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lm -lcrypt -lpthread -lgdbm -ldb -ldl -lgdbm_compat
    perllibs=-lm -lcrypt -lpthread -ldl
    libc=
    so=so
    useshrplib=true
    libperl=libperl.so.5.26.0
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared	-Wl,-z,relro -Wl,-z,now -Wl,--as-needed    '



@INC for perl 5.26.0:
    /usr/lib/perl5/site_perl
    /usr/share/perl5/site_perl
    /usr/lib/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib/perl5/core_perl
    /usr/share/perl5/core_perl


Environment for perl 5.26.0:
    HOME=/tmp
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_COLLATE=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/void-packages:/usr/bin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/sh

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2017

From @jkeenan

On Tue, 19 Sep 2017 17​:37​:54 GMT, leah@​vuxu.org wrote​:

This is a bug report for perl from leah@​vuxu.org,
generated with the help of perlbug 1.40 running under perl 5.26.0.

-----------------------------------------------------------------
[Please describe your issue here]

(Please note that this bug report applies to perl 5.26.0 on
a Linux 4.12 x86_64 system with musl libc 1.1.6.)

For reference​: https://en.wikipedia.org/wiki/Musl

Perl 5.26.0 uses memmem in fbm_instr via ninstr if available,
but this function can be defined only when a feature flag like
_GNU_SOURCE is set.

Currently, perl detects memmem on musl (because the symbol is there),
but doesn't define _GNU_SOURCE, so no prototype is declared and the
return value is assumed to be an int, thus line 951 of util.c
will truncate the pointer into a 32-bit value, and
little_p - big_p in pp_index is suddenly very big. ;)

This resulted in the following script

my $fn = 'Class/Inspector.pm';
print index('lib/Class/Inspector.pm', $fn);
print "\n";
print index('lib/Class/Inspector.pm', 'Class/Inspector.pm');

printing

% perl /tmp/foo.pl
-94012539142140
4

Forcing the use of _GNU_SOURCE (as seen below in ccflags) fixes the
issue,
perhaps there is a better test.

Also for reference​: locations in the core distribution which mention _GNU_SOURCE​:

$ ack -l _GNU_SOURCE . |sort
config_h.SH
cpan/Config-Perl-V/t/21_plv58.t
cpan/Config-Perl-V/t/27_plv5200.t
cpan/Config-Perl-V/t/27_plv5202.t
cpan/Config-Perl-V/t/28_plv5220.t
cpan/Config-Perl-V/t/30_plv5240.t
cpan/Config-Perl-V/t/31_plv52511.t
cpan/Config-Perl-V/t/32_plv5261rc1.t
hints/cygwin.sh
hints/freemint.sh
hints/gnu.sh
hints/linux.sh
NetWare/config_H.wc
plan9/config_h.sample
plan9/config.plan9
Porting/config_H
uconfig.h
win32/config_H.ce
win32/config_H.gc
win32/config_H.vc

Can someone familiar with ccflags take a look at this ticket? Could the OP's concern be accommodated somewhere in a hints file?

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2017

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 2, 2018

From @jkeenan

On Tue, 19 Sep 2017 17​:37​:54 GMT, leah@​vuxu.org wrote​:

This is a bug report for perl from leah@​vuxu.org,
generated with the help of perlbug 1.40 running under perl 5.26.0.

-----------------------------------------------------------------
[Please describe your issue here]

(Please note that this bug report applies to perl 5.26.0 on
a Linux 4.12 x86_64 system with musl libc 1.1.6.)

Perl 5.26.0 uses memmem in fbm_instr via ninstr if available,
but this function can be defined only when a feature flag like
_GNU_SOURCE is set.

Currently, perl detects memmem on musl (because the symbol is there),
but doesn't define _GNU_SOURCE, so no prototype is declared and the
return value is assumed to be an int, thus line 951 of util.c
will truncate the pointer into a 32-bit value, and
little_p - big_p in pp_index is suddenly very big. ;)

This resulted in the following script

my $fn = 'Class/Inspector.pm';
print index('lib/Class/Inspector.pm', $fn);
print "\n";
print index('lib/Class/Inspector.pm', 'Class/Inspector.pm');

printing

% perl /tmp/foo.pl
-94012539142140
4

Forcing the use of _GNU_SOURCE (as seen below in ccflags) fixes the
issue,
perhaps there is a better test.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=medium
---
Site configuration information for perl 5.26.0​:

Summary of my perl5 (revision 5 version 26 subversion 0)
configuration​:

Platform​:
osname=linux
osvers=current
archname=x86_64-linux
uname=''
config_args='--prefix=/usr -Dusethreads -Duseshrplib -Dusesoname
-Dusevendorprefix -Dprefix=/usr -Dvendorprefix=/usr
-Dprivlib=/usr/share/perl5/core_perl
-Darchlib=/usr/lib/perl5/core_perl
-Dsitelib=/usr/share/perl5/site_perl
-Dsitearch=/usr/lib/perl5/site_perl
-Dvendorlib=/usr/share/perl5/vendor_perl
-Dvendorarch=/usr/lib/perl5/vendor_perl -Dscriptdir=/usr/bin
-Dvendorscript=/usr/bin -Dinc_version_list=none -Dman1ext=1p
-Dman3ext=3p -Dman1dir=/usr/share/man/man1
-Dman3dir=/usr/share/man/man3 -Dd_sockaddr_in6=define -Dcccdlflags=-
fPIC -Doptimize= -Wall -Wl,-z,relro -Wl,-z,now -Wl,--as-needed
-Dperl_static_inline=static __inline__ -Dd_static_inline'
hint=default
useposix=true
d_sigaction=define
useithreads=define
usemultiplicity=undef
use64bitint=undef
use64bitall=undef
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=undef
bincompat5005=undef
Compiler​:
cc='cc'
ccflags =' -fstack-protector-strong -D_FORTIFY_SOURCE=2
-mtune=generic -O2 -pipe -D_GNU_SOURCE '
optimize=' -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2
-mtune=generic -O2 -pipe -D_GNU_SOURCE '
cppflags=''
ccversion=''
gccversion='0.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='cc'
ldflags =' -Wl,-z,relro -Wl,-z,now -Wl,--as-needed '
libpth=/lib /usr/lib /usr/local/lib
libs=-lm -lcrypt -lpthread -lgdbm -ldb -ldl -lgdbm_compat
perllibs=-lm -lcrypt -lpthread -ldl
libc=
so=so
useshrplib=true
libperl=libperl.so.5.26.0
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs
dlext=so
d_dlsymun=undef
ccdlflags='-Wl,-E'
cccdlflags='-fPIC'
lddlflags='-shared -Wl,-z,relro -Wl,-z,now -Wl,--as-needed '

---
@​INC for perl 5.26.0​:
/usr/lib/perl5/site_perl
/usr/share/perl5/site_perl
/usr/lib/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib/perl5/core_perl
/usr/share/perl5/core_perl

---
Environment for perl 5.26.0​:
HOME=/tmp
LANG=en_US.UTF-8
LANGUAGE (unset)
LC_COLLATE=C
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/void-packages​:/usr/bin​:/usr/sbin
PERL_BADLANG (unset)
SHELL=/bin/sh

Let's suppose that you are currently invoking ./Configure like this​:

#####
sh ./Configure -Dalpha -Dbeta -Dgamma
#####

... where you substitute the list of config_args you are currently using for alpha..beta..gamma.

Do you get any better results if you tack on two arguments at the end?

#####
sh ./Configure -Dalpha -Dbeta -Dgamma -Aoptimize="-D_GNU_SOURCE" -Accflags="-D_GNU_SOURCE"
#####

(Caution​: This is just a guess based on reading INSTALL.)

Thank you very much.
Jim Keenan
--
James E Keenan (jkeenan@​cpan.org)

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

2 participants