dotnet / dotnet/android

Consider storing R2R images in a separate file

Open
#10,802 0 comments 0 reactions 0 assignees View on GitHub
Area: App Runtime
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 19h
Merged PRs (30d)
252

Description

### Android framework version

net11.0-android (Preview)

### Affected platform version

.NET 11

### Description

Context:
* https://github.com/dotnet/runtime/pull/112934
* https://github.com/dotnet/runtime/pull/115631

When we added ReadyToRun support for Android (CoreCLR), R2R images remain inside `.dll` files. There was a step where this data was copied to memory and loaded, which may not be optimal.

For CoreCLR (R2R) support on iOS, there was **"Platform-Native R2R Envelope"** related work — tracked by issue [dotnet/runtime#120065](https://github.com/dotnet/runtime/issues/120065). On iOS, PE-based R2R can't work due to page protection restrictions (no JIT entitlement), so R2R native code is emitted into a **separate Mach-O (.dylib) file** that the OS can load natively.

Key PRs:

| PR | Title | Author | Date |
|---|---|---|---|
| [#120584](https://github.com/dotnet/runtime/pull/120584) | Add initial doc for R2R platform-native image (Mach-O, composite only) | elinor-fung | Oct 2025 |
| [#120777](https://github.com/dotnet/runtime/pull/120777) | Extract out minimal concerns from PEImageLayout for R2R images | jkoritzinsky | Nov 2025 |
| [#121186](https://github.com/dotnet/runtime/pull/121186) | Add support for emitting Mach-O R2R images | jkoritzinsky | Nov 2025 |
| [#121363](https://github.com/dotnet/runtime/pull/121363) | Add support for host callback to get information for platform-native composite R2R images | elinor-fung | Nov 2025 |
| [#122511](https://github.com/dotnet/runtime/pull/122511) | Reduce the number of sections in R2R PE files | jkoritzinsky | Jan 2026 |

The integration on the macios side was [dotnet/macios#24327](https://github.com/dotnet/macios/pull/24327), which got a MAUI iOS app running with R2R.

The design doc ([readytorun-platform-native-envelope.md](https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/readytorun-platform-native-envelope.md)) lays out the approach: crossgen2 emits the composite R2R image as a native Mach-O `.dylib`, and a new `get_native_code_data` host callback tells the runtime where to find it. This lets the OS `dlopen` the native code directly rather than needing to copy/map PE data.

## Question

Is there anything we can use from this work to improve Android?

### Steps to Reproduce

1. `dotnet new android`
2. `dotnet build -c Release` uses ReadyToRun by default

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.