Skip to content

[dotnet-linker] Set AssociatedSourceType on UnmanagedCallersOnly trampolines#25915

Draft
rolfbjarne wants to merge 1 commit into
net11.0from
dev/rolf/unmanagedcallersonly-associatedsourcetype
Draft

[dotnet-linker] Set AssociatedSourceType on UnmanagedCallersOnly trampolines#25915
rolfbjarne wants to merge 1 commit into
net11.0from
dev/rolf/unmanagedcallersonly-associatedsourcetype

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Set the AssociatedSourceType property on UnmanagedCallersOnly attributes
generated by the managed registrar step. This tells the trimmer/NativeAOT
that the trampoline entry point is only needed if the associated type
(the NSObject subclass declaring the exported method) is kept in the app.

This reduces app size in NativeAOT scenarios by avoiding unnecessary
native exports for trimmed types.

Fixes #25631

…polines

Set the AssociatedSourceType property on UnmanagedCallersOnly attributes
generated by the managed registrar step. This tells the trimmer/NativeAOT
that the trampoline entry point is only needed if the associated type
(the NSObject subclass declaring the exported method) is kept in the app.

This reduces app size in NativeAOT scenarios by avoiding unnecessary
native exports for trimmed types.

Fixes #25631

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 2, 2026 18:09
@rolfbjarne rolfbjarne added copilot do-not-merge Do not merge this pull request labels Jul 2, 2026
@rolfbjarne

rolfbjarne commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

It would be nice to wait until we get #25910 working so that we can get size diffs for this PR (thus do-not-merge)

@rolfbjarne rolfbjarne marked this pull request as draft July 2, 2026 18:10
@rolfbjarne rolfbjarne linked an issue Jul 2, 2026 that may be closed by this pull request

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 updates the managed registrar’s generated UnmanagedCallersOnly trampolines to set AssociatedSourceType, so NativeAOT/trimming can elide entry points when the corresponding NSObject subclass is trimmed, reducing app size.

Changes:

  • Pass the exported method’s declaring type into CreateUnmanagedCallersAttribute.
  • Emit an AssociatedSourceType named argument on generated UnmanagedCallersOnlyAttribute instances.

Comment on lines +1245 to 1252
CustomAttribute CreateUnmanagedCallersAttribute (string entryPoint, TypeReference? associatedSourceType = null)
{
var unmanagedCallersAttribute = new CustomAttribute (abr.UnmanagedCallersOnlyAttribute_Constructor);
unmanagedCallersAttribute.Fields.Add (new CustomAttributeNamedArgument ("EntryPoint", new CustomAttributeArgument (abr.System_String, entryPoint)));
if (associatedSourceType is not null)
unmanagedCallersAttribute.Fields.Add (new CustomAttributeNamedArgument ("AssociatedSourceType", new CustomAttributeArgument (abr.System_Type, associatedSourceType)));
return unmanagedCallersAttribute;
}
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #a4797cf] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: a4797cf6862fd4d21a436d49426960dc5f610406 [PR build]

@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: a4797cf6862fd4d21a436d49426960dc5f610406 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #a4797cf] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: a4797cf6862fd4d21a436d49426960dc5f610406 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #a4797cf] Build passed (Build packages) ✅

Pipeline on Agent
Hash: a4797cf6862fd4d21a436d49426960dc5f610406 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #a4797cf] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 49 tests failed, 159 tests passed.

Failures

❌ linker tests (iOS)

4 tests failed, 17 tests passed.

Failed tests

  • dont link/iOS - simulator/Debug (PrepareAssemblies, CoreCLR, Managed Static Registrar): Crashed
  • dont link/iOS - simulator/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Crashed
  • link sdk/iOS - simulator/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Crashed
  • link all/iOS - simulator/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Crashed

Html Report (VSDrops) Download

❌ linker tests (MacCatalyst)

4 tests failed, 17 tests passed.

Failed tests

  • dont link/Mac Catalyst/Debug (PrepareAssemblies, CoreCLR, Managed Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • dont link/Mac Catalyst/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • link sdk/Mac Catalyst/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • link all/Mac Catalyst/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)

Html Report (VSDrops) Download

❌ linker tests (macOS)

13 tests failed, 8 tests passed.

Failed tests

  • dont link/macOS/Debug (PrepareAssemblies, CoreCLR, Managed Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • dont link/macOS/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • dont link/macOS/Release: Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • dont link/macOS/Release (PrepareAssemblies, CoreCLR, Managed Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • dont link/macOS/Release (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • link sdk/macOS/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • link sdk/macOS/Release: Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • link sdk/macOS/Release (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • link all/macOS/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • link all/macOS/Release: Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • link all/macOS/Release (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • trimmode copy/macOS/Release: Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • trimmode link/macOS/Release: Failed (Test run crashed (exit code: 134).
    No test log file was produced)

Html Report (VSDrops) Download

❌ linker tests (tvOS)

4 tests failed, 17 tests passed.

Failed tests

  • dont link/tvOS - simulator/Debug (PrepareAssemblies, CoreCLR, Managed Static Registrar): Crashed
  • dont link/tvOS - simulator/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Crashed
  • link sdk/tvOS - simulator/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Crashed
  • link all/tvOS - simulator/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Crashed

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

4 tests failed, 14 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Release (trimmable static registrar, NativeAOT): BuildFailure
  • monotouch-test/iOS - simulator/Debug (managed static registrar): Crashed
  • monotouch-test/iOS - simulator/Debug (trimmable static registrar): Crashed
  • monotouch-test/iOS - simulator/Release (trimmable static registrar, all optimizations): Crashed

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst)

5 tests failed, 13 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug (managed static registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/Mac Catalyst/Debug (trimmable static registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/Mac Catalyst/Release (trimmable static registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/Mac Catalyst/Release (trimmable static registrar, all optimizations): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/Mac Catalyst/Release (trimmable static registrar, NativeAOT): BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))

Html Report (VSDrops) Download

❌ monotouch tests (macOS)

10 tests failed, 8 tests passed.

Failed tests

  • monotouch-test/macOS/Release (link sdk): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Release (link all): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Debug (managed static registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Debug (trimmable static registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Release (managed static registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Release (trimmable static registrar): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Release (managed static registrar, all optimizations): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Release (trimmable static registrar, all optimizations): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Release (compat inline dlfcn): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/macOS/Release (strict inline dlfcn, link sdk): Failed (Test run crashed (exit code: 134).
    No test log file was produced)

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

4 tests failed, 14 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Release (trimmable static registrar, NativeAOT): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (managed static registrar): Crashed
  • monotouch-test/tvOS - simulator/Debug (trimmable static registrar): Crashed
  • monotouch-test/tvOS - simulator/Release (trimmable static registrar, all optimizations): Crashed

Html Report (VSDrops) Download

❌ Tests on macOS Sequoia (15) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-arm64 monotouch-test: Failed (exit code 1)
    • [FAIL] AcceptSslCertificatesServicePointManager(System.Net.Http.HttpClientHandler) : Assert.That(ex, Is.Null)

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 (iOS): 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 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
✅ 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 Sonoma (14): 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: a4797cf6862fd4d21a436d49426960dc5f610406 [PR build]

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

Labels

copilot do-not-merge Do not merge this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start using UnmanagedCallersOnlyAttribute.AssociatedSourceType

3 participants