develooper Front page | perl.perl5.porters | Postings from May 2010

5.12: inplace sort <*> segfault (gcc 4.5.0 bug?)

Thread Next
From:
Alex Hunsaker
Date:
May 10, 2010 16:22
Subject:
5.12: inplace sort <*> segfault (gcc 4.5.0 bug?)
Message ID:
AANLkTilfA_Ga8zCs26w1Lii2NvwimcwQzJ7LJjBUePOO@mail.gmail.com
(Find at the bottom gcc, perl -V and uname output)

While trying to get mod_perl 2 up and running on 5.12, running perl
Makefile.PL resulted in segfaults.  It boiled down to some sorts
Apache-Test/lib/Apache/TestHarness.pm.  Commenting those out
everything was peachy.  Find below a simple test case:

$  ./perl -Ilib/ -e 'sort glob("*")'
Segmentation fault

- or -

 $ ./perl -Ilib/ -e 'sort <*>'
Segmentation fault

backtrace:
Program received signal SIGSEGV, Segmentation fault.
S_is_inplace_av (o=<value optimized out>, oright=<value optimized
out>, my_perl=<value optimized out>, o=<value optimized out>,
oright=<value optimized out>)
    at op.c:8418
8418		(oright->op_type != OP_RV2AV && oright->op_type != OP_PADAV)
(gdb) bt
#0  S_is_inplace_av (o=<value optimized out>, oright=<value optimized
out>, my_perl=<value optimized out>, o=<value optimized out>,
    oright=<value optimized out>) at op.c:8418
#1  0x000000000042510d in Perl_peep (my_perl=0x8a3f90, o=0x8ccc50) at op.c:8923
#2  0x000000000042e649 in Perl_newPROG (my_perl=0x8a3f90, o=<value
optimized out>) at op.c:2365
#3  0x000000000047874f in Perl_yyparse (my_perl=0x8a3f90) at perly.y:143
#4  0x0000000000442a69 in S_parse_body (my_perl=0x8a3f90, env=0x0,
xsinit=0x421240 <xs_init>) at perl.c:2160
#5  0x0000000000444569 in perl_parse (my_perl=0x8a3f90,
xsinit=0x421240 <xs_init>, argc=<value optimized out>,
argv=0x3e32c04e508, env=0x0) at perl.c:1605
#6  0x00000000004212c3 in main (argc=3, argv=0x3e32c04e508,
env=0x3e32c04e528) at perlmain.c:115

If I hack in some debugging:

diff --git a/op.c b/op.c
index 76eb16f..93da89c 100644
--- a/op.c
+++ b/op.c
@@ -8399,9 +8399,21 @@ STATIC OP *
 S_is_inplace_av(pTHX_ OP *o, OP *oright) {
     OP *o2;
     OP *oleft = NULL;
+    char buf[80];
+    memset(buf, 0, sizeof(buf));

     PERL_ARGS_ASSERT_IS_INPLACE_AV;

+    snprintf(buf, sizeof(buf), "inplace_av: oright: %p\n", oright);
+    write(2, buf, sizeof(buf));
+
+    if (!oright)
+    {
+ snprintf(buf, sizeof(buf), "returning\n");
+ write(2, buf, sizeof(buf));
+ return NULL;
+    }
+
     if (!oright ||
        (oright->op_type != OP_RV2AV && oright->op_type != OP_PADAV)
        || oright->op_next != o
@@ -8472,6 +8484,7 @@ Perl_peep(pTHX_ register OP *o)
 {
     dVAR;
     register OP* oldop = NULL;
+    char buf[80];

     if (!o || o->op_opt)
        return;
@@ -8897,12 +8910,16 @@ Perl_peep(pTHX_ register OP *o)
            /* make @a = sort @a act in-place */

            oright = cUNOPx(oright)->op_sibling;
+
            if (!oright)
                break;
            if (oright->op_type == OP_NULL) { /* skip sort block/sub */
                oright = cUNOPx(oright)->op_sibling;
            }

+     memset(buf, 0, sizeof(buf));
+     snprintf(buf, sizeof(buf), "oright: %p\n", oright);
+     write(2, buf, sizeof(buf));
            oleft = is_inplace_av(o, oright);
            if (!oleft)
                break;


I get:
oright: (nil)
inplace_av: oright: (nil)
Segmentation fault

Hrm Ok seems like gcc decided oright can never be NULL and so took out
those checks.  If I do an optimize='-g' no -O2 it seems to work.  Any
ideas?

--
Details:
./Configure -des -Dusemultiplicity -DDEBUGGING.

$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr
--enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--enable-lto --enable-gnu-unique-object --disable-multilib
--disable-libstdcxx-pch --with-system-zlib --with-ppl --with-cloog
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info
Thread model: posix
gcc version 4.5.0 (GCC)

$ uname -a
Linux archon 2.6.33.3-1-grsec #1 SMP PREEMPT Fri Apr 30 14:59:09 MDT
2010 x86_64 Intel(R) Core(TM)2 Quad CPU Q6700 @ 2.66GHz GenuineIntel
GNU/Linux

$ ./perl -Ilib -V
Summary of my perl5 (revision 5 version 12 subversion 1) configuration:
  Derived from: d54920628df719d2fc3f377ff487b3905b633c1a
  Ancestor: 68b8dcc8db021f5e71fda964c7b85cbee9df60f6
  Platform:
    osname=linux, osvers=2.6.33.3-1-grsec, archname=x86_64-linux-multi
    uname='linux archon 2.6.33.3-1-grsec #1 smp preempt fri apr 30
14:59:09 mdt 2010 x86_64 intel(r) core(tm)2 quad cpu q6700 @ 2.66ghz
genuineintel gnulinux '
    config_args='-des -Dusemultiplicity -DDEBUGGING'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g',
    cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include'
    ccversion='', gccversion='4.5.0', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.11.1.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.11.1'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib
-fstack-protector'


Characteristics of this binary (from libperl):
  Compile-time options: DEBUGGING MULTIPLICITY PERL_DONT_CREATE_GVSV
                        PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
                        PERL_TRACK_MEMPOOL USE_64_BIT_ALL USE_64_BIT_INT
                        USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF
  Locally applied patches:
	RC0
	uncommitted-changes
	937302a7ee64e57880e9b8f17d6257a67226d53e
	bc0181d7f5a909cb8942767c6d860b4705daddee
	20ae53ea18272858283b5c6062003207056b5ce0
	189604b10ea23a1742e336089a5819d6900287d5
	eb9b0d6bf2c198f9372900d7e1a505a06d9eac83
	e01378a33e10271b58f7345318c9241af28c64f8
	8615356d76c331b7754ec660c69a0632c60fc00c
	ed9a37359c07a6d8b582c6c1dead720366ae1533
	d54920628df719d2fc3f377ff487b3905b633c1a
  Built under linux
  Compiled at May 10 2010 17:10:17
  @INC:
    lib
    /usr/local/lib/perl5/site_perl/5.12.1/x86_64-linux-multi
    /usr/local/lib/perl5/site_perl/5.12.1
    /usr/local/lib/perl5/5.12.1/x86_64-linux-multi
    /usr/local/lib/perl5/5.12.1
    .

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About