Skip to content

Conversation

@jkoritzinsky
Copy link
Member

Today, crossgen2 uses its own PE builder built on top of System.Reflection.PortableExecutable. However, this implementation ends up manually redoing the vast majority of the features System.Reflection.PortableExecutable provides manually to support a number of edge cases that the library does not provide. Additionally, we plan to introduce a ReadyToRun format based on Mach-O (see #120065). There is no library like System.Reflection.PortableExecutable with a similar API that we could use for the Mach-O format, so we will either need to add some parallel path or move the PE path to something that can be shared with the Mach-O support.

For NativeAOT's ILCompiler, we use an ObjectWriter library based loosely around LibObjectFile to enable us to write COFF, ELF, and Mach-O objects. This library provides a consistent API for all three formats.

This PR changes crossgen2 to use a PE writer based on the COFF object writer from our ObjectWriter library. Additionally, this PR adds a number of features to the ObjectWriter library to support various constructs that are necessary for emitting a ReadyToRun image (symbol ranges, node size "relocs", deterministic file checksums, etc.).

This should make completing #120065 much easier as the vast majority of the "How do we emit code/data correctly so we can meet Apple's requirements?" question is already met by the MachObjectWriter in the ObjectWriter library, leaving a much smaller tail of work when adding support for it.

… need real unwind/debug info for R2R in the same way that NAOT does
…we needed this are CodeView debug sections, which aren't supported in PE files
…to ObjectWriter and move R2R usage over to be based on that.
…of it) can be used from within the ObjectWriter when provided.
…te a file on disk in the new path. (Does it work? That's the next step)
@jkoritzinsky
Copy link
Member Author

/azp run runtime-coreclr r2r-extra, runtime-coreclr r2r, runtime-coreclr crossgen2, runtime-coreclr crossgen2 outerloop, runtime-coreclr crossgen2-composite

@azure-pipelines
Copy link

Azure Pipelines successfully started running 5 pipeline(s).

@jkoritzinsky
Copy link
Member Author

My analysis of the failures:

crossgen2-composite is in main: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1173552&view=ms.vss-test-web.build-test-results-tab

r2r-extra: There's inconsistent occurrences of flaky tests like the ones I'm seeing here (stackoverflowtester in particular shows up quite a bit).

The TestReadyToRun_Libraries runs were broken due to an infra issue. Running them again now.

@jkoritzinsky
Copy link
Member Author

/azp run runtime-coreclr crossgen2

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky jkoritzinsky added this to the 11.0.0 milestone Oct 14, 2025
@jkoritzinsky jkoritzinsky moved this to High Priority in AppModel Oct 14, 2025
@jkoritzinsky jkoritzinsky requested a review from janvorli October 15, 2025 23:32
Copy link
Member

@davidwrighton davidwrighton left a comment

Choose a reason for hiding this comment

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

Looks good. I have a few issues I'd like to see you address/file a bug for, but otherwise thumbs up

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM although I see a few FIXME comments. Might be worth having bugs for those

@jkoritzinsky jkoritzinsky enabled auto-merge (squash) October 28, 2025 16:00
@jkoritzinsky
Copy link
Member Author

/ba-g Windows arm64 queue is currently dead.

@jkoritzinsky jkoritzinsky merged commit addf696 into dotnet:main Oct 28, 2025
92 of 96 checks passed
@github-project-automation github-project-automation bot moved this from High Priority to Done in AppModel Oct 28, 2025
@jkoritzinsky jkoritzinsky deleted the unified-object-writer branch October 28, 2025 18:17
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants