npm -v 和 node.js 在交叉编译的 nodejs0.12.2 上抛出非法指令
Posted
技术标签:
【中文标题】npm -v 和 node.js 在交叉编译的 nodejs0.12.2 上抛出非法指令【英文标题】:npm -v and node.js throwing Illegal Instruction on cross compiled nodejs0.12.2 【发布时间】:2015-12-14 06:04:07 【问题描述】:我使用以下工具链为 Atmel SAMA5D36 交叉编译了 nodejs 0.12.2
export AR=arm-linux-gnueabihf-ar
export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++
export LINK=arm-linux-gnueabihf-g++
并配置和构建如下
./configure --without-snapshot --dest-cpu=arm --dest-os=linux --prefix=/home/root/nodejs-v0.12.2
制作 make install DESTDIR=/home/user/Desktop/nodejs_arm/nodebins
编译后的文件夹在/home/user/Desktop/nodejs_arm/nodebins/home/root里面生成
我将该文件夹压缩成一个 tar 文件并传输到 AtmelSAMA5D36 臂板。我在 /home/root 目录中的板上解压缩它并创建以下符号链接
ln -s /home/root/nodejs-v0.12.2/bin/npm /bin/npm
ln -s /home/root/nodejs-v0.12.2/bin/node /bin/node
当我使用 "node -v" 和 "npm -v" 测试它时,
"node -v" 给出正确的输出但是
“npm -v”抛出“非法指令”错误 与“节点”相同。
但是,交叉编译的 nodejs 0.10.40 运行良好。
非常感谢任何帮助。
更新:
(gdb) run
Starting program: /usr/bin/node
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
Program received signal SIGILL, Illegal instruction.
0xb6edfec0 in _armv7_neon_probe () from /usr/lib/libcrypto.so.1.0.0
(gdb) c
Continuing.
Program received signal SIGILL, Illegal instruction.
0xb6edfec8 in _armv7_tick () from /usr/lib/libcrypto.so.1.0.0
(gdb) c
Continuing.
[New Thread 0xb65ca4c0 (LWP 3774)]
[New Thread 0xb67ca4c0 (LWP 3773)]
[New Thread 0xb69ca4c0 (LWP 3772)]
[New Thread 0xb6bca4c0 (LWP 3771)]
Program received signal SIGILL, Illegal instruction.
0x0054b504 in v8::internal::ComputeFlagListHash() ()
(gdb) c
Continuing.
[Thread 0xb65ca4c0 (LWP 3774) exited]
[Thread 0xb67ca4c0 (LWP 3773) exited]
[Thread 0xb69ca4c0 (LWP 3772) exited]
[Thread 0xb6bca4c0 (LWP 3771) exited]
Program terminated with signal SIGILL, Illegal instruction.
The program no longer exists.
(gdb) q
# gdb node -e 0
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-buildroot-linux-uclibcgnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from node...
(gdb)
(gdb) run
Starting program: /usr/bin/node
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
[New Thread 0xb64f84c0 (LWP 14382)]
[New Thread 0xb66f84c0 (LWP 14381)]
[New Thread 0xb68f84c0 (LWP 14380)]
[New Thread 0xb6af84c0 (LWP 14379)]
Program received signal SIGILL, Illegal instruction.
0x0054b504 in v8::internal::ComputeFlagListHash() ()
(gdb)
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /usr/bin/node
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
[New Thread 0xb653d4c0 (LWP 14531)]
[New Thread 0xb673d4c0 (LWP 14530)]
[New Thread 0xb693d4c0 (LWP 14529)]
[New Thread 0xb6b3d4c0 (LWP 14528)]
Program received signal SIGILL, Illegal instruction.
0x0054b504 in v8::internal::ComputeFlagListHash() ()
(gdb) Program received signal SIGILL, Illegal instruction.
Undefined command: "Program". Try "help".
(gdb) 0x0054b504 in v8::internal::ComputeFlagListHash() ()bt
Undefined command: "0x0054b504". Try "help".
(gdb) bt
#0 0x0054b504 in v8::internal::ComputeFlagListHash() ()
#1 0x007b8a54 in v8::internal::V8::InitializeOncePerProcessImpl() ()
#2 0x009281b0 in v8::base::CallOnceImpl(int*, void (*)(void*), void*) ()
#3 0x007b8ba8 in v8::internal::V8::Initialize() ()
#4 0x0028fc74 in v8::V8::Initialize() ()
#5 0x00897a34 in node::Start(int, char**) ()
#6 0xb6b95634 in __uClibc_main () from /lib/libc.so.1
#7 0x00000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) q
【问题讨论】:
能否输出node --v8-options
的结果
node--v8-options的前几行输出如下
目标 arm v7 vfp3 hard ARMv7=1 VFP3=1 VFP32DREGS=1 NEON=0 SUDIV=0 UNALIGNED_ACCESSES=1 MOVW_MOVT_IMMEDIATE_LOADS=0 USE_EABI_HARDFLOAT=1
你有没有想过如何解决这个问题?
@MohammedArif 有时问题是安装node
时npm
不是正确的版本,如果有任何提示,否则您也可以尝试清理npm
***.com/a/43763627/7707749 的缓存
【参考方案1】:
我们在尝试通过 SAMA5D31 上的 buildroot 工具链使用 nodejs 6.1.0 时遇到了类似的问题,并且遇到了相同的“非法指令”问题。最后我们切换到使用版本 0.10.45,它包含在 buildroot 中,用于旧处理器(armv5 和更早版本)。
在解决此问题时,问题似乎出在 node 使用的 nodejs 和 OpenSSL 库中,其中编译的代码试图使用 Neon 指令进行浮点运算。 SAMA5D3X 处理器报告为 armV7,但没有 Neon FPU。然而,nodejs(以及我们的 openssl)正在尝试使用 Neon 指令,因为它假定它具有它们的 armV7。在 nodejs 可以处理非 Neon armV7 之前,最好的选择是使用 0.10.40 或 0.10.45 版本的 node,直到可以解决。或者自己修改node的构建配置来处理非Neon armV7。
【讨论】:
以上是关于npm -v 和 node.js 在交叉编译的 nodejs0.12.2 上抛出非法指令的主要内容,如果未能解决你的问题,请参考以下文章