本文介绍了luajit2.0.0-分段错误:11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用来自 http://lua-users.org/wiki/SimpleLuaApiExample 的简单示例进行测试.该示例可以成功与libluajit.a静态链接,但是在运行它时会出现以下错误消息:

I use a simple example from http://lua-users.org/wiki/SimpleLuaApiExample to make a test. The sample can be statically linked with libluajit.a with a success, but this error message occurs when you run it:

Segmentation fault: 11

我使用2012年11月8日发布的LuaJIT-2.0.0.我的操作系统是Mac OSX Lion 10.7.5.

I use LuaJIT-2.0.0 released at 2012-11-08. My OS is Mac OSX Lion 10.7.5.

$ uname -a
Darwin macmatoMacBook-Pro.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64

测试步骤:

$ cd lj2
$ ls
COPYRIGHT Makefile  README    doc       dynasm    etc       src
$ make
==== Building LuaJIT 2.0.0 ====
make -C src
DYNLINK   libluajit.so
LINK      luajit
OK        Successfully built LuaJIT
==== Successfully built LuaJIT 2.0.0 ====
$ rm src/*.so            # force to use the static version: libluajit.a
$ cd ..

编译并运行示例应用程序

test.c script.lua 均来自此处.文件夹 lj2 包含上述luajit-2.0.0的源代码,刚刚编译成功.

compile and run the sample app

Both test.c and script.lua come from here. The folder lj2 contains the source code of the above luajit-2.0.0, just compiled successfully.

$ ls
lj2 script.lua test.c

使用clang编译器

use clang compiler

$ clang -o test test.c -I./lj2/src -L./lj2/src -lluajit
$ ./test
Segmentation fault: 11

使用gcc编译器

use gcc compiler

$ gcc -o test test.c -I./lj2/src -L./lj2/src -lluajit
$ ./test
Segmentation fault: 11


但是,如果我用test.c替换lj2/src/luajit.c,它将给我带来成功.这很奇怪.见下文:


But if I replace lj2/src/luajit.c with test.c, it will give me a success. This is very strange. See below:

$ cd lj2
$ make clean
$ mv src/luajit.c src/luajit.c.orig
$ cp ../test.c src/luajit.c
$ make
$ cp src/luajit ../
$ cd ..
$ ./luajit
The table the script received has:
1   2
2   4
3   6
4   8
5   10
Returning data back to C
Script returned: 30

推荐答案

问题已解决.在此页面中,有一节说明了如何嵌入LuaJIT:
http://luajit.org/install.html

Problem resolved. There is an section which explains how to Embedding LuaJIT in this page:
http://luajit.org/install.html

-pagezero_size 10000 -image_base 100000000

-pagezero_size 10000 -image_base 100000000

此外,建议对在运行时在OSX/x64上加载的所有(自编译)共享库(例如Lua的C扩展模块)进行重新基准化.请参阅:man rebase

Also, it's recommended to rebase all (self-compiled) shared libraries which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua). See: man rebase

现在,让我再次对其进行测试:

Now, let me test it again:

$ clang -o test test.c -O3 -I./lj2/src -L./lj2/src -lluajit -pagezero_size 10000 -image_base 100000000
$ ./test
The table the script received has:
1   2
2   4
3   6
4   8
5   10
Returning data back to C
Script returned: 30

然后valgrind返回

And valgrind returns

$ valgrind ./test
bad executable (__PAGEZERO is not 4 GB)
valgrind: ./test: cannot execute binary file

这是另一个问题.

这篇关于luajit2.0.0-分段错误:11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 18:49