Skip to content

Conversation

kg
Copy link
Member

@kg kg commented Aug 5, 2025

Hopefully these changes should produce more diagnostic output when this fails on outerloop to help track down what's happening. I haven't been able to reproduce the failures locally on linux or windows yet.

@kg kg marked this pull request as ready for review August 5, 2025 01:23
@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 01:23
Copy link
Contributor

@Copilot 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 diagnostic output to the ReadyToRun (R2R) reader to help troubleshoot failures reported in issues #106675 and #108255. The changes focus on providing detailed information about PE image structure when BadImageFormatException occurs.

Key changes:

  • Added exception handling with diagnostic output in ReadyToRunReader initialization methods
  • Enhanced PEExportTable with additional diagnostic information and console dumping capabilities
  • Added image information dumping including PE header details, export table data, and file metadata

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
ReadyToRunReader.cs Added try-catch blocks with diagnostic output for Initialize() and EnsureImportSections() methods, plus DumpImageInformation() method
PEReaderExtensions.cs Enhanced PEExportTable with diagnostic fields, console error logging for zero RVAs, and DumpToConsoleError() method
Comments suppressed due to low confidence (2)

src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs:490

  • [nitpick] The opening brace for the try block should be on the same line as the try statement according to C# conventions.
            try

src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs:520

  • [nitpick]
                        {

@kg
Copy link
Member Author

kg commented Aug 5, 2025

Interestingly, this seems to break for composite r2r locally:

"Running CrossGen2:  "Z:\runtime\artifacts\tests\coreclr\windows.x64.Checked\Tests\Core_Root\crossgen2\crossgen2.exe" @"Z:\runtime\artifacts\tests\coreclr\windows.x64.Checked\JIT\Regression\JitBlue\DevDiv_255294\DevDiv_255294\\composite-r2r.dll.rsp"   --composite"
Emitting R2R PE file: Z:\runtime\artifacts\tests\coreclr\windows.x64.Checked\JIT\Regression\JitBlue\DevDiv_255294\DevDiv_255294\\composite-r2r.dll
Emitting R2R PE file: Z:\runtime\artifacts\tests\coreclr\windows.x64.Checked\JIT\Regression\JitBlue\DevDiv_255294\DevDiv_255294\DevDiv_255294.dll
"Running R2RDump:  "Z:\runtime\dotnet.cmd" "Z:\runtime\artifacts\tests\coreclr\windows.x64.Checked\Tests\Core_Root\r2rdump\r2rdump.dll" --header --sc --in Z:\runtime\artifacts\tests\coreclr\windows.x64.Checked\JIT\Regression\JitBlue\DevDiv_255294\DevDiv_255294\\composite-r2r.dll --out Z:\runtime\artifacts\tests\coreclr\windows.x64.Checked\JIT\Regression\JitBlue\DevDiv_255294\DevDiv_255294\\composite-r2r.dll.r2rdump --val"
Z:\runtime\.dotnet
Image file 'Z:\runtime\artifacts\tests\coreclr\windows.x64.Checked\JIT\Regression\JitBlue\DevDiv_255294\DevDiv_255294\composite-r2r.dll' information:
Size: 729088 byte(s)
MetadataSize: 284 byte(s)
SizeOfImage: 729088 byte(s)
ImageBase: 0x180000000
FileAlignment: 0x1000
SectionAlignment: 0x1000
CorHeader.Flags: 0
Error: System.BadImageFormatException: Failed to convert invalid RVA to offset: 720940
   at ILCompiler.Reflection.ReadyToRun.PEReaderExtensions.GetOffset(PEReader reader, Int32 rva) in Z:\runtime\src\coreclr\tools\aot\ILCompiler.Reflection.ReadyToRun\PEReaderExtensions.cs:line 144
   at ILCompiler.Reflection.ReadyToRun.PEExportTable..ctor(PEReader peReader) in Z:\runtime\src\coreclr\tools\aot\ILCompiler.Reflection.ReadyToRun\PEReaderExtensions.cs:line 37
   at ILCompiler.Reflection.ReadyToRun.ReadyToRunReader.DumpImageInformation() in Z:\runtime\src\coreclr\tools\aot\ILCompiler.Reflection.ReadyToRun\ReadyToRunReader.cs:line 569
   at ILCompiler.Reflection.ReadyToRun.ReadyToRunReader.Initialize(IAssemblyMetadata metadata) in Z:\runtime\src\coreclr\tools\aot\ILCompiler.Reflection.ReadyToRun\ReadyToRunReader.cs:line 546
   at R2RDump.Program.Run() in Z:\runtime\src\coreclr\tools\r2rdump\Program.cs:line 449
20:33:48.42
R2RDump failed with exitcode - 1

EDIT: Based on DependenciesGui and dumpbin this looks like a valid PE executable, but we're failing to parse its export table for some reason. I think this may be a bug in R2RDump.

@kg
Copy link
Member Author

kg commented Aug 6, 2025

The RVA is valid and the code for parsing the headers is malfunctioning. Never seen this before.
image

EDIT: The disassembly looks wrong:
image

Verified the VS disassembly is correct. It's 81 7D FC 50 C3 00 00, which is comparing against some weird random constant, instead of 83 7d fc ff which would compare against -1. I can't figure out why this is happening.

EDIT 2: This was some sort of transient at-rest file corruption, it went away once I rebuilt everything. :(

@kg
Copy link
Member Author

kg commented Aug 6, 2025

Successfully verified this locally so it's ready for review.

@kg kg requested review from max-charlamb and mangod9 August 6, 2025 23:00
@kg
Copy link
Member Author

kg commented Aug 7, 2025

/azp run runtime-coreclr crossgen2 outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kg
Copy link
Member Author

kg commented Aug 7, 2025

This fails if the CORHeader is missing ATM, I have a fix for that I'll push once I see the test results.

@kg kg merged commit dc00334 into dotnet:main Aug 7, 2025
90 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 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.

2 participants