Add R2RDump support for Mach-O composite R2R images#121566
Merged
elinor-fung merged 8 commits intodotnet:mainfrom Nov 14, 2025
Merged
Add R2RDump support for Mach-O composite R2R images#121566elinor-fung merged 8 commits intodotnet:mainfrom
elinor-fung merged 8 commits intodotnet:mainfrom
Conversation
This was referenced Nov 13, 2025
Open
TODO: - Move shared code out of HostModel, separate into shared/HostModel/R2RDump parts - Print Mach-O header info when dumping image - Handle diff for Mach-O sections
9a4abc4 to
3e51420
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for Mach-O composite ReadyToRun (R2R) images to the R2RDump tool and ILCompiler.Reflection.ReadyToRun library. The implementation introduces an abstraction layer for binary image reading to handle both PE and Mach-O formats uniformly.
Key Changes:
- Introduced
IBinaryImageReaderinterface to abstract binary image reading across PE and Mach-O formats - Implemented
PEImageReaderandMachOImageReaderas format-specific readers - Moved common Mach-O types from
Microsoft.NET.HostModelto shared locationsrc/coreclr/tools/Common/MachOwith conditional compilation for namespace selection
Reviewed Changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
IBinaryImageReader.cs |
New interface abstracting binary image operations across formats |
PEImageReader.cs |
PE-specific implementation wrapping PEReader |
MachOImageReader.cs |
New Mach-O image reader with symbol table parsing and segment resolution |
ReadyToRunReader.cs |
Refactored to use IBinaryImageReader interface instead of directly using PEReader |
ManifestAssemblyMetadata.cs |
Added parameterless constructor for Mach-O support where PEReader is unavailable |
ReadyToRunMethod.cs |
Added debug assertion for PE-specific operations |
R2RDiff.cs |
Updated to use abstracted GetSections method |
NList64.cs |
New Mach-O symbol table entry structure |
NameBuffer.cs |
Added GetString method for reading segment/section names |
Segment64LoadCommand.cs |
Added GetVMAddress accessor |
Section64LoadCommand.cs |
Added SectionName, GetVMAddress, and GetSize accessors |
MachHeader.cs |
Added CpuType accessor |
MachObjectFile.cs |
Moved IsMachOImage method to shared location with conditional namespaces |
| Common MachO enums/types | Added conditional compilation for dual namespace support |
| Project files | Updated to include shared MachO sources |
Comments suppressed due to low confidence (1)
src/coreclr/tools/Common/MachO/BinaryFormat/NameBuffer.cs:57
- The
GetString()method may not respect byte order. When the struct is created,_nameLowerand_nameUppermay be swapped based on endianness (lines 29-38), butGetString()always reads bytes starting from_nameLower. On big-endian systems, the bytes should be read starting from_nameUpperinstead. Consider adjusting the implementation to account for endianness similar to how the constructor does.
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/MachO/MachOImageReader.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/MachO/MachOImageReader.cs
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/MachO/MachOImageReader.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/MachO/MachOImageReader.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/MachO/MachOImageReader.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/IBinaryImageReader.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/MachO/MachOImageReader.cs
Outdated
Show resolved
Hide resolved
Member
|
@adamperlin You should be aware of this effort. |
3 tasks
davidwrighton
approved these changes
Nov 14, 2025
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Update
R2RDump/ILCompiler.Reflection.ReadyToRunto handle Mach-O composite R2R imagesReadyToRunReadystop operating onPEReaderdirectlyIBinaryImageReaderinterface to handle reading of different R2R image types - implementations for PE and MachOMicrosoft.NET.HostModelto shared locationsrc/coreclr/tools/Common