nodejs / node

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

Cross compiling target aarch64-linux on host x86_64-macOS #37470

Open jjm2473 opened 3 years ago

jjm2473 commented 3 years ago

What steps will reproduce the bug?

I have a aarch64 openwrt toolchain (/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl), cross compiling node.js:

export PATH=/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/bin:$PATH
export STAGING_DIR=/Volumes/data/src/lienol-openwrt/staging_dir/target-aarch64_cortex-a72_musl
export PKG_CONFIG_PATH=$STAGING_DIR/usr/lib/pkgconfig:$STAGING_DIR/usr/share/pkgconfig
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_PATH

CC="aarch64-openwrt-linux-musl-gcc -Os -pipe" CXX="aarch64-openwrt-linux-musl-g++ -Os -pipe" CC_host="gcc " CXX_host="g++ "  ./configure --dest-cpu=arm64 --dest-os=linux --cross-compiling --shared-zlib --shared-openssl --shared-nghttp2 --shared-libuv --shared-cares --with-intl=none     --prefix=/usr

CFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/Volumes/data/src/node/node-v14.15.5=node-v14.15.5 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro  -I/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/usr/include -I/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/include/fortify -I/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/include " CXXFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/Volumes/data/src/node/node-v14.15.5=node-v14.15.5 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro  -I/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/usr/include -I/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/include/fortify -I/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/include " LDFLAGS="-L/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/usr/lib -L/Volumes/data/src/lienol-openwrt/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/lib -znow -zrelro " DESTCPU=arm64 NO_LOAD='cctest.target.mk embedtest.target.mk node_mksnapshot.target.mk' LD_LIBRARY_PATH=/Volumes/data/src/lienol-openwrt/staging_dir/hostpkg/share/icu/current/lib make  -C /Volumes/data/src/node/node-v14.15.5/. AR="aarch64-openwrt-linux-musl-gcc-ar" AS="aarch64-openwrt-linux-musl-gcc -c -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/Volumes/data/src/node/node-v14.15.5=node-v14.15.5 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=aarch64-openwrt-linux-musl-ld NM="aarch64-openwrt-linux-musl-gcc-nm" CC="aarch64-openwrt-linux-musl-gcc" GCC="aarch64-openwrt-linux-musl-gcc" CXX="aarch64-openwrt-linux-musl-g++" RANLIB="aarch64-openwrt-linux-musl-gcc-ranlib" STRIP=aarch64-openwrt-linux-musl-strip OBJCOPY=aarch64-openwrt-linux-musl-objcopy OBJDUMP=aarch64-openwrt-linux-musl-objdump SIZE=aarch64-openwrt-linux-musl-size CROSS="aarch64-openwrt-linux-musl-" ARCH="aarch64"

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

Everytime

What is the expected behavior?

Build node.js successful.

What do you see instead?

  g++  -o /Volumes/data/src/node/node-v14.15.5/out/Release/obj.host/v8_libbase/deps/v8/src/base/platform/platform-linux.o ../deps/v8/src/base/platform/platform-linux.cc '-DV8_GYP_BUILD' '-DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64' '-D__STDC_FORMAT_MACROS' '-DV8_TARGET_ARCH_ARM64' '-DV8_EMBEDDER_STRING="-node.18"' '-DENABLE_DISASSEMBLER' '-DV8_PROMISE_INTERNAL_FIELD_COUNT=1' '-DENABLE_MINOR_MC' '-DOBJECT_PRINT' '-DV8_CONCURRENT_MARKING' '-DV8_ARRAY_BUFFER_EXTENSION' '-DV8_ENABLE_LAZY_SOURCE_POSITIONS' '-DV8_USE_SIPHASH' '-DDISABLE_UNTRUSTED_CODE_MITIGATIONS' '-DV8_WIN64_UNWINDING_INFO' '-DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH' '-DV8_SNAPSHOT_COMPRESSION' '-DBUILDING_V8_BASE_SHARED' -I/usr/include -I../deps/v8 -I../deps/v8/include  -pthread -Wno-unused-parameter -Wno-return-type -fno-strict-aliasing -m64 -O3 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -O3 -fno-rtti -fno-exceptions -std=gnu++1y -MMD -MF /Volumes/data/src/node/node-v14.15.5/out/Release/.deps//Volumes/data/src/node/node-v14.15.5/out/Release/obj.host/v8_libbase/deps/v8/src/base/platform/platform-linux.o.d.raw   -c
../deps/v8/src/base/platform/platform-linux.cc:13:10: fatal error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
         ^~~~~~~~~~~~~
1 error generated.
make[1]: *** [tools/v8_gypfiles/v8_libbase.host.mk:149: /Volumes/data/src/node/node-v14.15.5/out/Release/obj.host/v8_libbase/deps/v8/src/base/platform/platform-linux.o] Error 1
make: *** [Makefile:104: node] Error 2
make: Leaving directory '/Volumes/data/src/node/node-v14.15.5'

Additional information

1.v8_libbase.host.mk link platform-linux.o, should be platform-macos.o 2.clang does not support '-Wl,--start-group'

I have a PR in https://github.com/openwrt/packages/pull/14829 , but it may not suitable for others.

Is host files necessary when cross compiling, is there a way to avoid compile host files? (only build target)

jjm2473 commented 3 years ago

Anyone?