我正在尝试在Ubuntu 17.04 x64下使用SpiderMonkey。
SpiderMonkey项目没有错误跟踪器,经过谷歌搜索后我没有找到任何关于我的问题的解决方法,所以我向社区寻求帮助。
1)从官方download page下载的SpiderMonkey源代码:
https://people.mozilla.org/~sfink/mozjs-45.0.2.tar.bz2
2)构建命令(来自官方documentation page):
$ cd js/src
$ autoconf2.13
$ mkdir build_OPT.OBJ
$ cd build_OPT.OBJ
$ ../configure
$ make
3)从官方example page嵌入mozjs库的示例代码,但是这里我带了最简单的代码,它重现了错误:
#include "jsapi.h"
#include "js/Initialization.h"
int main(int argc, const char *argv[])
{
JS_Init();
JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024);
if (!rt)
return 1;
JSContext *cx = JS_NewContext(rt, 8192);
if (!cx)
return 1;
// here I plan to evaluate JavaScript expressions...
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
JS_ShutDown();
return 0;
}
4)我已使用此命令编译,也在官方示例页面中给出:
$ g++ -std=c++11 -I~/mozjs-45.0.2/js/src/build_OPT.OBJ/dist/include -L~/mozjs-45.0.2/js/src/build_OPT.OBJ/dist/bin main.cpp -o main -lmozjs-45 -lz -lpthread -ldl
5)运行后,在JS_NewContext
调用时获得了分段错误,并进行了以下回溯:
Starting program: /home/tumick/C/cpp/main
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff5600700 (LWP 12326)]
[New Thread 0x7ffff53ff700 (LWP 12327)]
[New Thread 0x7ffff51fe700 (LWP 12328)]
[New Thread 0x7ffff4ffd700 (LWP 12329)]
[New Thread 0x7ffff4dfc700 (LWP 12330)]
Thread 1 "main" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff6d62722 in js::ScriptBytecodeHasher::hash (l=<synthetic pointer>..., l=<synthetic pointer>...)
at /home/tumick/mozjs-45.0.2/js/src/jsscript.h:2411
#2 js::detail::HashTable<js::SharedScriptData* const, js::HashSet<js::SharedScriptData*, js::ScriptBytecodeHasher, js::SystemAllocPolicy>::SetOps, js::SystemAllocPolicy>::prepareHash (l=<synthetic pointer>...) at ../../dist/include/js/HashTable.h:1126
#3 js::detail::HashTable<js::SharedScriptData* const, js::HashSet<js::SharedScriptData*, js::ScriptBytecodeHasher, js::SystemAllocPolicy>::SetOps, js::SystemAllocPolicy>::lookupForAdd (l=<synthetic pointer>..., this=<optimized out>) at ../../dist/include/js/HashTable.h:1638
#4 js::HashSet<js::SharedScriptData*, js::ScriptBytecodeHasher, js::SystemAllocPolicy>::lookupForAdd (l=<synthetic pointer>...,
this=<optimized out>) at ../../dist/include/js/HashTable.h:386
#5 SaveSharedScriptData (cx=cx@entry=0x5555557841f0, script=..., ssd=<optimized out>, nsrcnotes=1)
at /home/tumick/mozjs-45.0.2/js/src/jsscript.cpp:2502
#6 0x00007ffff6d62c41 in JSScript::fullyInitTrivial (cx=cx@entry=0x5555557841f0, script=..., script@entry=...)
at /home/tumick/mozjs-45.0.2/js/src/jsscript.cpp:2886
#7 0x00007ffff6d20316 in CreateFunctionPrototype (cx=0x5555557841f0, key=<optimized out>) at /home/tumick/mozjs-45.0.2/js/src/jsfun.cpp:785
#8 0x00007ffff6ddcb52 in js::GlobalObject::resolveConstructor (cx=0x5555557841f0, global=..., key=<optimized out>)
at /home/tumick/mozjs-45.0.2/js/src/vm/GlobalObject.cpp:158
#9 0x00007ffff6ddd06e in js::GlobalObject::ensureConstructor (cx=cx@entry=0x5555557841f0, global=..., global@entry=...,
key=key@entry=JSProto_Function) at /home/tumick/mozjs-45.0.2/js/src/vm/GlobalObject.cpp:98
#10 0x00007ffff6c4fe8b in CreateObjectConstructor (cx=0x5555557841f0, key=<optimized out>)
at /home/tumick/mozjs-45.0.2/js/src/builtin/Object.cpp:1035
#11 0x00007ffff6ddcbbe in js::GlobalObject::resolveConstructor (cx=0x5555557841f0, global=..., key=<optimized out>)
at /home/tumick/mozjs-45.0.2/js/src/vm/GlobalObject.cpp:166
#12 0x00007ffff6ddd06e in js::GlobalObject::ensureConstructor (cx=cx@entry=0x5555557841f0, global=..., global@entry=...,
key=key@entry=JSProto_Object) at /home/tumick/mozjs-45.0.2/js/src/vm/GlobalObject.cpp:98
#13 0x00007ffff6a05f92 in js::GlobalObject::getOrCreateObjectPrototype (cx=0x5555557841f0, this=<optimized out>)
at /home/tumick/mozjs-45.0.2/js/src/vm/GlobalObject.h:342
#14 CreateArrayPrototype (cx=0x5555557841f0, key=<optimized out>) at /home/tumick/mozjs-45.0.2/js/src/jsarray.cpp:3235
#15 0x00007ffff6ddebe1 in InitBareBuiltinCtor (cx=cx@entry=0x5555557841f0, global=..., global@entry=...,
protoKey=protoKey@entry=JSProto_Array) at /home/tumick/mozjs-45.0.2/js/src/vm/GlobalObject.cpp:368
#16 0x00007ffff6ddee10 in js::GlobalObject::initSelfHostingBuiltins (cx=cx@entry=0x5555557841f0, global=global@entry=...,
builtins=builtins@entry=0x7ffff7da9520 <intrinsic_functions>) at /home/tumick/mozjs-45.0.2/js/src/vm/GlobalObject.cpp:413
#17 0x00007ffff6e6ffcb in JSRuntime::createSelfHostingGlobal (cx=cx@entry=0x5555557841f0)
at /home/tumick/mozjs-45.0.2/js/src/vm/SelfHosting.cpp:1730
#18 0x00007ffff6e70115 in JSRuntime::initSelfHosting (this=this@entry=0x5555557693f0, cx=cx@entry=0x5555557841f0)
at /home/tumick/mozjs-45.0.2/js/src/vm/SelfHosting.cpp:1754
#19 0x00007ffff6cd3e23 in js::NewContext (rt=0x5555557693f0, stackChunkSize=<optimized out>)
at /home/tumick/mozjs-45.0.2/js/src/jscntxt.cpp:122
#20 0x000055555555499b in main ()
6)最后,有关版本的一些信息:
$ uname -r
4.10.0-20-generic
$ gcc --version
gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
$ ld --version
GNU lg (GNU Binutils for Ubuntu) 2.28
因为代码非常简单,我认为我的环境出了问题,但我不知道原因。
所以,也许你遇到了同样的问题,并且知道要解决它的解决方法,请帮助我处理它。
谢谢你:)
答案 0 :(得分:3)
这是一个老问题:MOZ_GLUE_IN_PROGRAM打破独立构建(最后在Linux平台上)。
要禁用MOZ_GLUE_IN_PROGRAM编辑js/src/configure.in
并替换
case "${OS_TARGET}" in
Android|WINNT|Darwin)
MOZ_GLUE_IN_PROGRAM=
;;
*)
dnl On !Android !Windows !OSX, we only want to link executables against mozglue
MOZ_GLUE_IN_PROGRAM=1
AC_DEFINE(MOZ_GLUE_IN_PROGRAM)
;;
esac
通过
dnl In stand-alone builds we always only want to link executables against mozglue.
if test "$JS_STANDALONE"; then
MOZ_GLUE_IN_PROGRAM=
else
case "${OS_TARGET}" in
Android|WINNT|Darwin)
MOZ_GLUE_IN_PROGRAM=
;;
*)
dnl On !Android !Windows !OSX, we only want to link executables against mozglue
MOZ_GLUE_IN_PROGRAM=1
AC_DEFINE(MOZ_GLUE_IN_PROGRAM)
;;
esac
fi
有关详细信息,请参阅Bugzilla Bug 1176787。