You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Glenn <gs...@gluelogic.com> on 2004/04/14 07:57:55 UTC

[mp1] segfault with DSO if compile options wrong

Back in Oct 2003, Joachim Feise started the thread:
http://marc.theaimsgroup.com/?l=apache-modperl&m=106583644716604&w=2
Subject: [mp1] segfault with Perl 5.8.1 and mod_perl 1.29

I have had similar problems with segfaults upon the first request and
traced it to a structure packing and alignment mismatch, because of
compile-time -Ddefines... mismatch between compiling mod_perl.so and
Apache.

Notice how the address of r->per_dir_config changes between
http_config.c and mod_perl.c, even though the address of the
request_rec r is the same:

Breakpoint 1, run_method (r=0x81f7384, offset=21, run_all=1) at http_config.c:370
370                 result = (*mod_handler) (r);
(gdb) print &r->per_dir_config
$1 = (void **) 0x81f74d0
(gdb) print r->per_dir_config
$2 = (void *) 0x81f806c
(gdb) stepi
0x08053b09      370                 result = (*mod_handler) (r);
(gdb)
0x08053b0c      370                 result = (*mod_handler) (r);
(gdb)
0x08053b0f      370                 result = (*mod_handler) (r);
(gdb)
perl_header_parser (r=0x81f7384) at mod_perl.c:1013
1013    {
(gdb) print &r->per_dir_config
$3 = (void **) 0x81f74d8
(gdb) print r->per_dir_config
$4 = (void *) 0x0


The site (http://bittorrent.netspace.org/) is on a dual-proc box
and the system is Fedora Core 1 with the Perl RPMs from Fedora.
The backtrace is the same as Joachim Feise's post linked above.
perl -V output is included at the end of this post.
apache 1.3.29 and mod_perl 1.29


I had been configuring mod_perl with
  perl Makefile.PL PREFIX=/pub/p/e/perl \
    APACHE_PREFIX=/usr/local/apache-1.3.29 \
    APACHE_SRC=../apache_1.3.29/src \
    PERL_TRANS=1 PERL_METHOD_HANDLERS=1 PERL_TABLE_API=1 \
    PERL_CHILD_INIT=1 PERL_STACKED_HANDLERS=1 PERL_FIXUP=1
    DO_HTTPD=1 PREP_HTTPD=1 USE_APACI=1
  make
and then performing a separate ./configure in ../apache_1.3.29/
  ./configure --prefix=/usr/local/apache-1.3.29 \
  --enable-shared=max \
  --enable-module=headers \
  --enable-module=auth_anon \
  --enable-module=expires \
  --enable-module=rewrite --enable-shared=rewrite \
  --enable-module=proxy --enable-shared=proxy \
  --activate-module=src/modules/perl/libperl.a \
  --enable-module=perl --enable-shared=perl
  make

When doing so, I noticed that while mod_perl compiled with 
  -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING \
  -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE \
  -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm  \
  -I/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE
Apache was not being compile with similar flags.

With the above configuration, Apache would segfault upon receiving
a request.


(I also noticed the mod_perl was being compile with -fPIC, while Apache
modules were being compiled with -fpic.  I don't think this makes a
different on i386, and just mention it in passing)


The following, on the other hand DID compile Apache and mod_perl with
appropriately similar flags, and WORKS (no segfault on requests):

  perl Makefile.PL PREFIX=/pub/p/e/perl APACHE_PREFIX=/usr/local/apache-1.3.29 APACHE_SRC=../apache_1.3.29/src PERL_TRANS=1 PERL_METHOD_HANDLERS=1 PERL_TABLE_API=1 PERL_CHILD_INIT=1 PERL_STACKED_HANDLERS=1 PERL_FIXUP=1 DO_HTTPD=1 USE_DSO=1 USE_APACI=1 APACI_ARGS='--prefix=/usr/local/apache-1.3.29,--enable-shared=max,--enable-module=headers,--enable-module=auth_anon,--enable-module=expires,--enable-module=rewrite,--enable-shared=rewrite,--enable-module=proxy,--enable-shared=proxy'

and then building mod_perl and Apache together.


I suppose one could compile mod_perl with PREP_HTTPD=1 and configure
Apache separately with
  #CFLAGS_SHLIB="-fPIC -DSHARED_MODULE" \
  EXTRA_CFLAGS=`perl -MExtUtils::Embed -e ccflags | sed 's/-D_GNU_SOURCE //'` \
  ./configure --prefix=/usr/local/apache-1.3.29 \
  --enable-shared=max \
  --enable-module=headers \
  --enable-module=auth_anon \
  --enable-module=expires \
  --enable-module=rewrite --enable-shared=rewrite \
  --enable-module=proxy --enable-shared=proxy \
  --activate-module=src/modules/perl/libperl.a \
  --enable-module=perl --enable-shared=perl
but I did not test this directly.

(removing -D_GNU_SOURCE is necessary to avoid getline() prototype
conflicts for the custom getline() function in
apache/src/support/{htdigest.c,htpasswd.c,logresolv.c} that
conflict with the one in /usr/include/stdio.h when -D_GNU_SOURCE
is defined)


Apologies for the long post, but this all took many hours for me
to figure out, and there seems to be some fatal differences
between what happens when compiling mod_perl with PREP_HTTPD=1
or not, and compiling mod_perl and Apache together or separately.


Also, I'm compiling a DSO, but not configuring mod_perl with DYNAMIC=1.
Are there advantages/disadvantages/requirements for using DYNAMIC=1 when
building mod_perl as a DSO?  Thanks much.

Cheers,
Glenn


Summary of my perl5 (revision 5.0 version 8 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.4.21-9.elsmp, archname=i386-linux-thread-multi
    uname='linux bugs.devel.redhat.com 2.4.21-9.elsmp #1 smp thu jan 8 17:08:56
est 2004 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 -Dversion=5.8.3 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.2 5.8.1 5.8.0'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -march=i386 -mcpu=i686',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.3.2 20031218 (Red Hat Linux 3.3.2-5)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.3/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
 
 
Characteristics of this binary (from libperl):
  Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
  Built under linux
  Compiled at Feb 25 2004 13:30:53
  @INC:
    /usr/lib/perl5/5.8.3/i386-linux-thread-multi
    /usr/lib/perl5/5.8.3
    /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.3
    /usr/lib/perl5/site_perl/5.8.2
    /usr/lib/perl5/site_perl/5.8.1
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.3
    /usr/lib/perl5/vendor_perl/5.8.2
    /usr/lib/perl5/vendor_perl/5.8.1
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    .

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] segfault with DSO if compile options wrong

Posted by Stas Bekman <st...@stason.org>.
Glenn wrote:
[a very detailed analysis snipped]

> Apologies for the long post, but this all took many hours for me
> to figure out, and there seems to be some fatal differences
> between what happens when compiling mod_perl with PREP_HTTPD=1
> or not, and compiling mod_perl and Apache together or separately.

Thanks Glenn for this research.

As you probably realize this is not a mod_perl problem per se, and it's up to 
the user to make sure that they use identical compilation arguments when 
building things separately. So it's probably the best to just adopt this post 
of yours in the install.pod of the modperl 1 guide in the section that 
explains how to build things separately. First, starting with the statement of 
the potential problem, following by the possible solutions as in your post. If 
you could submit a patch against modperl-docs/docs/1.0/guide/install.pod, I'd 
gladly commit it. Please see:
http://perl.apache.org/download/docs.html

Thanks.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html