[Chicago-talk] [Fwd: Re: 64 bit problems - XS wrappers - SOLVED.]

Scott T. Hildreth shild at sbcglobal.net
Tue Jul 18 17:42:48 PDT 2006


Well I figured it out, posting just for completeness. 
Maybe this will help someone else. :-)

-------- Forwarded Message --------
From: Scott T. Hildreth <shildret at scotth.emsphone.com>
Reply-To: shildreth at allantgroup.com
To: Perl-Xs <perl-xs at perl.org>
Subject: Re: 64 bit problems - XS wrappers - SOLVED.
Date: Tue, 18 Jul 2006 12:21:15 -0500

On Thu, 2006-07-13 at 18:49 -0500, Scott T. Hildreth wrote:
 
> I don't know how to see if it 
> is in the RETVAL

 I was not able to see RETVAL because the Makefile for my module had
 OPTIMIZE set to -O2, which was overriding my -O0 set in the PASTHRU_INC
 env.  Once I took that out of the Makefile, RETVAL was not optimized
out.  I tried to de-reference the var and saw that the memory address
was out of bounds (which I suspected all along).  Now the important
lesson that I learned. :-)  On 64 bit archs, the int is 4 bytes a
pointer is 8 bytes.  I didn't have a function prototype declared for 
this particular function.  Gcc will default the type to be int if a 
prototype doesn't declare it otherwise.  So when the return value was
being treated as a char * the 8 bit pointer was actually an 4 byte int
and was pointing off into the abyss.   
 
> > 
> > (gdb) n
> > 
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x0000000000473459 in Perl_sv_2mortal ()
> > 
> > 
> > On Thu, 2006-07-13 at 17:15 -0500, Scott T. Hildreth wrote:
> > > Posting again, didn't see it show up on the list.
> > > 
> > > ..I've seen the strlen() seg fault problem by searching, 
> > > just no solutions.  The string returned in RETVAL is null terminated, 
> > > so I don't understand.  
> > > 
> > > 
> > > On Thu, 2006-07-13 at 14:56 -0500, Scott T. Hildreth wrote:
> > > > ...we are installing 64bit Suse boxes.  I normally compile our own Perl,
> > > > leaving the vendor Perl alone.  I don't think this will help with this 
> > > > problem though (unless I compile as 32 bit).  The following XS code
> > > > fails in libc - strlen(),
> > > > 
> > > > =============================================================================
> > > > 
> > > > 1180    {
> > > > (gdb) n
> > > > 1181        dXSARGS;
> > > > (gdb) n
> > > > 1182        if (items != 2)
> > > > (gdb) n
> > > > 1188            dXSTARG;
> > > > (gdb) n
> > > > 1190            if (sv_derived_from(ST(0), "FMTPtr")) {
> > > > (gdb) n
> > > > 1191                IV tmp = SvIV((SV*)SvRV(ST(0)));
> > > > (gdb) n
> > > > 1197            if (sv_derived_from(ST(1), "FMT_FLDPtr")) {
> > > > (gdb) n
> > > > 1198                IV tmp = SvIV((SV*)SvRV(ST(1)));
> > > > (gdb) n
> > > > 419             RETVAL = (char *)fmt_get_fld_location(fmt, fld);
> > > > (gdb) p tmp
> > > > $4 = 11516288
> > > > (gdb) n 
> > > > 1206            sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
> > > > (gdb) p RETVAL
> > > > No symbol "RETVAL" in current context.
> > > > (gdb) s
> > > > 419             RETVAL = (char *)fmt_get_fld_location(fmt, fld);
> > > > (gdb) s
> > > > 1206            sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
> > > > (gdb) s
> > > > 
> > > > Program received signal SIGSEGV, Segmentation fault.
> > > > 0x00002ad1795286d0 in strlen () from /lib64/libc.so.6
> > > > 
> > > > =================================================================================
> > > > 
> > > > ...at first I thought it was the threaded-64 bit Perls, but it seg
> > > > faults  on a non-threaded version as well.  It runs fine on a 32 bit 
> > > > server.  
> > > > 
> > > > I am really hopping someone has run into this, any help would be much
> > > > appreciated.
> > > > 
> > > > 
> > > >                                       STH
> > > > 
> > > > 
> > > > 
> > > >  
-- 
Scott T. Hildreth <shild at sbcglobal.net>


More information about the Chicago-talk mailing list