Discussion:
64 bit problems - XS wrappers
(too old to reply)
Scott T. Hildreth
2006-07-13 22:15:07 UTC
Permalink
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.
...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 <***@scotth.emsphone.com>
Scott T. Hildreth
2006-07-13 23:32:38 UTC
Permalink
I changed the XS declaration to a SV * and changed,

RETVAL = (char *)fmt_get_fld_location(fmt, fld);

to RETVAL = (SV *)fmt_get_fld_location(fmt, fld)

...and in gdb I could see more,

(gdb) n
1197 IV tmp = SvIV((SV*)SvRV(ST(1)));
(gdb) n
419 RETVAL = (SV *)fmt_get_fld_location(fmt, fld);
(gdb) n
1205 ST(0) = RETVAL;
(gdb) p RETVAL
No symbol "RETVAL" in current context.
(gdb) n
1206 sv_2mortal(ST(0));
(gdb) p ST(0)
$6 = (SV *) 0x600ea0
(gdb) p *ST(0)
$7 = {sv_any = 0x0, sv_refcnt = 2147482504, sv_flags = 8388608}


...shouldn't sv_any not be null?

(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x0000000000473459 in Perl_sv_2mortal ()
Post by Scott T. Hildreth
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.
...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 <***@scotth.emsphone.com>
Scott T. Hildreth
2006-07-13 23:49:14 UTC
Permalink
Post by Scott T. Hildreth
I changed the XS declaration to a SV * and changed,
RETVAL = (char *)fmt_get_fld_location(fmt, fld);
to RETVAL = (SV *)fmt_get_fld_location(fmt, fld)
...and in gdb I could see more,
(gdb) n
1197 IV tmp = SvIV((SV*)SvRV(ST(1)));
(gdb) n
419 RETVAL = (SV *)fmt_get_fld_location(fmt, fld);
(gdb) n
1205 ST(0) = RETVAL;
(gdb) p RETVAL
No symbol "RETVAL" in current context.
(gdb) n
1206 sv_2mortal(ST(0));
(gdb) p ST(0)
$6 = (SV *) 0x600ea0
(gdb) p *ST(0)
...okay this doesn't tell me anything. I got the same result on
for another function call, which does not seg fault. It also returns a
(char *) and works. I'm stumped. If I step into the function I see the
null string is created and the returned. I don't know how to see if it
is in the RETVAL
Post by Scott T. Hildreth
$7 = {sv_any = 0x0, sv_refcnt = 2147482504, sv_flags = 8388608}
...shouldn't sv_any not be null?
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0x0000000000473459 in Perl_sv_2mortal ()
Post by Scott T. Hildreth
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.
...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 <***@scotth.emsphone.com>
Scott T. Hildreth
2006-07-18 17:21:15 UTC
Permalink
Post by Scott T. Hildreth
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.
Post by Scott T. Hildreth
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0x0000000000473459 in Perl_sv_2mortal ()
Post by Scott T. Hildreth
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.
...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 <***@scotth.emsphone.com>
Loading...