Skip to content

Add R2RDump support for Mach-O composite R2R images#121566

Merged
elinor-fung merged 8 commits intodotnet:mainfrom
elinor-fung:r2rdump-macho
Nov 14, 2025
Merged

Add R2RDump support for Mach-O composite R2R images#121566
elinor-fung merged 8 commits intodotnet:mainfrom
elinor-fung:r2rdump-macho

Conversation

@elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented Nov 13, 2025

Update R2RDump / ILCompiler.Reflection.ReadyToRun to handle Mach-O composite R2R images

  • Make ReadyToRunReady stop operating on PEReader directly
  • Add a IBinaryImageReader interface to handle reading of different R2R image types - implementations for PE and MachO
  • Move common types and functionality related to Mach-O from Microsoft.NET.HostModel to shared location src/coreclr/tools/Common

@elinor-fung elinor-fung marked this pull request as ready for review November 13, 2025 19:45
Copilot AI review requested due to automatic review settings November 13, 2025 19:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IBinaryImageReader interface to abstract binary image reading across PE and Mach-O formats
  • Implemented PEImageReader and MachOImageReader as format-specific readers
  • Moved common Mach-O types from Microsoft.NET.HostModel to shared location src/coreclr/tools/Common/MachO with 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, _nameLower and _nameUpper may be swapped based on endianness (lines 29-38), but GetString() always reads bytes starting from _nameLower. On big-endian systems, the bytes should be read starting from _nameUpper instead. Consider adjusting the implementation to account for endianness similar to how the constructor does.

@davidwrighton
Copy link
Member

@adamperlin You should be aware of this effort.

@elinor-fung elinor-fung merged commit 9278f39 into dotnet:main Nov 14, 2025
120 of 124 checks passed
@elinor-fung elinor-fung deleted the r2rdump-macho branch November 14, 2025 19:44
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants