我想在Linux x64(Ubuntu 17.04)下使用libmozjs(SpiderMonkey)。然而,在最初的步驟中出現了問題。Linux x64下使用libmozjs-52(SpiderMonkey)的分段錯誤
SpiderMonkey項目沒有錯誤跟蹤器,也非常困難地使用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
(最初我使用configure
不帶選項--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;
}
我從這個代碼,一個編3個可執行文件的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
一ND最後,結果是:
版本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)
./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>, [email protected]=1,
[email protected]=0x7fffffffe078, [email protected]=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(版本32和64位)上的52版本幾個月,從相同的源代碼生成,沒有任何問題。
版本52有幾個關鍵特性,因爲我們必須使用完全版本52或更高版本。最後,我應該承認,我並不是非常有經驗的C++和Linux都不是。考慮到在這樣的第一步中出現的問題以及這樣一個瑣碎的代碼,我想我只是忽略了一些非常基本和簡單的東西。
因此,如果您遇到同樣的問題並知道解決方法,請幫助我解決它。
謝謝:)
重要提示:後'make' libmozjs(所有三個版本的)我第一次確信,它的工作原理是正確的,運行'./build_DBG.OBJ/JS/src目錄/ JSAPI檢驗/ JSAPI-tests'。所有的測試都是成功的。 – tumick
'$ UNAME -r' 4.10.0-20泛型 '$ GCC --version' GCC(Ubuntu的6.3.0-12ubuntu2)6.3.0 20170406 '$ LD --version' GNU LG (用於Ubuntu的GNU Binutils)2.28 – tumick
已經使用選項'--disable-jemalloc'嘗試過 - 相同的結果 – tumick