Skip to content

Support multiple R2R images for ios/tvos apps#25072

Closed
jkoritzinsky wants to merge 1 commit intodotnet:net11.0from
jkoritzinsky:dev/jekoritz/r2r-multiple-images
Closed

Support multiple R2R images for ios/tvos apps#25072
jkoritzinsky wants to merge 1 commit intodotnet:net11.0from
jkoritzinsky:dev/jekoritz/r2r-multiple-images

Conversation

@jkoritzinsky
Copy link
Copy Markdown
Member

@jkoritzinsky jkoritzinsky commented Apr 2, 2026

Note

This PR was generated with the help of GitHub Copilot.

Instead of linking all R2R .o files into a single large dylib/framework, create a separate framework (or dylib) for each R2R .o file. This way, when only one R2R input changes, only that module's framework needs to be relinked — significantly improving incremental build times.

Each R2R .o file exports an RTR_HEADER symbol. To avoid collisions when multiple modules are loaded, each module's dylib uses the linker flags -Wl,-alias,_RTR_HEADER,_RTR_HEADER_<module> and -Wl,-unexported_symbol,_RTR_HEADER to export a uniquely-named alias.

A new MSBuild task (GenerateR2RModuleRegistration) generates a native registration file (r2r_modules.mm) that maps module names to their header pointers. The file is compiled into the main executable and uses __attribute__((constructor)) to register the modules before main().

The runtime's xamarin_get_native_code_data callback now iterates the module table to find the correct R2R header for each owner_composite_name, with a fallback to the single xamarin_rtr_header for backward compat.

Changes:

  • runtime/xamarin/main.h: Add struct xamarin_r2r_module and externs
  • runtime/runtime.m: Multi-module lookup in get_native_code_data
  • tools/common/Target.cs: Remove single RTR_HEADER from generated main.mm
  • msbuild/.../GenerateR2RModuleRegistration.cs: New task
  • dotnet/targets/Microsoft.Sdk.R2R.targets: Per-module framework/dylib creation with symbol renaming
  • dotnet/targets/Xamarin.Shared.Sdk.targets: Handle multiple R2R frameworks in post-processing

Contributes to dotnet/runtime#126194

Instead of linking all R2R .o files into a single large dylib/framework,
create a separate framework (or dylib) for each R2R .o file. This way,
when only one R2R input changes, only that module's framework needs to
be relinked — significantly improving incremental build times.

Each R2R .o file exports an RTR_HEADER symbol.  To avoid collisions when
multiple modules are loaded, each module's dylib uses the linker flags
-Wl,-alias,_RTR_HEADER,_RTR_HEADER_<module> and
-Wl,-unexported_symbol,_RTR_HEADER to export a uniquely-named alias.

A new MSBuild task (GenerateR2RModuleRegistration) generates a native
registration file (r2r_modules.mm) that maps module names to their
header pointers.  The file is compiled into the main executable and
uses __attribute__((constructor)) to register the modules before main().

The runtime's xamarin_get_native_code_data callback now iterates the
module table to find the correct R2R header for each owner_composite_name,
with a fallback to the single xamarin_rtr_header for backward compat.

Changes:
- runtime/xamarin/main.h: Add struct xamarin_r2r_module and externs
- runtime/runtime.m: Multi-module lookup in get_native_code_data
- tools/common/Target.cs: Remove single RTR_HEADER from generated main.mm
- msbuild/.../GenerateR2RModuleRegistration.cs: New task
- dotnet/targets/Microsoft.Sdk.R2R.targets: Per-module framework/dylib
  creation with symbol renaming
- dotnet/targets/Xamarin.Shared.Sdk.targets: Handle multiple R2R
  frameworks in post-processing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jkoritzinsky jkoritzinsky changed the title Dev/jekoritz/r2r multiple images Support multiple R2R images for ios/tvos apps Apr 2, 2026
@jkoritzinsky jkoritzinsky changed the base branch from main to net11.0 April 2, 2026 23:13
@jkoritzinsky jkoritzinsky marked this pull request as ready for review April 2, 2026 23:13
@rolfbjarne
Copy link
Copy Markdown
Member

Recreated from origin as #25077 (due to CI with PRs from forks).

@rolfbjarne rolfbjarne closed this Apr 3, 2026
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.

2 participants