Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 22, 2025

Fixes #

main PR

Description

When CrossGen2 fails (e.g., segfault with exit code 139), the bash test script continues to run R2RDump on invalid output, producing misleading errors like "The file is not a ReadyToRun image" instead of clearly reporting the CrossGen2 failure.

Added exit code check to skip R2RDump when CrossGen2 fails, matching existing Windows batch script behavior:

$__Command
__cg2ExitCode=$?

if [ $__cg2ExitCode -ne 0 ]; then
  return
fi

echo "Running R2RDump: $__R2RDumpCommand"

Customer Impact

Test failures show confusing error messages that obscure the actual failure (CrossGen2 crash). Developers waste time investigating R2RDump errors instead of the root cause.

Regression

No. This is a test infrastructure improvement, not a functional regression.

Testing

Verified logic matches Windows batch script implementation (line 327 in same file). No functional changes to CrossGen2 or R2RDump execution paths—only error reporting flow.

Risk

Minimal. Four-line change to generated test scripts. Failure cases exit earlier with clearer error messages. Success cases unchanged.

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Test failure: Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.cmd</issue_title>
<issue_description>Failed in: runtime-coreclr crossgen2 20251117.1

Failed tests:

R2R-CG2 osx arm64 Checked @ OSX.13.Arm64.Open
    - Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.cmd

Error message:

DOTNET_DbgEnableMiniDump is set and the createdump binary does not exist: /private/tmp/helix/working/A9240945/p/crossgen2/createdump
/private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/Interop/../PInvoke/CriticalHandles/StructTest/StructTest/StructTest.sh: line 258: 89488 Segmentation fault: 11  $__Command
Image file '/private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.dll' information:
Size: 8704 byte(s)
MetadataSize: 4396 byte(s)
SizeOfImage: 32768 byte(s)
ImageBase: 0x400000
FileAlignment: 0x200
SectionAlignment: 0x2000
CorHeader.Flags: ILOnly
Sections:
  .text 8192 - 14104
  .rsrc 16384 - 17636
  .reloc 24576 - 24588
HasExportTable: False
ExportTableHeaderLength: 0
_namedExportRva: 0 item(s)

Return code:      1
Raw output file:      /tmp/helix/working/A9240945/w/AB4909B9/uploads/PInvoke/CriticalHandles/StructTest/StructTest/output.txt
Raw output:
BEGIN EXECUTION
in takeLock
/private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/IL-CG2/StructTest.dll
02:31:13
Response file: /private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.dll.rsp
/private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/IL-CG2/StructTest.dll
-o:/private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.dll
-O
--targetarch:arm64
--targetos:osx
--verify-type-and-field-layout
--method-layout:random
-r:/tmp/helix/working/A9240945/p/System.*.dll
-r:/tmp/helix/working/A9240945/p/Microsoft.*.dll
-r:/tmp/helix/working/A9240945/p/xunit.*.dll
-r:/tmp/helix/working/A9240945/p/mscorlib.dll
-r:/tmp/helix/working/A9240945/p/netstandard.dll
Running CrossGen2:  /tmp/helix/working/A9240945/p/crossgen2/crossgen2 @/private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.dll.rsp   -r:/private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/IL-CG2/*.dll
Running R2RDump:  dotnet /tmp/helix/working/A9240945/p/R2RDump/R2RDump.dll --header --sc --in /private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.dll --out /private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.dll.r2rdump --val
Error: System.BadImageFormatException: The file is not a ReadyToRun image
   at ILCompiler.Reflection.ReadyToRun.ReadyToRunReader.Initialize(IAssemblyMetadata metadata) in /_/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs:line 524
   at ILCompiler.Reflection.ReadyToRun.ReadyToRunReader..ctor(IAssemblyResolver assemblyResolver, String filename) in /_/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs:line 429
   at R2RDump.Program.Run() in /_/src/coreclr/tools/r2rdump/Program.cs:line 449
02:31:13
Crossgen2 failed with exitcode: 139
in ReleaseLock
Test failed. Trying to see if dump file was created in /cores since 11/18/2025 2:31:13 AM
Test Harness Exitcode is : 1
To run the test:
Set up CORE_ROOT and run.
> /private/tmp/helix/working/A9240945/w/AB4909B9/e/Interop/Interop/../PInvoke/CriticalHandles/StructTest/StructTest/StructTest.sh

Stack trace:

   at Xunit.Assert.True(Nullable`1 condition, String userMessage) in /_/src/arcade/src/Microsoft.DotNet.XUnitAssert/src/BooleanAsserts.cs:line 141
   at TestLibrary.OutOfProcessTest.RunOutOfProcessTest(String assemblyPath, String testPathPrefix)
   at Program.<<Main>$>g__TestExecutor260|0_261(StreamWriter tempLogSw, StreamWriter statsCsvSw, <>c__DisplayClass0_0&)

</issue_description>

<agent_instructions>It looks suspicious that r2rdump is just failing. Can we verify that crossgen2 is returning success in these cases?</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix test failure in StructTest for osx arm64 Fix CrossGen2 exit code handling in bash test scripts Nov 22, 2025
Copilot AI requested a review from agocke November 22, 2025 02:41
Copilot finished work on behalf of agocke November 22, 2025 02:41
$__Command
__cg2ExitCode=$?
if [ $__cg2ExitCode -ne 0 ]; then
Copy link
Member

Choose a reason for hiding this comment

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

This is going to skip the code after echo "Crossgen2 compilation finished, exit code" that does not look desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure: Interop/PInvoke/CriticalHandles/StructTest/StructTest/StructTest.cmd

3 participants