c – 在Linux x64下使用libmozjs-52(SpiderMonkey)进行分段错误
作者:互联网
我正在尝试在Linux x64(Ubuntu 17.04)下使用libmozjs(SpiderMonkey).但是,在最初的步骤出现问题.
SpiderMonkey项目没有bug跟踪器,在使用Google之后我也没有找到关于我的问题的任何解决方法,所以我向荣幸的StackOverflow社区寻求帮助.
首先,我尝试使用3个版本的SpiderMonkey:
>版本45(稳定):https://people.mozilla.org/~sfink/mozjs-45.0.2.tar.bz2
>第52版(草案):https://hg.mozilla.org/releases/mozilla-esr52/archive/tip.tar.bz2
>版本55a1(草案,最新):hg clone http://hg.mozilla.org/mozilla-central/
其次,所有这些版本都是以同样的方式制作的:
$cd js/src
$autoconf2.13
$mkdir build_DBG.OBJ
$cd build_DBG.OBJ
$../configure --enable-debug --disable-optimize
$make
(最初我使用的配置没有选项–enable-debug –disable-optimize,具有相同的错误,后来添加了选项以便能够回溯代码)
第三,我的示例代码非常简单:
#include <iostream>
#include <stdexcept>
#include "jsapi.h"
#include "js/Initialization.h"
int main(int argc, char** args){
std::cout<< "Start...\n"
if(!JS_Init())
throw std::runtime_error("Failed to initialize");
std::cout << "It's alive!\n";
JS_ShutDown();
std::cout << "Finished\n";
return 0;
}
我已经从这段代码编译了三个可执行文件,每个版本的SpiderMonkey一个:
$g++ --std=c++11 -I~/mozjs-45/js/src/build_OPT.OBJ/dist/include -L~/mozjs-45/js/src/build_OPT.OBJ/dist/bin test.cpp -o test.45 -Wall -lmozjs-45 -DDEBUG -ggdb
$g++ --std=c++11 -I~/mozjs-52/js/src/build_OPT.OBJ/dist/include -L~/mozjs-52/js/src/build_OPT.OBJ/dist/bin test.cpp -o test.52 -Wall -lmozjs-52 -DDEBUG -ggdb
$g++ --std=c++11 -I~/mozjs-55a1/js/src/build_OPT.OBJ/dist/include -L~/mozjs-55a1/js/src/build_OPT.OBJ/dist/bin test.cpp -o test.55a1 -Wall -lmozjs-55a1 -DDEBUG -ggdb
最后,结果是:
版本45
正如所料:
$./test.45
Start...
It's alive!
Finished
第52版
调用JS_Init时出错:
$./test.52
Start...
Segmentation fault (core dumped)
版本55a1
调用JS_Init之前出错:
$./test.55a1
Segmentation fault (core dumped)
Backtrace ./test.52
Starting program: /home/tumick/C/cpp/test.52
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff5c27dfa in JS::detail::InitWithFailureDiagnostic (isDebugBuild=true)
at /home/tumick/mozilla-esr52-patched/js/src/vm/Initialization.cpp:89
#2 0x000055555555501a in JS_Init ()
at /home/tumick/mozilla-esr52-patched/js/src/build_DBG.OBJ/dist/include/js/Initialization.h:68
#3 0x0000555555554e38 in main (argc=1, args=0x7fffffffe078) at test.cpp:9
回溯./test.55a1
Starting program: /home/tumick/C/cpp/test.55a1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff5d8d02c in js::Mutex::Mutex (this=0x7ffff7dcc000 <js::vtune::VTuneMutex>, id=...)
at /home/tumick/mozilla-central/js/src/threading/Mutex.h:57
#2 0x00007ffff5d9a1e3 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535)
at /home/tumick/mozilla-central/js/src/vtune/VTuneWrapper.cpp:26
#3 0x00007ffff5d9a213 in _GLOBAL__sub_I_VTuneWrapper.cpp(void) ()
at /home/tumick/mozilla-central/js/src/vtune/VTuneWrapper.cpp:181
#4 0x00007ffff7de781a in call_init (l=<optimized out>, argc=argc@entry=1,
argv=argv@entry=0x7fffffffe078, env=env@entry=0x7fffffffe088) at dl-init.c:72
#5 0x00007ffff7de792b in call_init (env=0x7fffffffe088, argv=0x7fffffffe078, argc=1, l=<optimized out>)
at dl-init.c:30
#6 _dl_init (main_map=0x7ffff7ffe168, argc=1, argv=0x7fffffffe078, env=0x7fffffffe088) at dl-init.c:120
#7 0x00007ffff7dd7cda in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#8 0x0000000000000001 in ?? ()
#9 0x00007fffffffe3b8 in ?? ()
#10 0x0000000000000000 in ?? ()
是的我知道,45版是最新版本.但首先,Mozilla Firefox本身在完成后会使用每个新版本的SpiderMonkey.第二,我们在非常高负载的环境中使用Windows上的版本52(32位和64位),使用相同的源代码构建,没有任何问题.
版本52有几个关键功能,因为我们必须使用52或更高版本.
最后,我应该承认,我对C和Linux都不是很有经验.考虑到问题出现在这样的第一步和如此简单的代码,我想我只是忽略了一些非常基本和简单的东西.
所以,如果您遇到同样的问题并知道解决方法,请帮我处理.
谢谢 :)
解决方法:
我和59a1有同样的问题.防止核心转储的唯一方法是使用gecko-dev使用的expandlibs.py工具.我还提供了用于链接gecko-dev的相同g选项.
在我的59a1 build_OPT.OBJ目录中,我做了:
./_virtualenv/bin/python ../../../config/expandlibs_exec.py --uselist
-- /usr/bin/g++ -std=gnu++14 -o js-test $(pkg-config --libs mozjs-59a1) $(pkg-config --cflags mozjs-59a1) -U_FORTIFY_SOURCE
-D_FORTIFY_SOURCE=2 -Wall -Wempty-body -Wignored-qualifiers -Woverloaded-virtual -Wpointer-arith -Wsign-compare -Wtype-limits -Wunreachable-code -Wwrite-strings -Wno-invalid-offsetof -Wno-error=maybe-uninitialized -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wformat -Wformat-security -fno-sized-deallocation -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-rtti -fno-exceptions -fno-math-errno -pthread -pipe -g -freorder-blocks -O3 -fno-omit-frame-pointer test.cpp -lpthread -Wl,-z,noexecstack -Wl,-z,text -Wl,-z,relro -Wl,--build-id -B /home/plm/Source/gecko-dev/js/src/build_OPT.OBJ/build/unix/gold -rdynamic -Wl,-rpath-link,/home/plm/Source/gecko-dev/js/src/build_OPT.OBJ/dist/bin
-Wl,-rpath-link,/usr/local/lib ./mozglue/build/libmozglue.a ./js/src/build/libjs_static.a -lm -ldl -lz -lm -ldl
标签:c-2,linux,64bit,sigsegv,spidermonkey 来源: https://codeday.me/bug/20190622/1264997.html