Repository navigation
[NativeAOT] Narrow automatic unmanaged entry-point discovery. Fixes #18484 - #27207
rolfbjarne wants to merge 2 commits into
Conversation
Record the assemblies containing generated registrar trampolines and pass only surviving callback assemblies to NativeAOT, alongside the platform assembly required for runtime exports. Use the trampoline module to account for callbacks relocated into companion assemblies, instead of scanning every application dependency. Persist the registrar assembly list across incremental builds, track it as a preparation output and FileWrites item, and preserve explicitly configured UnmanagedEntryPointsAssembly items. Add focused registrar and MSBuild regression coverage and document how libraries opt into named native exports. Fixes #18484. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 8565f47b-0cbe-4c7e-8fa6-0069840f42e9
Include surviving user assemblies in the persisted entry-point assembly list even when the registrar generates no callbacks for them. User libraries can contain hand-written UnmanagedCallersOnly exports, so requiring explicit opt-in would break existing applications. Continue to exclude unrelated SDK/framework assemblies while retaining the platform assembly and relocated registrar callbacks. Extend regression coverage to user libraries without registrar callbacks, deleted user assemblies, SDK assemblies, and repeated MSBuild invocations. Correct the build-item documentation to describe automatic user-assembly discovery. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 8565f47b-0cbe-4c7e-8fa6-0069840f42e9
There was a problem hiding this comment.
🟡 Changes recommended
The tests explicitly select Microsoft.iOS, so they would still pass if automatic platform-assembly inclusion were removed, leaving that behavior unverified.
1 open issue
What changed in this PR
This PR narrows NativeAOT entry-point discovery to user assemblies, the platform assembly, and assemblies containing generated registrar callbacks, addressing #18484 while preserving explicit selections.
Changes:
- Persist a deterministic, deduplicated assembly list that includes relocated callbacks.
- Filter automatic selections against trimmed output and track the list for incremental builds and cleanup.
- Document selection behavior and add registrar and MSBuild regression tests.
| File | Description |
|---|---|
| tools/dotnet-linker/Steps/ManagedRegistrarStep.cs | Persist user and callback assembly selections. |
| tests/dotnet/UnitTests/RegistrarTest.cs | Test filtering, explicit selections, and repeated invocations. |
| tests/assembly-preparer/ManagedRegistrarStepTests.cs | Test list generation, callback relocation, and exclusions. |
| msbuild/Xamarin.Shared/Xamarin.Shared.targets | Track the persisted list as an output and cleanable file. |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Apply narrowed selections before NativeAOT compilation. |
| docs/building-apps/build-items.md | Document UnmanagedEntryPointsAssembly behavior. |
Review effort: Balanced
| <Target Name=""Restore"" /> | ||
| <ItemGroup> | ||
| <ManagedAssemblyToLink Include=""{string.Join (";", assemblies.Select (v => Path.Combine (directory, "original", v + ".dll")))};original/TrimmedCallbacks.dll;original/TrimmedUserLibrary.dll"" /> | ||
| <UnmanagedEntryPointsAssembly Include=""MyApp;ExplicitLibrary;Microsoft.iOS"" /> |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [CI Build #2eeb9c9] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 3 tests failed, 214 tests passed. Failures❌ dotnettests tests (iOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Sonoma (14) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Sequoia (15) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |

Instead of asking NativeAOT to discover named
UnmanagedCallersOnlyentry points in every assembly, limit automatic discovery to user assemblies, the platform assembly, and assemblies containing generated registrar callbacks. This avoids unnecessarily exporting entry points from unrelated SDK/framework assemblies and reduces the risk of native symbol conflicts.The registrar persists a deterministic, deduplicated assembly list, using each trampoline's actual assembly so relocated callbacks in companion assemblies are included. Before invoking NativeAOT, intersect that list with assemblies that survived trimming and retain explicitly configured
UnmanagedEntryPointsAssemblyitems.User assemblies remain included even when they contain no registrar callbacks, preserving existing hand-written native exports. Track the persisted list as a preparation output and cleanable file so incremental builds can restore it, and document the resulting build-item behavior.
Add regression coverage for user libraries without callbacks, both registrar modes, relocated callbacks, excluded SDK assemblies, deleted/trimmed assemblies, explicit selections, and repeated MSBuild invocations.
Fixes #18484
Note
This description and the changes were generated with GitHub Copilot.
🤖 Pull request created by Copilot