Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm -v and node.js throwing Illegal Instruction on cross compiled nodejs0.12.2

I cross compiled nodejs 0.12.2 for Atmel SAMA5D36 using following tool chain

export AR=arm-linux-gnueabihf-ar
export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++
export LINK=arm-linux-gnueabihf-g++

and configured and build as follows

./configure --without-snapshot --dest-cpu=arm --dest-os=linux --prefix=/home/root/nodejs-v0.12.2

make make install DESTDIR=/home/user/Desktop/nodejs_arm/nodebins

The compiled folder is generated inside /home/user/Desktop/nodejs_arm/nodebins/home/root

I compressed that folder into a tar file and transferred to AtmelSAMA5D36 arm board.I uncompressed it on the board in /home/root directory and created following symbolic link

ln -s /home/root/nodejs-v0.12.2/bin/npm /bin/npm
ln -s /home/root/nodejs-v0.12.2/bin/node /bin/node

when I test it using "node -v" and "npm -v" ,

"node -v" gives correct output but

"npm -v" throwing "illegal instruction" error
same with "node".

However cross compiled nodejs 0.10.40 is working totally fine.

Any help is highly appreciated.

Update:

(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
like image 492
Mohammed Arif Avatar asked Oct 31 '22 19:10

Mohammed Arif


1 Answers

We had a similar issue trying to use nodejs 6.1.0 via a buildroot toolchain on SAMA5D31, and ran into the same "Illegal instruction" issues. Finally we switched to using version 0.10.45 which is included in buildroot for older processors (armv5 and older).

In troubleshooting this, the problem appears to be in nodejs and OpenSSL libraries used by node where the compiled code is attempting to use Neon instructions for floating point operations. The SAMA5D3X processor reports as an armV7, but does not have a Neon FPU. However, nodejs (and openssl for us) are trying to use Neon instructions because it assumes as an armV7 it has them. Until nodejs can handle a non-Neon armV7, the best option is to use the 0.10.40 or 0.10.45 version of node until that can be resolved. Or modify the build configuration yourself for node to handle the non-Neon armV7.

like image 167
A. Blodgett Avatar answered Nov 15 '22 06:11

A. Blodgett