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

Native AOT broken in Android-arm64 #76983

Closed
josephmoresena opened this issue Oct 13, 2022 · 4 comments
Closed

Native AOT broken in Android-arm64 #76983

josephmoresena opened this issue Oct 13, 2022 · 4 comments
Labels
area-NativeAOT-coreclr help wanted [up-for-grabs] Good issue for external contributors os-android
Milestone

Comments

@josephmoresena
Copy link
Contributor

Description

I have been experimenting with Android and NativeAOT through JNI shared libraries that are consumed by the HelloJNI application.

However with latest runtime version, opening the application closes it due to the absence of the "tls_CurrentThread" symbol into the compiled library.

My last successful experiment was on 2022 July 20th with microsoft.dotnet.ilcompiler 7.0.0-rc.1.22370.2.

The JNI library code is: https://github.com/josephmoresena/NativeAOT-AndroidHelloJniLib

The branch I use to compile NativeAOT is:
https://github.com/josephmoresena/runtime/tree/android

Reproduction Steps

  1. Download the NDK version r21e.
  2. Install the NDK in ~/android-ndk-r21e
  3. Clone the android branch of josephmoresena/runtime to ~/source/repos/runtime
  4. Clone the main branch of josephmoresena/NativeAOT-AndroidHelloJniLib.
  5. Declare the following environment variables:
    export NDK_VER=r21e export ANDROID_NDK_ROOT=~/android-ndk-${NDK_VER} export ANDROID_SDK_ROOT=~/android-sdk export HOST_OS=linux export RUNTIME_REPO=~/source/repos/runtime
  6. Compile the runtime with the following command:
    TARGET_BUILD_ARCH=arm64 ./build.sh -s clr.nativeaotruntime+clr.nativeaotlibs+libs+mono -arch arm64 -os Android -c Release -lc Release -rc Release
  7. Compile NativeAOT-AndroidHelloJniLib using the instructions in the README.md file.
  8. Rename output AndroidHelloJniLib.so file to libhello-jni.so and put it inside com.example.hellojni jniLibs/ folder.
  9. Compile and debug com.example.hellojni on Android ARM64 device.

Expected behavior

The android application loads an shows a text generated by NativeAOT JNI library.

Actual behavior

Application crashes and debugger shows following error:

I/xample.hellojn: Late-enabling -Xcheck:jni E/xample.hellojn: Unknown bits set in runtime_flags: 0x8000 D/tperf_getInstance: processName = com.example.hellojni unsupported!!! D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.hellojni, PID: 17805 java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "tls_CurrentThread" referenced by "/data/app/com.example.hellojni-XDL8YyYt8MsAq_ToR3xQ8A==/base.apk!/lib/arm64-v8a/libhello-jni.so"... at java.lang.Runtime.loadLibrary0(Runtime.java:1071) at java.lang.Runtime.loadLibrary0(Runtime.java:1007) at java.lang.System.loadLibrary(System.java:1667) at com.example.hellojni.HelloJni.<clinit>(HelloJni.kt:72) at java.lang.Class.newInstance(Native Method) at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95) at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45) at android.app.Instrumentation.newActivity(Instrumentation.java:1252) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3318) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3562) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2131) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7540) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)

Regression?

I don't know with accurrancy, latest succesfull experimente was mate on 2022 July 20th.

Known Workarounds

No response

Configuration

  1. Linux Host: WLS/WLS2 Ubuntu 22.04 x64
  2. Android version: 10
  3. Android Studio: 2021.3.1

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 13, 2022
@jkotas
Copy link
Member

jkotas commented Oct 13, 2022

We are happy to accept community contributions to make native AOT to work on Android and other currently unsupported platforms.

@jkotas jkotas added this to the Future milestone Oct 13, 2022
@jkotas jkotas added help wanted [up-for-grabs] Good issue for external contributors os-android labels Oct 13, 2022
@ghost
Copy link

ghost commented Oct 13, 2022

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I have been experimenting with Android and NativeAOT through JNI shared libraries that are consumed by the HelloJNI application.

However with latest runtime version, opening the application closes it due to the absence of the "tls_CurrentThread" symbol into the compiled library.

My last successful experiment was on 2022 July 20th with microsoft.dotnet.ilcompiler 7.0.0-rc.1.22370.2.

The JNI library code is: https://github.com/josephmoresena/NativeAOT-AndroidHelloJniLib

The branch I use to compile NativeAOT is:
https://github.com/josephmoresena/runtime/tree/android

Reproduction Steps

  1. Download the NDK version r21e.
  2. Install the NDK in ~/android-ndk-r21e
  3. Clone the android branch of josephmoresena/runtime to ~/source/repos/runtime
  4. Clone the main branch of josephmoresena/NativeAOT-AndroidHelloJniLib.
  5. Declare the following environment variables:
    export NDK_VER=r21e export ANDROID_NDK_ROOT=~/android-ndk-${NDK_VER} export ANDROID_SDK_ROOT=~/android-sdk export HOST_OS=linux export RUNTIME_REPO=~/source/repos/runtime
  6. Compile the runtime with the following command:
    TARGET_BUILD_ARCH=arm64 ./build.sh -s clr.nativeaotruntime+clr.nativeaotlibs+libs+mono -arch arm64 -os Android -c Release -lc Release -rc Release
  7. Compile NativeAOT-AndroidHelloJniLib using the instructions in the README.md file.
  8. Rename output AndroidHelloJniLib.so file to libhello-jni.so and put it inside com.example.hellojni jniLibs/ folder.
  9. Compile and debug com.example.hellojni on Android ARM64 device.

Expected behavior

The android application loads an shows a text generated by NativeAOT JNI library.

Actual behavior

Application crashes and debugger shows following error:

I/xample.hellojn: Late-enabling -Xcheck:jni E/xample.hellojn: Unknown bits set in runtime_flags: 0x8000 D/tperf_getInstance: processName = com.example.hellojni unsupported!!! D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.hellojni, PID: 17805 java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "tls_CurrentThread" referenced by "/data/app/com.example.hellojni-XDL8YyYt8MsAq_ToR3xQ8A==/base.apk!/lib/arm64-v8a/libhello-jni.so"... at java.lang.Runtime.loadLibrary0(Runtime.java:1071) at java.lang.Runtime.loadLibrary0(Runtime.java:1007) at java.lang.System.loadLibrary(System.java:1667) at com.example.hellojni.HelloJni.<clinit>(HelloJni.kt:72) at java.lang.Class.newInstance(Native Method) at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95) at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45) at android.app.Instrumentation.newActivity(Instrumentation.java:1252) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3318) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3562) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2131) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7540) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)

Regression?

I don't know with accurrancy, latest succesfull experimente was mate on 2022 July 20th.

Known Workarounds

No response

Configuration

  1. Linux Host: WLS/WLS2 Ubuntu 22.04 x64
  2. Android version: 10
  3. Android Studio: 2021.3.1

Other information

No response

Author: josephmoresena
Assignees: -
Labels:

help wanted, os-android, untriaged, area-NativeAOT-coreclr

Milestone: Future

@steveisok steveisok removed the untriaged New issue has not been triaged by the area owner label Oct 13, 2022
@MichalStrehovsky
Copy link
Member

TLS-related issues were fixed by this in the past: dotnet/corert#8323. We either introduced a new place that needs an ifdef or something else regressed. (I'm on vacation and won't be looking at this more right now.)

@MichalStrehovsky
Copy link
Member

Fixed in #77475.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr help wanted [up-for-grabs] Good issue for external contributors os-android
Projects
None yet
Development

No branches or pull requests

4 participants