-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
grendello
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
grendello:dev/grendel/android-crypto-public-symbols
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Android] Put Java JNI function in a separate static library #108513
grendello
wants to merge
2
commits into
dotnet:main
from
grendello:dev/grendel/android-crypto-public-symbols
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet-policy-service
bot
added
the
community-contribution
Indicates that the PR has been added by a community member
label
Oct 3, 2024
grendello
force-pushed
the
dev/grendel/android-crypto-public-symbols
branch
from
October 3, 2024 11:59
aa4fac2
to
7e67d99
Compare
Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger |
teo-tsirpanis
removed
the
community-contribution
Indicates that the PR has been added by a community member
label
Oct 3, 2024
This was referenced Oct 3, 2024
grendello
force-pushed
the
dev/grendel/android-crypto-public-symbols
branch
from
November 25, 2024 15:44
c77e32e
to
25d242e
Compare
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
force-pushed
the
dev/grendel/android-crypto-public-symbols
branch
from
December 6, 2024 10:38
25d242e
to
9521f00
Compare
This was referenced Dec 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In dotnet/android#9006 we are working on linking the
.NET for Android
runtime dynamically at the application build time.
Linking includes all the relevant BCL native libraries, and one of the goals is to
hide all the exported symbols used as
p/invokes
by the managed BCLlibraries. 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
anddlsym
to look them up, they are all resolvedinternally, 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 tonot 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 itrequires that not only its name follows the Java JNI naming rules, but
that it is also available for the JVM to look up using
dlsym
.I tried using the
--export-dynamic-symbol
clang flag toexport 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.