Commit 345de77
committed
[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.1 parent 0787787 commit 345de77
File tree
5 files changed
+28
-14
lines changed- src
- installer/pkg/sfx/Microsoft.NETCore.App
- native/libs/System.Security.Cryptography.Native.Android
5 files changed
+28
-14
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| |||
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | | - | |
| 56 | + | |
| 57 | + | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
| |||
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| 67 | + | |
63 | 68 | | |
Lines changed: 1 addition & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | 2 | | |
6 | 3 | | |
7 | 4 | | |
8 | | - | |
| 5 | + | |
9 | 6 | | |
10 | 7 | | |
11 | 8 | | |
| |||
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
0 commit comments