Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl 5.14 source - Sample program failing

Tags:

c++

linux

perl

Perl 5.14 source - Sample program failing

I'm trying to execute the below program on Linux 64 with libperl.so built with 5.14 source and i'm getting an abort in the location

Program terminated with signal 11, Segmentation fault.
#0  0x00002abdc0eb2656 in Perl_sv_2mortal () from ./libperl.so
(gdb) where
#0  0x00002abdc0eb2656 in Perl_sv_2mortal () from ./libperl.so
#1  0x00000000004010ed in PerlPower ()
#2  0x0000000000401335 in main ()
(gdb)

My program:

#include <EXTERN.h>
#include <perl.h>
#include <stdio.h>

static PerlInterpreter *my_perl;
static void PerlPower(int a, int b)
{
    dSP;            /* initialize stack pointer */
    ENTER;          /* everything created after here */
    SAVETMPS;       /* ...is a temporary variable. */
    PUSHMARK(SP);       /* remember the stack pointer */
    XPUSHs(sv_2mortal(newSViv(a))); /* push the base onto the stack */
    XPUSHs(sv_2mortal(newSViv(b))); /* push the exponent onto stack */
    PUTBACK;        /* make local stack pointer global */
    call_pv("expo", G_SCALAR);  /* call the function */
    SPAGAIN;        /* refresh stack pointer *
                   /* pop the return value from stack */
    printf("%d to the %dth power is %d.\n", a, b, POPi);
    PUTBACK;
    FREETMPS;       /* free that return value */
    LEAVE;          /* ...and the XPUSHed "mortal" args. */
}

int main(int argc, char **argv, char **env)
{
    char *my_argv[] = { "", "power.pl" };

    PERL_SYS_INIT3(&argc, &argv, &env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL);
    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    PerlPower(3, 4);
             /*** Compute 3 ** 4 ***/

    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}

power.pl contains the below statements

sub expo {
my ($a, $b) = @_;
return $a ** $b;
}

The above sample C and perl program was taken from the link http://perldoc.perl.org/perlembed.html#Evaluating-a-Perl-statement-from-your-C-program

I'm using the below compiler options

Compiler:

cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement'
ccversion='', gccversion='4.1.2 20070115 (prerelease) (SUSE Linux)', 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 

Can you please help me to narrow down the problem?

like image 471
yogishaj Avatar asked May 10 '26 01:05

yogishaj


1 Answers

I got one too, I got the win32 equivalent Faulting application power.exe, version 0.0.0.0, faulting module perl514.dll, version 0.0.0.0, fault address 0x000c155f. but I also got an error message :)

$ power.exe
Can't open perl script "power.pl": No such file or directory

After copying power.pl from embed it works as expected

$ cat power.pl
sub expo {
    my ($a, $b) = @_;
    return $a ** $b;
}

$ power.exe
3 to the 4th power is 81.
like image 58
perldeltas Avatar answered May 12 '26 13:05

perldeltas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!