Skip to content

[r8-obfuscation] Rewrite trimmable typemap JNI metadata - #12631

Open
simonrozsival wants to merge 4 commits into
mainfrom
simonrozsival-trimmable-typemap-jni-rewriting
Open

[r8-obfuscation] Rewrite trimmable typemap JNI metadata#12631
simonrozsival wants to merge 4 commits into
mainfrom
simonrozsival-trimmable-typemap-jni-rewriting

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Related to #12535

Depends on #12630

Layer 4 of 6 in the replacement stack for PR #12575. Build-pipeline activation follows in layers 5 and 6.

@simonrozsivalsimonrozsival changed the title Rewrite trimmable typemap JNI metadata[r8-obfuscation] Rewrite trimmable typemap JNI metadataSep 1, 2026
@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from 6f38f84 to df5c3eeCompareSeptember 1, 2026 16:29
@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from df5c3ee to 7aa7696CompareSeptember 1, 2026 19:09
@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from 3373599 to 4cb3e0aCompareSeptember 2, 2026 08:58
@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from 4cb3e0a to 97d02a5CompareSeptember 2, 2026 11:23
@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from 97d02a5 to d05381eCompareSeptember 2, 2026 11:55
@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from d05381e to 80bca70CompareSeptember 2, 2026 12:14
@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from 80bca70 to 6d05845CompareSeptember 2, 2026 15:19
@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from 6d05845 to e2031e4CompareSeptember 2, 2026 21:28
@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from e2031e4 to 3eeeaaaCompareSeptember 3, 2026 05:00
@simonrozsival
simonrozsival marked this pull request as ready for review September 3, 2026 10:24
CopilotAI lite review requested due to automatic review settings September 3, 2026 10:24
@simonrozsivalsimonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Sep 3, 2026
@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/review

@github-actions

github-actionsBot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12631

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new custom-attribute string-array rewriter reads the array length using host endianness and doesn’t validate the required attribute prolog, which can misparse blobs and should be fixed before merge.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (2)
SeverityFinding
Medium severitysrc/​Xamarin.Android.Build.Tasks/​Utilities/​JniRemapping/​CustomAttributeStringRewriter.cs — ❌ The custom attribute string-array rewriter doesn’t validate the 0x0001 prolog and reads the array…
Low severitytests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TypeMapAssemblyGeneratorTests.cs — 💡 ReadInlineMethodTokens is now used for ldsflda (field) tokens as well as method tokens, so…
What changed in this PR

This PR extends the R8 JNI name remapping pipeline to cover trimmable typemap metadata that is stored outside simple ldstr strings, so managed JNI metadata stays consistent with R8 mappings when obfuscation is enabled.

Changes:

  • Add support for rewriting FieldRVA-backed null-terminated UTF-8 JNI data (method names and descriptors) using R8 mappings, with conflict detection when shared data would require incompatible rewrites.
  • Extend custom-attribute rewriting to cover TypeMapAttribute<T> keys and JavaPeerAliasesAttribute string arrays.
  • Update the trimmable typemap generator to deduplicate signatures but not method names, since R8 member renames are owner-specific.
FileDescription
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TypeMapAssemblyGeneratorTests.csUpdates generator tests to reflect signature-only deduplication and adds field-token assertions.
src/​Xamarin.Android.Build.Tasks/​Utilities/​MetadataExtensions.csImproves GetCustomAttributeFullName handling for generic TypeSpecification parents (TypeRef/TypeDef).
src/​Xamarin.Android.Build.Tasks/​Utilities/​JniRemapping/​JniRewritePlanner.csPlans rewrites for FieldRVA UTF-8 data, TypeMapAttribute keys, and JavaPeerAliasesAttribute arrays; adds JavaPeerProxy owner resolution via .ctor IL.
src/​Xamarin.Android.Build.Tasks/​Utilities/​JniRemapping/​JniAssemblyRewriter.csPlumbs FieldRvaTable into rewrite planning and reverse-scan validation.
src/​Xamarin.Android.Build.Tasks/​Utilities/​JniRemapping/​CustomAttributeStringRewriter.csDocuments expanded scope and adds a helper to rewrite string-array fixed arguments.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Utilities/​JniRemapping/​JniAssemblyRewriterTests.csAdds coverage for typemap key/alias rewriting and FieldRVA UTF-8 rewrite behavior and failure modes.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Generator/​TypeMapAssemblyEmitter.csFilters registrations to those with wrappers and prepares UTF-8 fields as (shared signatures, unique method names).
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Generator/​PEAssemblyBuilder.csSplits UTF-8 FieldRVA preparation into shared vs unique caches and exposes GetUniqueUtf8Field.

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the JNI metadata rewrite, owner-specific FieldRVA allocation, reverse-scan behavior, alias rewriting, wrapper reuse, and the accompanying regression coverage. I found no actionable issues in the changed lines.

CI build #1580573 is still in progress; the currently visible checks show no failures, so this is not yet a green-build determination.

Generated by Android PR Reviewer for #12631 · gpt56 · 322.2 AIC · ⌖ 12.9 AIC · ⊞ 25.7K
Comment /review to run again

Base automatically changed from simonrozsival-managed-jni-assembly-rewriting to mainSeptember 3, 2026 16:37
simonrozsivaland others added 3 commits September 3, 2026 18:37
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival
simonrozsivalforce-pushed the simonrozsival-trimmable-typemap-jni-rewriting branch from 3eeeaaa to 351afd5CompareSeptember 3, 2026 16:37
@simonrozsivalsimonrozsival removed the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Sep 3, 2026
Validate string-array custom attribute prologs and decode their element count explicitly as little-endian. Rename the test IL token reader to reflect that it handles both method and field tokens.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsivalsimonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Sep 4, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-reviewThis PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@simonrozsival@rolfbjarne