Skip to content

[release/11.0.1xx] [build] Avoid registrar compilation for MVID-only edits. Fixes #26728 - #26824

Merged
rolfbjarne merged 4 commits into
release/11.0.1xxfrom
dev/rolf/backport-pr-26747-release/11.0.1xx-2026-10-02
Oct 3, 2026
Merged

rolfbjarne merged 4 commits into
release/11.0.1xxfrom
dev/rolf/backport-pr-26747-release/11.0.1xx-2026-10-02

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Summary

An app-only IL edit changes its assembly MVID without changing registration metadata. Previously, embedding that MVID in registrar.mm caused Clang to recompile the entire large Objective-C++ registrar source.

  • Keep registrar.mm stable across MVID-only edits and emit the ordered assembly-name/MVID table directly as registrar-assemblies.o for arm64 and x86_64. The object contains the exported registration symbol, pointer relocations, and platform-specific Mach-O build-version metadata.
  • Pass the generated object to the native linker without compiling a separate assembly-table source. Other architectures retain the Objective-C++ fallback. Changes to registered methods still rebuild registrar.mm.
  • Track the object for incremental linking and clean, and cover MVID updates, native registration, binary layout, and clean with regression tests.

Performance

For the same 193-assembly table, 30 warm scratch-prototype runs took a median of 168 ms to compile with Clang versus 41 ms to emit directly from a Node process. Production writes the object in-process; these numbers are not an end-to-end app-build measurement. Native relinking is still required.

Fixes #26728


Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Backport of #26747.

rolfbjarne and others added 4 commits October 2, 2026 18:47
The CoreCLR trimmable static registrar previously embedded every registered assembly MVID in registrar.mm. An app-only IL edit therefore changed the large Objective-C++ file and made Clang recompile it even when all registration metadata was stable.

Emit the assembly table in a small registrar-assemblies.mm translation unit with an external C symbol, and include both sources and their object files in incremental build and clean tracking. Cover two real managed edits, the linked MVID, reuse of the large registrar object, a registered-method change, and Mac Catalyst runtime registration in an integration test; document the generated layout.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
For CoreCLR trimmable-static builds targeting arm64 or x86_64, write
assembly names and MVIDs into a relocatable Mach-O object with the
exported registration symbol and section-relative pointer relocations.
This eliminates the separate Objective-C++ compilation on MVID-only
edits while preserving native relinking and the source-based fallback
for other architectures.

Pass the generated object directly to the native linker, track it for
incremental linking and clean, and cover the binary layout and iOS and
Mac Catalyst registration behavior with regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 35b7dbf0-b000-4ac5-9769-8fe0f272f9e9
Mac Catalyst records an iOS-style SDK version in its Mach-O build-version
command, which can differ from the underlying macOS SDK version. Pass the
converted SDK version already held by Application so emitted objects keep
matching the platform metadata produced by Clang.

Exercise a real dotnet clean in the incremental registrar test instead of
the test helper that deletes bin and obj directories directly. This
checks that the generated assembly object is removed by the build system.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 35b7dbf0-b000-4ac5-9769-8fe0f272f9e9
Copilot AI balanced review requested due to automatic review settings October 2, 2026 16:47
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner October 2, 2026 16:47
@rolfbjarne rolfbjarne added backported ready-to-review This PR is ready to review/merge. labels Oct 2, 2026

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.

Copilot review overview

🟢 Approval recommended

The implementation is consistent with the linker pipeline and includes focused binary-layout, runtime, incremental-build, and cleanup coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Optimizes CoreCLR trimmable-static registrar builds by separating volatile assembly MVID data from registrar.mm.

Changes:

  • Emits arm64/x86_64 assembly tables directly as Mach-O objects.
  • Updates incremental compilation, linking, and cleanup.
  • Adds layout, runtime, and incremental regression tests.
File Description
tools/​mtouch/​mtouch.csproj Includes the object writer.
tools/​dotnet-linker/​Steps/​RegistrarStep.cs Selects object or source emission.
tools/​dotnet-linker/​dotnet-linker.csproj Includes the object writer.
tools/​common/​StaticRegistrar.cs Separates MVID data from registrar code.
tools/​common/​RegistrarAssembliesObjectWriter.cs Generates relocatable Mach-O objects.
tools/​common/​MachO.cs Adds required Mach-O constants.
tools/​assembly-preparer/​assembly-preparer.csproj Includes the object writer.
tests/​dotnet/​UnitTests/​RegistrarTest.cs Tests incremental and runtime behavior.
tests/​dotnet/​UnitTests/​RegistrarAssembliesObjectWriterTest.cs Validates emitted object layout.
tests/​dotnet/​UnitTests/​DotNetUnitTests.csproj Includes writer tests.
dotnet/​targets/​Xamarin.Shared.Sdk.targets Tracks, links, and cleans generated objects.
docs/​managed-static-registrar.md Documents the optimized flow.

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

@rolfbjarne
rolfbjarne enabled auto-merge (squash) October 2, 2026 17:48
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #45792c5] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 269 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 7 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 25 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 Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ 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: 45792c558e933e4b52f7bf655b6ac5b2c81cc4af [PR build]

@rolfbjarne
rolfbjarne merged commit d29473a into release/11.0.1xx Oct 3, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/backport-pr-26747-release/11.0.1xx-2026-10-02 branch October 3, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants