Repository navigation
Fix typemap proxy metadata field ownership - #12497
Conversation
Make ordinary Java peers conditional on managed reachability while preserving explicit external Java roots. Emit UTF-8 registration fields before proxy types so metadata field ownership cannot create accidental proxy-to-proxy linker dependencies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a6de09d8-fc09-4560-a976-ffcccd21ba70
There was a problem hiding this comment.
Pull request overview
This PR fixes a trimmable typemap codegen/rooting issue that could accidentally retain proxy types and their managed implementors during trimming, and expands rooting to correctly preserve external Java roots (including XML-only custom views).
Changes:
- Updates scanner/model rules so ordinary ACW peers are conditional on managed reachability unless explicitly rooted (attributes, manifests, custom views).
- Fixes typemap assembly emission by preparing and emitting deduplicated UTF-8 RVA fields on dedicated
__utf8_*helper types before proxyTypeDefrows are emitted. - Adds/updates test coverage, including new build-level CoreCLR trimming tests for used/unused binding listener implementors and external Java roots.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Scanner/JavaPeerScannerTests.cs | Updates scanner assertions around unconditional rooting rules. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapModelBuilderTests.cs | Adjusts model expectations for conditional vs unconditional entries. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapAssemblyGeneratorTests.cs | Adds validation that RVA fields are declared on __utf8_* helper types. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TrimmableTypeMapGeneratorTests.cs | Adds unit coverage for rooting only custom-view referenced managed types. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs | Adds end-to-end CoreCLR trimming tests and helpers to verify retention/trim behavior. |
| src/Xamarin.Android.Build.Tasks/Tasks/GenerateTrimmableTypeMap.cs | Plumbs custom view map inputs into typemap generation. |
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.targets | Adds custom view map to incremental inputs and passes it to the generation task. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs | Adds custom-view rooting step prior to manifest-based rooting. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs | Refines unconditional rooting logic (framework vs non-framework + JNI signature roots). |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs | Prepares UTF-8 fields up-front instead of interleaving with proxy emission. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/PEAssemblyBuilder.cs | Implements grouped preparation for contiguous UTF-8 RVA field emission. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ModelBuilder.cs | Removes unconditional default for user ACW types so reachability governs unless explicitly rooted. |
Review details
- Files reviewed: 12/12 changed files
- Comments generated: 2
- Review effort level: Lite
Move the independent conditional ACW and external Java root changes to a separate pull request. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a6de09d8-fc09-4560-a976-ffcccd21ba70
Reuse the encoded size collected while grouping registration strings when allocating their RVA data. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a6de09d8-fc09-4560-a976-ffcccd21ba70
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ LGTM
Findings: 0 errors · 0 warnings · 1 suggestion
The eager, size-grouped emission preserves contiguous ECMA-335 field ownership before proxy TypeDef rows are created, while retaining UTF-8 deduplication. The regression assertion directly verifies that RVA fields resolve to the intended __utf8_* declaring types. All 44 CI checks passed.
Generated by Android PR Reviewer for #12497 · gpt56 · 186 AIC · ⌖ 19 AIC · ⊞ 25.7K
Comment /review to run again
Rename the lookup API now that UTF-8 fields must be prepared before proxy emission. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a6de09d8-fc09-4560-a976-ffcccd21ba70
## Summary - make ordinary Java peers conditional on managed reachability instead of preserving every ACW - preserve explicit external Java roots from component and JNI-provider attributes - preserve peers referenced by the manifest and custom views instantiated from Android XML resources - add standalone and trimmed CoreCLR build coverage for used/unused binding listener implementors and XML-only custom views ## Why custom views are part of this change Removing the blanket unconditional ACW rule allows ILLink to trim ordinary Java peers. Types instantiated externally by Android still need explicit roots even when managed code does not reference them. Custom views used only in layout XML are one such root, so the custom-view map is consumed by the typemap generator before trimming. ## Dependency Stacked on #12497 so the trimmed integration coverage runs with correct UTF-8 metadata field ownership. The diff in this PR contains only conditionality and external-root behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Summary
__utf8_*helper typeRoot cause
UTF-8 RVA fields and proxy
TypeDefrows were emitted interleaved. ECMA-335 represents field ownership using contiguousTypeDef.FieldListranges, so fields emitted after another proxy type could become owned by that proxy even though they were intended for<PrivateImplementationDetails>.When a live proxy referenced a shared registration field, ILLink correctly marked the field's accidental declaring proxy, its constructor, and its managed listener implementor. This caused unrelated framework implementors to survive trimming.
The emitter now prepares all registration strings and emits their fields contiguously on dedicated
__utf8_*helper types before emitting any proxy type. Typemap attributes, conditionality, associations, proxy APIs, and UTF-8 string deduplication remain unchanged.Testing
Microsoft.Android.Sdk.TrimmableTypeMap.Tests: 800 passed