Skip to content

[dotnet-linker] Only override NSObjectProxyAttribute.LookupUnmanagedFunction when the type actually has any UnmanagedCallersOnly methods to look up. - #26364

Open
rolfbjarne wants to merge 1 commit into
dev/rolf/trimmable-registrar-no-param-namesfrom
dev/rolf/default-lookupunmanaged-impl
Open

[dotnet-linker] Only override NSObjectProxyAttribute.LookupUnmanagedFunction when the type actually has any UnmanagedCallersOnly methods to look up.#26364
rolfbjarne wants to merge 1 commit into
dev/rolf/trimmable-registrar-no-param-namesfrom
dev/rolf/default-lookupunmanaged-impl

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Only override NSObjectProxyAttribute.LookupUnmanagedFunction when the type actually has any UnmanagedCallersOnly methods to look up. The method is now virtual instead of abstract, and the base implementation returns IntPtr.Zero, which is exactly what the generated override did for types without any such methods.

Copilot-Session: 6aeeddfd-3bd8-4129-ad90-7292860c4b66

…Function` when the type actually has any `UnmanagedCallersOnly` methods to look up.

Only override `NSObjectProxyAttribute.LookupUnmanagedFunction` when the type actually has any `UnmanagedCallersOnly` methods to look up. The method is now virtual instead of abstract, and the base implementation returns `IntPtr.Zero`, which is exactly what the generated override did for types without any such methods.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6aeeddfd-3bd8-4129-ad90-7292860c4b66
Copilot AI review requested due to automatic review settings July 30, 2026 10:20

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.

Pull request overview

This PR reduces the size of trimmable static registrar type map assemblies by only emitting NSObjectProxyAttribute.LookupUnmanagedFunction overrides for proxy types that actually need to resolve any UnmanagedCallersOnly trampolines. It does this by making LookupUnmanagedFunction virtual with a default IntPtr.Zero implementation, and then skipping override emission when there are no entry points to look up.

Changes:

  • Make NSObjectProxyAttribute.LookupUnmanagedFunction virtual with a default implementation returning IntPtr.Zero.
  • Update the trimmable registrar step to only generate LookupUnmanagedFunction when there are any UnmanagedCallersOnly entry points for the proxied type.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tools/dotnet-linker/Steps/TrimmableRegistrarStep.cs Only emits a LookupUnmanagedFunction override when UnmanagedCallersOnly trampolines exist for the proxy type.
src/ObjCRuntime/TypeMaps.cs Changes LookupUnmanagedFunction from abstract to virtual, with a default IntPtr.Zero implementation to support skipping overrides.

@@ -485,30 +485,31 @@ void addPostAction (AssemblyDefinition assembly, Action<AssemblyDefinition> acti
}

var ucos = uco.OrderBy (v => v.UnmanagedCallersOnlyEntryPoint).ToList ();
@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: d76b78b4819bcdd3154fc7d68397709d8a550241 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #d76b78b] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 6 tests failed, 197 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.AppSizeTest.NativeAOT_TrimmableStatic(iOS,"ios-arm...: App size changed significantly (-49,448 bytes (-48.3 KB = -0.0 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB)). ...

Html Report (VSDrops) Download

❌ dotnettests tests (MacCatalyst)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppSizeTest.NativeAOT_TrimmableStatic(MacCatalyst,...: App size changed significantly (-49,824 bytes (-48.7 KB = -0.0 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB)). ...

Html Report (VSDrops) Download

❌ dotnettests tests (macOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppSizeTest.CoreCLR_Interpreter_TrimmableStatic(Ma...: App size changed significantly (-833,409 bytes (-813.9 KB = -0.8 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB))...
    • Xamarin.Tests.AppSizeTest.CoreCLR_Interpreter(MacOSX,"osx-arm64;...: App size changed significantly (-441,233 bytes (-430.9 KB = -0.4 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB))...
    • Xamarin.Tests.AppSizeTest.NativeAOT_TrimmableStatic(MacOSX,"osx-...: App size changed significantly (-82,423 bytes (-80.5 KB = -0.1 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB)). ...

Html Report (VSDrops) Download

❌ dotnettests tests (tvOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.AppSizeTest.NativeAOT_TrimmableStatic(TVOS,"tvos-a...: App size changed significantly (-32,975 bytes (-32.2 KB = -0.0 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB)). ...
    • Xamarin.Tests.AppSizeTest.NativeAOT(TVOS,"tvos-arm64"): App size changed significantly (-16,407 bytes (-16.0 KB = -0.0 MB) different > tolerance of +-10,240 bytes (10.0 KB = 0.0 MB)). ...

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst)

1 tests failed, 17 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Release (link all): Failed (Test run failed.
    Tests run: 3786 Passed: 3601 Inconclusive: 19 Failed: 1 Ignored: 184)

Html Report (VSDrops) Download

❌ monotouch tests (macOS)

1 tests failed, 18 tests passed.

Failed tests

  • monotouch-test/macOS/Release (NativeAOT): TimedOut (Execution timed out after 1200 seconds.
    Test run crashed)

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 (Multiple platforms): 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 5 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 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 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 Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: d76b78b4819bcdd3154fc7d68397709d8a550241 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

⚠️ AppSizeTest expected files changed ⚠️

The AppSizeTest detected changes in the expected app size files.

To update the expected files, add a comment with the following command:

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/6957d959a45ca8593060ebf74f17b36c
Updated files
  • iOS-NativeAOT-TrimmableStatic-size.txt
  • MacCatalyst-NativeAOT-TrimmableStatic-size.txt
  • MacOSX-CoreCLR-Interpreter-size.txt
  • MacOSX-CoreCLR-Interpreter-TrimmableStatic-size.txt
  • MacOSX-NativeAOT-TrimmableStatic-size.txt
  • TVOS-NativeAOT-size.txt
  • TVOS-NativeAOT-TrimmableStatic-size.txt

Pipeline on Agent
Hash: d76b78b4819bcdd3154fc7d68397709d8a550241 [PR build]

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.

3 participants