-
Notifications
You must be signed in to change notification settings - Fork 579
[r8-obfuscation] Keep runtime-owned JNI types #12645
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
Draft
simonrozsival
wants to merge
2
commits into
simonrozsival-nativeaot-r8-jni-integration
from
simonrozsival-r8-runtime-jni-keeps
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/Xamarin.Android.Build.Tasks/Resources/proguard_r8_jni_runtime.cfg
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Runtime-owned JNI names consumed before managed R8 remapping is available. | ||
|
|
||
| # Native entry points and runtime initialization resolve this class and its fields by name. | ||
| -keep class mono.android.Runtime { *; } | ||
|
|
||
| # The native GC bridge resolves these interface methods by name. | ||
| -keep interface mono.android.IGCUserPeer { | ||
| void monodroidAddReference(java.lang.Object); | ||
| void monodroidClearReferences(); | ||
| } | ||
|
|
||
| # The native GC bridge creates this runtime helper and invokes its interface methods. | ||
| -keep class mono.android.GCUserPeer { | ||
| <init>(); | ||
| void monodroidAddReference(java.lang.Object); | ||
| void monodroidClearReferences(); | ||
| } | ||
|
|
||
| # NativeAOT resolves this marker interface before the managed runtime is initialized. | ||
| -keep interface net.dot.jni.GCUserPeerable { | ||
| void jiAddManagedReference(java.lang.Object); | ||
| void jiClearManagedReferences(); | ||
| } | ||
|
|
||
| # Java.Interop registers these prebuilt Java runtime types by their original JNI names. | ||
| -keep class net.dot.jni.ManagedPeer { | ||
| public static native void registerNativeMembers(java.lang.Class,java.lang.String); | ||
| public static native void construct(java.lang.Object,java.lang.String,java.lang.Object[]); | ||
| } | ||
| -keep class net.dot.jni.internal.JavaProxyObject { | ||
| <init>(); | ||
| public boolean equals(java.lang.Object); | ||
| public int hashCode(); | ||
| public java.lang.String toString(); | ||
| public void jiAddManagedReference(java.lang.Object); | ||
| public void jiClearManagedReferences(); | ||
| } | ||
| -keep class net.dot.jni.internal.JavaProxyThrowable { | ||
| <init>(); | ||
| <init>(java.lang.String); | ||
| public void jiAddManagedReference(java.lang.Object); | ||
| public void jiClearManagedReferences(); | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #pragma once | ||
|
|
||
| #include <string_view> | ||
|
|
||
| namespace xamarin::android | ||
| { | ||
| class RuntimeJniNames | ||
| { | ||
| public: | ||
| static inline constexpr std::string_view RuntimeClass { "mono/android/Runtime" }; | ||
| static inline constexpr std::string_view IGCUserPeerClass { "mono/android/IGCUserPeer" }; | ||
| static inline constexpr std::string_view GCUserPeerableClass { "net/dot/jni/GCUserPeerable" }; | ||
|
|
||
| static inline constexpr std::string_view GCUserPeerRuntimeField { "mono_android_GCUserPeer" }; | ||
| static inline constexpr std::string_view IGCUserPeerRuntimeField { "mono_android_IGCUserPeer" }; | ||
| static inline constexpr std::string_view GCUserPeerableRuntimeField { "net_dot_jni_GCUserPeerable" }; | ||
|
|
||
| static inline constexpr std::string_view IGCUserPeerAddReferenceMethod { "monodroidAddReference" }; | ||
| static inline constexpr std::string_view IGCUserPeerClearReferencesMethod { "monodroidClearReferences" }; | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 💡 Testing — Please include
src/native/mono/monodroid/**/*.ccin this audit and scan it alongside CoreCLR and NativeAOT. MonoVM currently has the same SDK-owned runtime-field lookups (mono_android_IGCUserPeer,net_dot_jni_GCUserPeerable, andmono_android_GCUserPeer) inmonodroid-glue.cc/osbridge.cc; because those sources are omitted here, a future Mono-only JNI name can bypass the explicit R8 keep-coverage test.Rule: Missing regression coverage