forked from openembedded/meta-openembedded
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nodejs: support cross compile without qemu user conditionally
Due to the scope of supported BSPs by qemu-user is limited, such as a segment fault on armv9 after qemu apply commit [target/arm: Convert LDAPR/STLR (imm) to decodetree][1] ``` |tmp-glibc/work/neoversen2-crypto-wrs-linux/nodejs/20.5.1/node-v20.5.1/out/ Release/v8-qemu-wrapper.sh: line 7: 3179613 Segmentation fault (core dumped) PSEUDO_UNLOAD=1 qemu-aarch64 -r 5.15 -L tmp-glibc/work/neoversen2-crypto-wrs-linux/ nodejs/20.5.1/recipe-sysroot -E LD_LIBRARY_PATH=tmp-glibc/work/neoversen2-crypto-wrs-linux/ nodejs/20.5.1/recipe-sysroot/usr/lib64:tmp-glibc/work/neoversen2-crypto-wrs-linux/ nodejs/20.5.1/recipe-sysroot/usr/lib64 "$@" ``` Upstream nodejs have cross compile support, but it needs host and target have same bit width (e.g. a x86_64 host targeting arrch64 to produce a 64-bit binary). So: 1. If host and target have different bit width, build with QEMU user as usual; 2. If host and target have same bit width, enable notejs cross compile support: - The build tools of nodejs is GYP[2], set CC_host, CFLAGS_host, CXX_host, CXXFLAGS_host, LDFLAGS_host, AR_host for host build which is separated with target build [3] - Add missing native packages to fix library missing on host build - Rework libatomic.patch, explicitly link to libatomic for clang conditionally BTW, enable riscv64 build [1] qemu/qemu@2521b60 [2] https://github.com/nodejs/node-gyp [3] https://github.com/nodejs/node-gyp/blob/main/gyp/docs/UserDocumentation.md#cross-compiling Signed-off-by: Hongxu Jia <[email protected]> Signed-off-by: Khem Raj <[email protected]>
- Loading branch information
1 parent
e09f1b0
commit 2b5c8b7
Showing
2 changed files
with
121 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,77 @@ | ||
Link mksnapshot with libatomic on x86 | ||
From 15e751e4b79475fb34e4b32a3ca54119b20c564a Mon Sep 17 00:00:00 2001 | ||
From: Hongxu Jia <[email protected]> | ||
Date: Sat, 17 Aug 2024 21:33:18 +0800 | ||
Subject: [PATCH] link libatomic for clang conditionally | ||
|
||
Clang-12 on x86 emits atomic builtins | ||
Clang emits atomic builtin, explicitly link libatomic conditionally: | ||
- For target build, always link -latomic for clang as usual | ||
- For host build, if host and target have same bit width, cross compiling | ||
is enabled, and host toolchain is gcc which does not link -latomic; | ||
if host and target have different bit width, no cross compiling, | ||
host build is the same with target build that requires to link | ||
-latomic; | ||
|
||
Fixes | ||
| module-compiler.cc:(.text._ZN2v88internal4wasm12_GLOBAL__N_123ExecuteCompilationUnitsERKSt10shared_ptrINS2_22BackgroundCompileTokenEEPNS0_8CountersEiNS2_19CompileBaselineOnlyE+0x558): un | ||
defined reference to `__atomic_load' | ||
Fix: | ||
|tmp-glibc/work/core2-64-wrs-linux/nodejs/20.13.0/node-v20.13.0/out/Release/node_js2c: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory | ||
|
||
Upstream-Status: Pending | ||
Signed-off-by: Khem Raj <[email protected]> | ||
Upstream-Status: Inappropriate [OE specific] | ||
|
||
Signed-off-by: Hongxu Jia <[email protected]> | ||
--- | ||
node.gyp | 13 ++++++++++++- | ||
tools/v8_gypfiles/v8.gyp | 15 ++++++++++++--- | ||
2 files changed, 24 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/node.gyp b/node.gyp | ||
index b425f443..f296f35c 100644 | ||
--- a/node.gyp | ||
+++ b/node.gyp | ||
@@ -487,7 +487,18 @@ | ||
], | ||
}], | ||
['OS == "linux" and llvm_version != "0.0"', { | ||
- 'libraries': ['-latomic'], | ||
+ 'target_conditions': [ | ||
+ ['_toolset=="host"', { | ||
+ 'conditions': [ | ||
+ ['"<!(echo $HOST_AND_TARGET_SAME_WIDTH)"=="0"', { | ||
+ 'libraries': ['-latomic'], | ||
+ }], | ||
+ ], | ||
+ }], | ||
+ ['_toolset=="target"', { | ||
+ 'libraries': ['-latomic'], | ||
+ }], | ||
+ ], | ||
}], | ||
], | ||
}, | ||
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp | ||
index b23263cf..dcabf4ca 100644 | ||
--- a/tools/v8_gypfiles/v8.gyp | ||
+++ b/tools/v8_gypfiles/v8.gyp | ||
@@ -1436,6 +1436,7 @@ | ||
{ | ||
'target_name': 'mksnapshot', | ||
'type': 'executable', | ||
+ 'libraries': [ '-latomic' ], | ||
'dependencies': [ | ||
'v8_base_without_compiler', | ||
'v8_compiler_for_mksnapshot', | ||
@@ -1100,9 +1100,18 @@ | ||
# Platforms that don't have Compare-And-Swap (CAS) support need to link atomic library | ||
# to implement atomic memory access | ||
['v8_current_cpu in ["mips64", "mips64el", "ppc", "arm", "riscv64", "loong64"]', { | ||
- 'link_settings': { | ||
- 'libraries': ['-latomic', ], | ||
- }, | ||
+ 'target_conditions': [ | ||
+ ['_toolset=="host"', { | ||
+ 'conditions': [ | ||
+ ['"<!(echo $HOST_AND_TARGET_SAME_WIDTH)"=="0"', { | ||
+ 'libraries': ['-latomic'], | ||
+ }], | ||
+ ], | ||
+ }], | ||
+ ['_toolset=="target"', { | ||
+ 'libraries': ['-latomic', ], | ||
+ }], | ||
+ ], | ||
}], | ||
], | ||
}, # v8_base_without_compiler | ||
-- | ||
2.35.5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters