-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add initial doc for future R2R platform-native image (Mach-O, composite only) #120584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
docs/design/coreclr/botr/readytorun-platform-native-envelope.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # ReadyToRun Platform Native Envelope | ||
|
|
||
| Up through .NET 10, ReadyToRun (R2R) uses the Windows PE format as the native envelope on every platform. Non‑Windows platforms therefore load a PE file with the .NET loader performing the required fixups and code activation. | ||
|
|
||
| In .NET 11, we plan to start adding support beyond the PE format. We will target support for: | ||
| - Composite R2R only | ||
| - Mach-O object files emitted by `crossgen2` | ||
| - Runtime using a composite R2R image that is a Mach-O shared library | ||
| - Linking the object files into a shared library is expected to be handled by the SDK and is not covered in this document. | ||
|
|
||
| The tentative high-level design is outlined below. As we implement this support, this document should be updated with more details and the [ReadyToRun overview](./readytorun-overview.md) and [ReadyToRun format](./readytorun-format.md) should be updated to reflect the changes. | ||
|
|
||
| ## crossgen2: producing Mach-O object files | ||
|
|
||
| Mach‑O support will only be supported for composite ReadyToRun when the target OS is macOS. It will be opt-in via a new `crossgen2` flag: | ||
| - `--obj-format macho` | ||
|
|
||
| `crossgen2` will: | ||
| - Produce a Mach-O object file as the composite R2R image with the `RTR_HEADER` export for the `READYTORUN_HEADER`. | ||
| - Mark each input IL assembly as a component R2R assembly: `READYTORUN_FLAG_COMPONENT`. | ||
| - Mark each input IL assembly with a new flag indicating that the associated composite image is in the platform-native format: `READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE` | ||
|
|
||
| `crossgen2` does not produce the final shared library. A separate SDK / build linking step must preserve the `RTR_HEADER` export in the final `dylib`. | ||
|
|
||
| ## Runtime: consuming a platform-native R2R image | ||
|
|
||
| The runtime will be updated to handle platform-native R2R images during assembly load. | ||
|
|
||
| 1. Load IL assembly and determine if it is a R2R assembly. | ||
| 2. If it is not a component R2R assembly, proceed with existing R2R load logic. | ||
kotlarmilos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - We will not have platform-native support for this scenario | ||
| 3. If it is a component R2R assembly with the new `READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE` flag set: | ||
| a. Read `OwnerCompositeExecutable` value. | ||
| b. Invoke host callback with component assembly path and owner composite name. | ||
| c. On success, obtain pointer to composite `READYTORUN_HEADER` and use it for native method lookup / fixups. | ||
| d. On failure, fall back to IL/JIT path. | ||
| 4. If the platform-native flag is not set, proceed with existing R2R load logic (PE assembly lookup and load). | ||
|
|
||
| ### Host callback | ||
|
|
||
| The [`host_runtime_contract`](/src/native/corehost/host_runtime_contract.h) will be updated with a new callback for getting native code information. | ||
|
|
||
| ```c | ||
| struct native_code_context | ||
| { | ||
| size_t size; // size of this struct | ||
| const char* assembly_path; // component assembly path | ||
| const char* owner_composite_name; // name from component R2R header | ||
| }; | ||
|
|
||
| struct native_code_data | ||
| { | ||
| size_t size; // size of this struct | ||
| void* r2r_header_ptr; // ReadyToRun header | ||
| size_t image_size; // size of the image | ||
| void* image_base; // base address where the image was loaded | ||
| }; | ||
|
|
||
| bool get_native_code_data( | ||
| const struct native_code_context* context, | ||
| /*out*/ struct native_code_data* data | ||
| ); | ||
| ``` | ||
|
|
||
| This leaves it to the host to do the actual load (for example, `dlopen` of a shared library, using something statically linked into the host itself) of the platform-native image. It is also responsible for any caching desired. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.