Skip to content

[NativeAOT] Narrow automatic unmanaged entry-point discovery. Fixes #18484 - #27207

Open
rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/narrow-nativeaot-entrypoints
Open

rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/narrow-nativeaot-entrypoints

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Instead of asking NativeAOT to discover named UnmanagedCallersOnly entry 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 UnmanagedEntryPointsAssembly items.

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

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
Copilot AI balanced review requested due to automatic review settings October 30, 2026 11:03
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner October 30, 2026 11:03

Copilot AI 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.

🟡 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"" />
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 2eeb9c9b2c35b4f9ebf5ef954a7918a2ec649c27 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [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

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.RegistrarTest.NativeAotEntryPointAssemblies("manag...: '/Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-12.0.100-alpha.1.26523.103/dotnet' failed with exit code 1
      Fu...
    • Xamarin.Tests.RegistrarTest.NativeAotEntryPointAssemblies("manag...: '/Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-12.0.100-alpha.1.26523.103/dotnet' failed with exit code 1
      Fu...
    • Xamarin.Tests.RegistrarTest.NativeAotEntryPointAssemblies("trimm...: '/Users/cloudtest/vss/_work/1/s/macios/builds/downloads/dotnet-sdk-12.0.100-alpha.1.26523.103/dotnet' failed with exit code 1
      Fu...
    • ... and 1 more

Html Report (VSDrops) Download

❌ Tests on macOS Sonoma (14) tests

1 tests failed, 4 tests passed.

Failed tests

  • MacCatalyst/maccatalyst-x64 monotouch-test: Failed (exit code 1)
    • [FAIL] PerformAsynchronousFileAccess_Null : System.UnauthorizedAccessException : Access to the path '/Users/builder/Documents/mydocument.txt' is denied.
    • [FAIL] Save : System.UnauthorizedAccessException : Access to the path '/Users/builder/Documents/mydocument.txt' is denied.

Html Report (VSDrops) Download

❌ Tests on macOS Sequoia (15) tests

1 tests failed, 4 tests passed.

Failed tests

  • MacCatalyst/maccatalyst-x64 monotouch-test: Failed (exit code 137)
    • No test failure details available. Output tail:
      • at MonoTouch.NUnit.UI.BaseTouchRunner.Run(NUnit.Framework.Internal.Test)
      • at MonoTouch.NUnit.UI.BaseTouchRunner.Run()
      • at MonoTouch.NUnit.UI.BaseTouchRunner.<AutoRun>b__49_0()
      • at MonoTouch.NUnit.UI.TouchRunner+<>c__DisplayClass19_0.<ExecuteOnMainThread>b__0()
      • at Foundation.NSAsyncActionDispatcher.Apply()
      • at __Registrar_Callbacks__.callback_3037_Foundation_NSAsyncActionDispatcher_Apply(IntPtr, IntPtr, IntPtr*)
      • at UIKit.UIApplication.UIApplicationMain(Int32, System.String[], IntPtr, IntPtr)
      • at UIKit.UIApplication.Main(System.String[], System.Type, System.Type)
      • at MainClass.Main(System.String[])
      • Execution completed with exit code 137
  • MacCatalyst/maccatalyst-arm64 monotouch-test: Failed (exit code 137)
    • No test failure details available. Output tail:
      • at MonoTouch.NUnit.UI.BaseTouchRunner.Run(NUnit.Framework.Internal.Test)
      • at MonoTouch.NUnit.UI.BaseTouchRunner.Run()
      • at MonoTouch.NUnit.UI.BaseTouchRunner.<AutoRun>b__49_0()
      • at MonoTouch.NUnit.UI.TouchRunner+<>c__DisplayClass19_0.<ExecuteOnMainThread>b__0()
      • at Foundation.NSAsyncActionDispatcher.Apply()
      • at __Registrar_Callbacks__.callback_3037_Foundation_NSAsyncActionDispatcher_Apply(IntPtr, IntPtr, IntPtr*)
      • at UIKit.UIApplication.UIApplicationMain(Int32, System.String[], IntPtr, IntPtr)
      • at UIKit.UIApplication.Main(System.String[], System.Type, System.Type)
      • at MainClass.Main(System.String[])
      • Execution completed with exit code 137

Html Report (VSDrops) Download

Successes

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 1 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 21 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Golden Gate (27): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: 2eeb9c9b2c35b4f9ebf5ef954a7918a2ec649c27 [PR build]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NativeAOT: Investigate whether we can narrow down the list of assemblies to look for UnmanagedCallersOnly entry points

3 participants