Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross compile node v14.x or v.15.x for android x86_64 #36287

Open
NhatTanXT3 opened this issue Nov 27, 2020 · 6 comments · Fixed by termux/termux-packages#8108
Open

Cross compile node v14.x or v.15.x for android x86_64 #36287

NhatTanXT3 opened this issue Nov 27, 2020 · 6 comments · Fixed by termux/termux-packages#8108
Labels
android Issues and PRs related to the android platform. build Issues and PRs related to build files or the CI.

Comments

@NhatTanXT3
Copy link

  • Version: v14.15.1 and v15.3.0
  • Platform: cross compile for androidx86_64. Host (5.4.0-53-generic What goes in core / stdlib.js? #59~18.04.1-Ubuntu SMP Wed Oct 21 12:14:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux). Target (androidx86_64 sdk24)
  • Subsystem: mksnapshot build fail

What steps will reproduce the bug?

> source android-configure /path_to_ndk x86_64 24
> make -j8

The Android NDK version: Linux 64-bit (x86) r21, download from https://developer.android.com/ndk/downloads

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

The build always stuck as below state.

What is the expected behavior?

Build without error

What do you see instead?

/usr/bin/g++ -rdynamic -m64 -pthread -m64 -fPIC  -o /node/out/Release/mksnapshot -Wl,--start-group /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/embedded-empty.o /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/embedded-file-writer.o /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.o /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.o /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.o /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.o /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-win.o /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/mksnapshot.o /node/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/snapshot-empty.o /node/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a /node/out/Release/obj.host/tools/v8_gypfiles/libv8_init.a /node/out/Release/obj.host/tools/v8_gypfiles/libv8_libbase.a /node/out/Release/obj.host/tools/v8_gypfiles/libv8_libplatform.a /node/out/Release/obj.host/tools/icu/libicutools.a /node/out/Release/obj.host/tools/v8_gypfiles/libv8_libsampler.a /node/out/Release/obj.host/tools/v8_gypfiles/libv8_zlib.a /node/out/Release/obj.host/tools/v8_gypfiles/libv8_compiler.a /node/out/Release/obj.host/tools/v8_gypfiles/libv8_initializers.a -Wl,--end-group -ldl -lrt
/node/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+0x6): undefined reference to `v8::internal::trap_handler::TryHandleSignal(int, siginfo_t*, void*)'
/node/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+0x1d): undefined reference to `v8::internal::trap_handler::RegisterDefaultTrapHandler()'
collect2: error: ld returned 1 exit status

Additional information

I noted that in v8_base_without_compiler build config at deps/v8/BUILD.gn, EnableTrapHandler and RegisterDefaultTrapHandler are defined for Linux and x64 platform, but I don't see it generated in out/tools/v8_gypfiles/v8_base_without_compiler.target(host).mk (even I change the condition to always true)

I wonder is this an expected behavior?

I fixed it temporarily by disabling undefined code paths and the node can work normally in the target platform.

diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc
index 3b6226b0f4..9f346bcfc8 100644
--- a/deps/v8/src/api/api.cc
+++ b/deps/v8/src/api/api.cc
@@ -5646,7 +5646,8 @@ bool v8::V8::Initialize(const int build_config) {
 bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t* info,
                                    void* context) {
 #if V8_TARGET_ARCH_X64 && !V8_OS_ANDROID
-  return i::trap_handler::TryHandleSignal(sig_code, info, context);
+  // return i::trap_handler::TryHandleSignal(sig_code, info, context);
+  return false;
 #else
   return false;
 #endif
diff --git a/deps/v8/src/trap-handler/handler-outside.cc b/deps/v8/src/trap-handler/handler-outside.cc
index 1efbc398d0..497cf2894c 100644
--- a/deps/v8/src/trap-handler/handler-outside.cc
+++ b/deps/v8/src/trap-handler/handler-outside.cc
@@ -256,7 +256,8 @@ bool EnableTrapHandler(bool use_v8_handler) {
     return false;
   }
   if (use_v8_handler) {
-    g_is_trap_handler_enabled = RegisterDefaultTrapHandler();
+    // g_is_trap_handler_enabled = RegisterDefaultTrapHandler();
+    g_is_trap_handler_enabled = false;
     return g_is_trap_handler_enabled;
   }
   g_is_trap_handler_enabled = true;

I wonder if there are any further issues if I do this.

Thanks

@aduh95
Copy link
Contributor

aduh95 commented Nov 28, 2020

Any chance this is related to #35520?

@aduh95 aduh95 added the android Issues and PRs related to the android platform. label Nov 28, 2020
@NhatTanXT3
Copy link
Author

I think it's not related, this is more about the linker when building the objects: mksnapshot and the v8_base_without_compiler. I suspect that the handler-inside-posix.o and handler-outside-posix.o is not compiled wiith the v8_base_without_compiler

But when I hard-code to include these objects, It shown a lot of other errors on both the target and host output. I still don't know why.

Btw, I'm new with build systems like GN and GYP. Any hints are welcome.

Thank you.

@thunder-coding
Copy link
Contributor

thunder-coding commented Oct 9, 2021

This seems to have become a 64 bit problem somewhere between 16.10.10 and 16.11.0

See termux/termux-packages#7710. node v16.10.10 compiles for Android aarch64 but not v16.11.0

@thunder-coding
Copy link
Contributor

Update, I was able to fix this error by using this patch

--- ./deps/v8/src/trap-handler/trap-handler.h	2021-10-08 19:08:46.000000000 +0530
+++ ./deps/v8/src/trap-handler/trap-handler.h.mod	2021-10-09 19:43:08.715641214 +0530
@@ -17,22 +17,7 @@
 namespace internal {
 namespace trap_handler {
 
-// X64 on Linux, Windows, MacOS, FreeBSD.
-#if V8_HOST_ARCH_X64 && V8_TARGET_ARCH_X64 &&                        \
-    ((V8_OS_LINUX && !V8_OS_ANDROID) || V8_OS_WIN || V8_OS_MACOSX || \
-     V8_OS_FREEBSD)
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Arm64 (non-simulator) on Mac.
-#elif V8_TARGET_ARCH_ARM64 && V8_HOST_ARCH_ARM64 && V8_OS_MACOSX
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Arm64 simulator on x64 on Linux or Mac.
-#elif V8_TARGET_ARCH_ARM64 && V8_HOST_ARCH_X64 && (V8_OS_LINUX || V8_OS_MACOSX)
-#define V8_TRAP_HANDLER_VIA_SIMULATOR
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Everything else is unsupported.
-#else
 #define V8_TRAP_HANDLER_SUPPORTED false
-#endif
 
 // Setup for shared library export.
 #if defined(BUILDING_V8_SHARED) && defined(V8_OS_WIN)

@NhatTanXT3
Copy link
Author

I patched the nodejs on our x86_64 platform and have used it for a year without any problem. Currently, I no longer maintain the build, so I can not help you to test it. Anyway, thanks for your fix @thunder-coding

@Mesteery Mesteery added the build Issues and PRs related to build files or the CI. label Oct 21, 2021
thunder-coding added a commit to termux/termux-packages that referenced this issue Dec 1, 2021
Additional changes made:
- The patch `deps-v8-src-trap-handler-trap-handler.h.patch` should no longer be needed needed. This should also have been fixed nodejs/node#36287. If this PR succeeds to build, I will report that this has been fixed by nodejs/node@e3f8988#diff-f350b1b5e53caf9ecde4240ba8f544b3be4f278e4f8efa86b54c30ea625b8b1d
- The libatomic hack has been removed since #3092 has been reported to have been fixed with newer NDK
@guthrietiffany63
Copy link

api.cc

nodejs-github-bot pushed a commit that referenced this issue Sep 12, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
Fyko pushed a commit to Fyko/node that referenced this issue Sep 15, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: nodejs#44207
Refs: nodejs#36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
RafaelGSS pushed a commit that referenced this issue Sep 26, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
RafaelGSS pushed a commit that referenced this issue Sep 26, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
RafaelGSS pushed a commit that referenced this issue Sep 26, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
juanarbol pushed a commit that referenced this issue Oct 4, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
juanarbol pushed a commit that referenced this issue Oct 4, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
juanarbol pushed a commit that referenced this issue Oct 4, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
juanarbol pushed a commit that referenced this issue Oct 7, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
juanarbol pushed a commit that referenced this issue Oct 10, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
juanarbol pushed a commit that referenced this issue Oct 11, 2022
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: #44207
Refs: #36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
guangwong pushed a commit to noslate-project/node that referenced this issue Jan 3, 2023
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: nodejs/node#44207
Refs: nodejs/node#36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
guangwong pushed a commit to noslate-project/node that referenced this issue Jan 3, 2023
Completely rewritten the Android build system using Python

Co-Authored-By: 东灯 <43312495+Lampese@users.noreply.github.com>
Co-Authored-By: Feng Yu <F3n67u@outlook.com>
PR-URL: nodejs/node#44207
Refs: nodejs/node#36287
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issues and PRs related to the android platform. build Issues and PRs related to build files or the CI.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants