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 compiling for android arm fail. #43906

Closed
caijw opened this issue Jul 20, 2022 · 2 comments
Closed

cross compiling for android arm fail. #43906

caijw opened this issue Jul 20, 2022 · 2 comments
Labels
android Issues and PRs related to the android platform. arm Issues and PRs related to the ARM platform.

Comments

@caijw
Copy link

caijw commented Jul 20, 2022

Version

v16.14.0

Platform

Linux VM-81-13-ubuntu 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

cross compiling for android arm fail.

android-configure file content:

#!/bin/bash

# In order to cross-compile node for Android using NDK, run:
#   source android-configure <path_to_ndk> [arch]
#
# By running android-configure with source, will allow environment variables to
# be persistent in current session. This is useful for installing native node
# modules with npm. Also, don't forget to set the arch in npm config using
# 'npm config set arch=<arch>'

# if [ $# -ne 3 ]; then
#   echo "$0 should have 3 parameters: ndk_path, target_arch and sdk_version"
#   return 1
# fi

NDK_PATH=/data/dev/android-ndk-r24
ARCH=arm
ANDROID_SDK_VERSION=27

if [ $ANDROID_SDK_VERSION -lt 23 ]; then
  echo "$ANDROID_SDK_VERSION should equal or later than 23(Android 6.0)"
fi

# CC_VER="4.9"

case $ARCH in
    arm)
        DEST_CPU="arm"
        TOOLCHAIN_NAME="armv7a-linux-androideabi"
        PLATFORM_NAME="arm-linux-androideabi";
        ;;
    x86)
        DEST_CPU="ia32"
        TOOLCHAIN_NAME="i686-linux-android"
        PLATFORM_NAME="i686-linux-android";
        ;;
    x86_64)
        DEST_CPU="x64"
        TOOLCHAIN_NAME="x86_64-linux-android"
        ARCH="x64"
        PLATFORM_NAME="x86_64-linux-android";
        ;;
    arm64|aarch64)
        DEST_CPU="arm64"
        TOOLCHAIN_NAME="aarch64-linux-android"
        ARCH="arm64"
        PLATFORM_NAME="aarch64-linux-androideabi";
        ;;
    *)
        echo "Unsupported architecture provided: $ARCH"
        return 1
        ;;
esac

SUFFIX="$TOOLCHAIN_NAME$ANDROID_SDK_VERSION"
TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH

HOST_OS="linux"
HOST_ARCH="x86_64"

export CC_host="$(command -v clang) -m32"
export CXX_host="$(command -v clang++) -m32"
export AR_host="$TOOLCHAIN/bin/llvm-ar";
export AS_host="$TOOLCHAIN/bin/llvm-as";
export LD_host="$TOOLCHAIN/bin/ld";
export NM_host="$TOOLCHAIN/bin/llvm-nm";
export RANLIB_host="$TOOLCHAIN/bin/llvm-ranlib";
export STRIP_host="$TOOLCHAIN/bin/llvm-strip";

CC_host_bin=$(command -v gcc)

host_gcc_version=$($CC_host_bin --version | grep gcc | awk '{print $NF}')
major=$(echo $host_gcc_version | awk -F . '{print $1}')
minor=$(echo $host_gcc_version | awk -F . '{print $2}')
if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || ( [ $major -eq 6 ] && [ $minor -lt 3 ] ); then
  echo "host gcc $host_gcc_version is too old, need gcc 6.3.0"
  return 1
fi



export PATH=$TOOLCHAIN/bin:$PATH
export CC=$TOOLCHAIN/bin/$SUFFIX-clang
export CXX=$TOOLCHAIN/bin/$SUFFIX-clang++
export AR_target="$TOOLCHAIN/bin/llvm-ar";
export AS_target="$TOOLCHAIN/bin/llvm-as";
export LD_target="$TOOLCHAIN/bin/ld";
export NM_target="$TOOLCHAIN/bin/llvm-nm";
export RANLIB_target="$TOOLCHAIN/bin/llvm-ranlib";
export STRIP_target="$TOOLCHAIN/bin/llvm-strip";

echo "CC ${CC}"
echo "AR_target: ${AR_target}"


GYP_DEFINES="target_arch=$ARCH"
GYP_DEFINES+=" v8_target_arch=$ARCH"
GYP_DEFINES+=" v8_target_cpu=$ARCH"
GYP_DEFINES+=" target_os=android"
GYP_DEFINES+=" target_cpu=$ARCH"
GYP_DEFINES+=" android_target_arch=$ARCH"
GYP_DEFINES+=" host_os=$HOST_OS host_arch=i386 OS=android"
export GYP_DEFINES

if [ -f "configure" ]; then
    ./configure \
        --debug \
        --dest-cpu=$DEST_CPU \
        --dest-os=android \
        --without-node-snapshot \
        --without-node-code-cache \
        --openssl-no-asm \
        --cross-compiling \
        --without-intl \
        --without-inspector \
        --without-npm
fi

building steps:

export PATH=$PATH:/data/dev/android-ndk-r24/toolchains/llvm/prebuilt/linux-x86_64/bin
source ./android-configure
make

error output:

ld: error: undefined symbol: __atomic_load
 /data/dev/android-ndk-r24/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -m32 -rdynamic -pthread -m32 -fPIC  -o /data/dev/nodejs/out/Release/mksnapshot -Wl,--start-group /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/embedded-empty.o /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/embedded-file-writer.o /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-aix.o /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.o /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-generic.o /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-mac.o /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-win.o /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/mksnapshot.o /data/dev/nodejs/out/Release/obj.host/mksnapshot/deps/v8/src/snapshot/snapshot-empty.o /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_init.a /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_libbase.a /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_libplatform.a /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_zlib.a /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_compiler.a /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_initializers.a -Wl,--end-group -latomic -ldl -lrt
ld: error: undefined symbol: __atomic_store
>>> referenced by elements.cc
>>>               /data/dev/nodejs/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/objects/elements.o:(v8::internal::(anonymous namespace)::TypedElementsAccessor<(v8::internal::ElementsKind)24, double>::TryCopyElementsFastNumber(v8::internal::Context, v8::internal::JSArray, v8::internal::JSTypedArray, unsigned int, unsigned int)) in archive /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a
>>> referenced by elements.cc
>>>               /data/dev/nodejs/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/objects/elements.o:(v8::internal::(anonymous namespace)::TypedElementsAccessor<(v8::internal::ElementsKind)24, double>::TryCopyElementsFastNumber(v8::internal::Context, v8::internal::JSArray, v8::internal::JSTypedArray, unsigned int, unsigned int)) in archive /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a
>>> referenced by elements.cc
>>>               /data/dev/nodejs/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/objects/elements.o:(v8::internal::(anonymous namespace)::TypedElementsAccessor<(v8::internal::ElementsKind)24, double>::TryCopyElementsFastNumber(v8::internal::Context, v8::internal::JSArray, v8::internal::JSTypedArray, unsigned int, unsigned int)) in archive /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a
>>> referenced 51 more times

ld: error: undefined symbol: __atomic_load
>>> referenced by elements.cc
>>>               /data/dev/nodejs/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/objects/elements.o:(v8::internal::(anonymous namespace)::TypedElementsAccessor<(v8::internal::ElementsKind)23, float>::CopyElementsFromTypedArray(v8::internal::JSTypedArray, v8::internal::JSTypedArray, unsigned int, unsigned int)) in archive /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a
>>> referenced by elements.cc
>>>               /data/dev/nodejs/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/objects/elements.o:(v8::internal::(anonymous namespace)::TypedElementsAccessor<(v8::internal::ElementsKind)24, double>::CopyElementsFromTypedArray(v8::internal::JSTypedArray, v8::internal::JSTypedArray, unsigned int, unsigned int)) in archive /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a
>>> referenced by elements.cc
>>>               /data/dev/nodejs/out/Release/obj.host/v8_base_without_compiler/deps/v8/src/objects/elements.o:(v8::internal::(anonymous namespace)::TypedElementsAccessor<(v8::internal::ElementsKind)25, unsigned char>::CopyElementsFromTypedArray(v8::internal::JSTypedArray, v8::internal::JSTypedArray, unsigned int, unsigned int)) in archive /data/dev/nodejs/out/Release/obj.host/tools/v8_gypfiles/libv8_base_without_compiler.a
>>> referenced 46 more times
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
tools/v8_gypfiles/mksnapshot.host.mk:200: recipe for target '/data/dev/nodejs/out/Release/mksnapshot' failed
make[1]: *** [/data/dev/nodejs/out/Release/mksnapshot] Error 1
rm 0ccb60d940f06e60813ee9365d029afe15dc99c0.intermediate 44c5707c8b5159d32082d5834fde45a8195947ea.intermediate 58d4b41f922c60e5789b2be74579a651f9d110e5.intermediate 7f641bbf196a7ec4220af0136bdfc750f22249af.intermediate
Makefile:113: recipe for target 'node' failed

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

No response

What is the expected behavior?

I don't know why __atomic_load is an undefined symbol.

What do you see instead?

see above: "steps reproducing the bug".

Additional information

No response

@MoLow MoLow added arm Issues and PRs related to the ARM platform. android Issues and PRs related to the android platform. labels Jul 20, 2022
@bnoordhuis
Copy link
Member

Apparently your libatomic (note the -latomic linker flag) doesn't export those symbols. That's an issue with your toolchain, not with node.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2022
@caijw
Copy link
Author

caijw commented Jul 25, 2022

@bnoordhuis I use the android NDK toolchain.

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. arm Issues and PRs related to the ARM platform.
Projects
None yet
Development

No branches or pull requests

3 participants