Skip to content

[ObjCRuntime] Allow native dynamic registrar removal. Fixes #16668#26219

Merged
rolfbjarne merged 8 commits into
mainfrom
dev/rolf/issue-16668-dynamic-registrar-native-code
Jul 23, 2026
Merged

[ObjCRuntime] Allow native dynamic registrar removal. Fixes #16668#26219
rolfbjarne merged 8 commits into
mainfrom
dev/rolf/issue-16668-dynamic-registrar-native-code

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Initialize the native trampoline table from generated startup code only when dynamic registration support is enabled, so the native linker can dead-strip it otherwise.

Verify the linked trampoline symbol follows DynamicRegistrationSupported.

Fixes #16668

🤖 Pull request created by Copilot

Initialize the native trampoline table from generated startup code only when dynamic registration support is enabled, so the native linker can dead-strip it otherwise.

Verify the linked trampoline symbol follows DynamicRegistrationSupported.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 436154f1-6cca-4e7e-bd3e-199087275dcf
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@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/717a6a4b43800834a40cd9ee0cbfd862
Updated files
  • iOS-MonoVM-size.txt
  • iOS-NativeAOT-size.txt
  • iOS-NativeAOT-TrimmableStatic-size.txt
  • MacCatalyst-MonoVM-size.txt
  • MacCatalyst-NativeAOT-size.txt
  • MacCatalyst-NativeAOT-TrimmableStatic-size.txt
  • MacOSX-NativeAOT-size.txt
  • MacOSX-NativeAOT-TrimmableStatic-size.txt
  • TVOS-MonoVM-size.txt
  • TVOS-NativeAOT-size.txt
  • TVOS-NativeAOT-TrimmableStatic-size.txt

Pipeline on Agent
Hash: d031bb1d630ccf983f06e96ac8d50480e16cfa3c [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne

Copy link
Copy Markdown
Member Author

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/717a6a4b43800834a40cd9ee0cbfd862

@github-actions

Copy link
Copy Markdown
Contributor

✅ Applied expected app size files from gist.

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

Updates the native runtime initialization path so the dynamic registrar’s trampoline table is only referenced/initialized when dynamic registration support is enabled, allowing the native linker to dead-strip the dynamic-registrar native code when it’s disabled (fixing #16668).

Changes:

  • Emit a call to xamarin_initialize_dynamic_registrar () from generated startup code only when DynamicRegistrationSupported is enabled (and not for NativeAOT).
  • Move options.Trampolines = &trampolines; out of xamarin_initialize () into the new xamarin_initialize_dynamic_registrar () entry point.
  • Add a unit test that validates _xamarin_invoke_trampoline is present/absent based on DynamicRegistrationSupported, and update size baselines accordingly.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/common/Target.cs Generated startup code now conditionally calls xamarin_initialize_dynamic_registrar () and sets xamarin_supports_dynamic_registration only for non-NativeAOT.
runtime/xamarin/runtime.h Declares xamarin_initialize_dynamic_registrar () for generated code to call.
runtime/runtime.m Introduces xamarin_initialize_dynamic_registrar () and removes unconditional trampoline-table wiring from xamarin_initialize ().
tests/dotnet/UnitTests/DynamicRegistrationSupportedTest.cs Adds symbol-level verification (nm) that _xamarin_invoke_trampoline matches the feature switch.
tests/dotnet/UnitTests/expected/*-size.txt Updates size baselines reflecting dead-stripping improvements across platforms/configurations.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 4 commits July 22, 2026 12:28
The UserSpecifiedValue test verifies that the dynamic registrar's native
trampoline symbol ('_xamarin_invoke_trampoline') is linked into the main
executable when '$(DynamicRegistrationSupported)' is true and dead-stripped
when it's false.

On a simulator build, '$(_LibXamarinLinkMode)' defaults to 'dylib', so
libxamarin is a dynamic library that always contains the trampoline symbol,
and the main executable never does - so the 'nm -j <mainExecutable>' check
could never observe the presence of the symbol, failing the true case.

Force '$(_LibXamarinLinkMode)=static' so libxamarin is linked into the main
executable and the native linker's dead-stripping becomes observable there.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne marked this pull request as ready for review July 22, 2026 18:00
@vs-mobiletools-engineering-service2

This comment has been minimized.

dalexsoto
dalexsoto previously approved these changes Jul 22, 2026
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

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

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne enabled auto-merge (squash) July 23, 2026 16:23
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #e37d4cb] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 203 tests passed 🎉

Tests counts

✅ 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. [attempt 2] 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 (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): 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: e37d4cbbbbcc9909b3e6e7ceb237722f5cfa98f1 [PR build]

@rolfbjarne
rolfbjarne merged commit 38a0d8e into main Jul 23, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/issue-16668-dynamic-registrar-native-code branch July 23, 2026 17:17
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.

Make it possible to remove the native code for the dynamic registrar

4 participants