Perl 5.14 源代码 - 示例程序失败

发布于 2024-12-19 20:20:39 字数 2901 浏览 1 评论 0 原文

Perl 5.14 源代码 - 示例程序失败

我尝试使用 5.14 源代码构建的 libperl.so 在 Linux 64 上执行以下程序 我在位置中止

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)

我的程序:

#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 包含以下语句 上面

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

的示例 C 和 perl 程序取自链接 http://perldoc.perl.org/perlembed.html#Evaluating-a-Perl-statement-from-your-C-program

我正在使用以下编译器选项

编译器:

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 

可以请帮我缩小问题范围?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷了相思 2024-12-26 20:20:39

我也有一个,我得到了win32等效的故障应用程序power.exe,版本0.0.0.0,故障模块perl514.dll,版本0.0.0.0,故障地址0x000c155f。
但我也收到一条错误消息:)

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

从 embed 复制 power.pl 后,它按预期工作

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

$ power.exe
3 to the 4th power is 81.

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.
初与友歌 2024-12-26 20:20:39

问题是在编译源代码时我没有指定新的 5.14.2 头文件位置。我将 c 和 perl 文件复制到包含 5.14.2 的新头文件的文件夹中,并使用以下选项进行编译解决了问题

g++ -o test_perl test_perl.c -I 。 -L。 -g perl -MExtUtils::Embed -e ccopts -e ldopts
LD_LIBRARY_PATH=.:LD_LIBRARY_PATH;导出LD_LIBRARY_PATH

The problem was while compiling the source i hadn't specified the new 5.14.2 header files location. I copied both the c and perl file to the folder containing new header file of 5.14.2 and compiling with below options resolved the problem

g++ -o test_perl test_perl.c -I . -L . -g perl -MExtUtils::Embed -e ccopts -e ldopts
LD_LIBRARY_PATH=.:LD_LIBRARY_PATH;export LD_LIBRARY_PATH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文