nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.8k stars 29.7k forks source link

Cross Compilation for arm64 on x64 fails #42544

Open Marv-CZ opened 2 years ago

Marv-CZ commented 2 years ago

Version

16.14.2

Platform

Linux (Fedora 34 64bit)

Subsystem

No response

What steps will reproduce the bug?

I cross compile Node.js 16.14.2 from sources for 64bit arm on 64bit Intel PC. I use the following options:

./configure --without-dtrace --without-etw --without-npm --cross-compiling --partly-static --dest-cpu=arm64 --dest-os=linux

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

It fails with following:

g++ -o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/mksnapshot -pthread -rdynamic -m64  -Wl,--start-group /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/embedded-empty.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/embedded-file-writer.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-win.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/mksnapshot.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/snapshot-empty.o /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/tools/v8_gypfiles/libv8_init.a /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/tools/v8_gypfiles/libv8_libbase.a /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/tools/v8_gypfiles/libv8_libplatform.a /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/tools/v8_gypfiles/libv8_zlib.a /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/tools/v8_gypfiles/libv8_compiler.a /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/tools/v8_gypfiles/libv8_initializers.a -static-libgcc -static-libstdc++ -ldl -lrt -Wl,--end-group
/usr/bin/ld: /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/api/api.o: in function 'v8::TryHandleWebAssemblyTrapPosix(int, siginfo_t*, void*)':
api.cc:(.text._ZN2v829TryHandleWebAssemblyTrapPosixEiP9siginfo_tPv+0x1): undefined reference to 'v8::internal::trap_handler::TryHandleSignal(int, siginfo_t*, void*)'
/usr/bin/ld: /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/api/api.o: in function 'v8::V8::TryHandleSignal(int, void*, void*)':
api.cc:(.text._ZN2v82V815TryHandleSignalEiPvS1_+0x1): undefined reference to 'v8::internal::trap_handler::TryHandleSignal(int, siginfo_t*, void*)'
/usr/bin/ld: /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/trap-handler/handler-outside.o: in function 'v8::internal::trap_handler::EnableTrapHandler(bool)':
handler-outside.cc:(.text._ZN2v88internal12trap_handler17EnableTrapHandlerEb+0x2d): undefined reference to 'v8::internal::trap_handler::RegisterDefaultTrapHandler()'
/usr/bin/ld: /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/execution/arm64/simulator-arm64.o: in function 'v8::internal::Simulator::ProbeMemory(unsigned long, unsigned long)':
simulator-arm64.cc:(.text._ZN2v88internal9Simulator11ProbeMemoryEmm+0x1c): undefined reference to `ProbeMemory'
/usr/bin/ld: /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/execution/arm64/simulator-arm64.o: in function 'v8::internal::Simulator::LoadStoreHelper(v8::internal::Instruction*, long, v8::internal::AddrMode)':
simulator-arm64.cc:(.text._ZN2v88internal9Simulator15LoadStoreHelperEPNS0_11InstructionElNS0_8AddrModeE+0x85): undefined reference to 'ProbeMemory'
/usr/bin/ld: /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/execution/arm64/simulator-arm64.o: in function 'v8::internal::Simulator::NEONLoadStoreSingleStructHelper(v8::internal::Instruction const*, v8::internal::AddrMode)':
simulator-arm64.cc:(.text._ZN2v88internal9Simulator31NEONLoadStoreSingleStructHelperEPKNS0_11InstructionENS0_8AddrModeE+0xde): undefined reference to 'ProbeMemory'
/usr/bin/ld: simulator-arm64.cc:(.text._ZN2v88internal9Simulator31NEONLoadStoreSingleStructHelperEPKNS0_11InstructionENS0_8AddrModeE+0x258): undefined reference to 'ProbeMemory'
/usr/bin/ld: simulator-arm64.cc:(.text._ZN2v88internal9Simulator31NEONLoadStoreSingleStructHelperEPKNS0_11InstructionENS0_8AddrModeE+0x40a): undefined reference to 'ProbeMemory'
/usr/bin/ld: /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/execution/arm64/simulator-arm64.o:simulator-arm64.cc:(.text._ZN2v88internal9Simulator31NEONLoadStoreSingleStructHelperEPKNS0_11InstructionENS0_8AddrModeE+0x83c): more undefined references to 'ProbeMemory' follow
collect2: error: ld returned 1 exit status
make[2]: *** [tools/v8_gypfiles/mksnapshot.host.mk:183: /home/cernockym/Vyvoj/modulesnodered/packages/nodejs/node-v16.14.2/out/Release/mksnapshot] Error1
rm 9f3f2e3c4ad47a90f02b3b7187e9a3474a4663fa.intermediate 7cd555c6c2320e6d4413897b735e5c5c5d6e73a6.intermediate 6bcf538ce384c5de2b15bb794e81c50b7ea812d0.intermediate fc574ff59cc128ac3e7879ba202a247eb6792904.intermediate
make[1]: *** [Makefile:113: node] Error 2

Additional information

No response

bnoordhuis commented 2 years ago

Where did you get the source tarball from? I'm pretty sure simulator-arm64.cc isn't built by the official distribution.

edit: I was wrong, it's scraped at configure time from deps/v8/BUILD.gn.

Marv-CZ commented 2 years ago

I used link on https://nodejs.org/en/download/ i.e. https://nodejs.org/dist/v16.14.2/node-v16.14.2.tar.gz

Marv-CZ commented 2 years ago

Actually, no, because of the size, I downloaded xz archive: https://nodejs.org/dist/v16.14.2/node-v16.14.2.tar.xz

Hypfer commented 2 years ago

Can confirm that the same happens by checking out the v16.14.2 git tag

bnoordhuis commented 2 years ago

Can you check if HEAD of the master branch cross-compiles okay? I think there's a good chance 6ac1cccf9fd5 fixed this.

Hypfer commented 2 years ago

What I can say right now is that compilation of git tag v17.8.0 works fine Same for v16.10.0

I can try building HEAD of master later today

Marv-CZ commented 2 years ago

Yes, I used 16.10.0 previously and it works fine. I try to find which version is breaking.

Marv-CZ commented 2 years ago

So, I tried to build various versions and it is broken from 16.11.0.

I also tried to apply Ben's suggested patch 6ac1ccc back to 16.14.2 and it works. Thank you very much Ben.

bnoordhuis commented 2 years ago

@targos is 6ac1ccc eligible for cherry-picking to the release branches? Looks low risk to me.

targos commented 2 years ago

I don't have any problem with it if it doesn't break the build.

bnoordhuis commented 2 years ago

@Hypfer @Marv-CZ you want to take a stab at back-porting it? Details are here.

edit: deleted an OoO auto-reply from @Tronzo

AHgPuK commented 2 years ago

Here is a working patch link