Repository: pytorch
Issue: arm64-v8a not compiling due to libpytorch_jni.so
Labels: module: build,triaged,module: android,module: arm

## ❓ Questions and Help

I'm currently adapting the [Native Android C++ with Custom Ops](https://pytorch.org/tutorials/recipes/android_native_app_with_custom_op.html) guide to run my own model on React Native for Android on the nightly `PyTorch 1.8.0` build.

When I run something like `npx react-native run-android` to compile, it compiles successfully for the first kind of CPU architecture (e.g. `armeabi-v7a`):

> Build pytorch_native_armeabi-v7a
[1/2] Building CXX object CMakeFiles/pytorch_native.dir/src/main/cpp/pytorch_native.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libpytorch_native.so

but then it fails for the second architecture (e.g. `arm64-v8a`.

> Build pytorch_native_arm64-v8a
[1/2] Building CXX object CMakeFiles/pytorch_native.dir/src/main/cpp/pytorch_native.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libpytorch_native.so
FAILED: : && /Users/Sigma/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  --target=aarch64-none-linux-android21 --gcc-toolchain=/Users/Sigma/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/Sigma/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libpytorch_native.so -o ../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libpytorch_native.so CMakeFiles/pytorch_native.dir/src/main/cpp/pytorch_native.cpp.o -L/Users/Sigma/recycleNN/android/app/build/pytorch_android-1.8.0-SNAPSHOT.aar/jni/arm64-v8a -lpytorch_jni -lfbjni -llog -latomic -lm && :
ld: error: found local symbol '_edata' in global part of symbol table in file /Users/Sigma/recycleNN/android/app/build/pytorch_android-1.8.0-SNAPSHOT.aar/jni/arm64-v8a/libpytorch_jni.so
ld: error: found local symbol '__end__' in global part of symbol table in file /Users/Sigma/recycleNN/android/app/build/pytorch_android-1.8.0-SNAPSHOT.aar/jni/arm64-v8a/libpytorch_jni.so
ld: error: found local symbol '__bss_end__' in global part of symbol table in file /Users/Sigma/recycleNN/android/app/build/pytorch_android-1.8.0-SNAPSHOT.aar/jni/arm64-v8a/libpytorch_jni.so
ld: error: found local symbol '_bss_end__' in global part of symbol table in file /Users/Sigma/recycleNN/android/app/build/pytorch_android-1.8.0-SNAPSHOT.aar/jni/arm64-v8a/libpytorch_jni.so
ld: error: found local symbol '__bss_start__' in global part of symbol table in file /Users/Sigma/recycleNN/android/app/build/pytorch_android-1.8.0-SNAPSHOT.aar/jni/arm64-v8a/libpytorch_jni.so
ld: error: found local symbol '_end' in global part of symbol table in file /Users/Sigma/recycleNN/android/app/build/pytorch_android-1.8.0-SNAPSHOT.aar/jni/arm64-v8a/libpytorch_jni.so
ld: error: found local symbol '__bss_start' in global part of symbol table in file /Users/Sigma/recycleNN/android/app/build/pytorch_android-1.8.0-SNAPSHOT.aar/jni/arm64-v8a/libpytorch_jni.so
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

It seems like certain compiled variables inside `libpytorch_jni.so` is being added to runtime multiple times, causing the conflict. Does that mean I have to compile only for one architecture at a time, or am I missing something entirely? Since the native build extraction extracts all 4 at the same time, I figure they must be able to compile separately just fine.

Thank you!

**EDIT: It seems it's just `arm64-v8a` inherently that has this problem, not necessarily due to conflicts. I've cleaned my Android build files and filtered the NDK to just compile for `arm64-v8a` and it still fails on the same error.** All other architectures build properly.

cc @malfet @seemethere @walterddr