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

[Android] Put Java JNI function in a separate static library #108513

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Commits on Nov 25, 2024

  1. [Android] Put Java JNI function in a separate static library

    In dotnet/android#9006 we are working on linking
    the .NET for Android runtime dynamically at the application build time.
    Linking involves all the BCL native libraries, including
    `System.Security.Cryptography.Native.Android` and one of the goals is to
    hide all the exported symbols used as p/invokes by the managed BCL
    libraries.  This is because p/invoke calls are handled internally and,
    with dynamic linking of the runtime, there is no longer any reason to
    use `dlopen` and `dlsym` to look them up, they are all resolved
    internally, at the link time.
    
    Symbol hiding works fine thanks to the `--exclude-libs` `clang` flag,
    which makes all the exported symbols in the indicated `.a` archives to
    not be exported by the linker.  However,
    `System.Security.Cryptography.Native.Android` is special in the sense
    that it contains one symbol which must not be hidden,
    `Java_net_dot_android_crypto_DotnetProxyTrustManager_verifyRemoteCertificate`.
    
    The above function is a Java `native` method implementation, and it
    requires that not only its name follows the Java JNI naming rules, but
    that is also available for the JVM to look up using `dlsym`.
    
    I tried using the `--export-dynamic-symbol` clang flag to
    export **just** this function, but it doesn't appear to work no matter
    where I put the flag in relation to reference to the `.a` archives.
    
    Instead, the problem can be dealt with by putting the JNI function in a
    separate static library, so that I can link it without changing symbol
    visibility, while making all the
    `System.Security.Cryptography.Native.Android` symbols invisible.
    grendello committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    d84e9b9 View commit details
    Browse the repository at this point in the history
  2. Add a comment

    grendello committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    25d242e View commit details
    Browse the repository at this point in the history