Skip to content

Conversation

@am11
Copy link
Member

@am11 am11 commented Jan 8, 2026

Fixes #116375.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 8, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@am11 am11 force-pushed the feature/il_throw_PUSH_COOP_PINVOKE_FRAME branch from 1a243a6 to 00c4f6a Compare January 8, 2026 22:39
@am11 am11 force-pushed the feature/il_throw_PUSH_COOP_PINVOKE_FRAME branch from b8782d2 to 0d677dd Compare January 8, 2026 22:41
@am11 am11 force-pushed the feature/il_throw_PUSH_COOP_PINVOKE_FRAME branch from 0d677dd to 5359b4c Compare January 8, 2026 22:42
@am11
Copy link
Member Author

am11 commented Jan 13, 2026

@janvorli, JIT/Directed, JIT/CodeGenBringUpTests and Exceptions suites are now passing. I cannot repro the remaining win-x64 failures like add_r4:

# in powershell
> ./build.cmd clr+libs -rc Checked
> src/tests/build.cmd Checked -Dir JIT/Directed -Dir JIT/CodeGenBringUpTests -Dir Exceptions -Dir JIT/IL_Conformance /p:LibrariesConfiguration=Debug
> $CORE_ROOT=$env:CORE_ROOT="$pwd/artifacts/tests/coreclr/windows.x64.Debug/Tests/Core_Root"
> artifacts\tests\coreclr\windows.x64.Checked\JIT\IL_Conformance\IL_Conformance\IL_Conformance.cmd
...
END EXECUTION - PASSED
PASSED

CI is showing https://helix.dot.net/api/2019-06-17/jobs/36ba1a26-3370-47a0-a24a-e0b2d2e41006/workitems/IL_Conformance/console:

13:15:59.276 Running test: JIT/IL_Conformance/Old/Conformance_Base/add_ovf_u8/add_ovf_u8.dll
13:15:59.281 Passed test: JIT/IL_Conformance/Old/Conformance_Base/add_ovf_u8/add_ovf_u8.dll
13:15:59.402 Running test: JIT/IL_Conformance/Old/Conformance_Base/add_r4/add_r4.dll
Xunit.Sdk.EqualException: Assert.Equal() Failure: Values differ
Expected: 100
Actual:   0
   at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in /_/src/arcade/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs:line 174
   at Program.<<Main>$>g__TestExecutor10|0_11(StreamWriter tempLogSw, StreamWriter statsCsvSw, <>c__DisplayClass0_0&)
13:16:00.027 Failed test: JIT/IL_Conformance/Old/Conformance_Base/add_r4/add_r4.dll
13:16:00.039 Running test: JIT/IL_Conformance/Old/Conformance_Base/add_r8/add_r8.dll
Xunit.Sdk.EqualException: Assert.Equal() Failure: Values differ
Expected: 100
Actual:   0
   at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in /_/src/arcade/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs:line 174
   at Program.<<Main>$>g__TestExecutor11|0_12(StreamWriter tempLogSw, StreamWriter statsCsvSw, <>c__DisplayClass0_0&)
13:16:00.050 Failed test: JIT/IL_Conformance/Old/Conformance_Base/add_r8/add_r8.dll
13:16:00.063 Running test: JIT/IL_Conformance/Old/Conformance_Base/beq_r4/beq_r4.dll
13:16:00.241 Passed test: JIT/IL_Conformance/Old/Conformance_Base/beq_r4/beq_r4.dll

@am11
Copy link
Member Author

am11 commented Jan 13, 2026

OK with $env:DOTNET_TieredCompilation=0 it fails locally. Investigating..


#ifdef UNIX_AMD64_ABI
// On Unix AMD64, argument registers are saved in the transition block
m_Context.Rax = 0;
Copy link
Member

Choose a reason for hiding this comment

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

We need to store non-volatile registers and control registers only. The EH should not need anything else. So on Unix, we don't need the float state at all. And the general purpose argument registers are also not needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going by #116375 (comment), which is why I added FP registers (and took a while to figure out the right restore points). Do you want me to revert FP registers and use PROLOG_WITH_TRANSITION_BLOCK ? I can test if it's sufficient for unwind. Note that we are replacing PAL_VirtualUnwind call in excep.cpp, where libunwind does account for FP registers.

Copy link
Member

Choose a reason for hiding this comment

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

My comment was on Unix Amd64 only. Other architectures need to restore some float registers, as they are non-volatile there. Only Unix Amd64 has no non-volatile FP regs.
So for Unix Amd64, let's not capture any FP regs and let's not copy them here - and thus not set the CONTEXT_FLOATING_POINT in the ContextFlags.

; which can corrupt MXCSR (setting it to 0x20 with all FP exception masks cleared).
; Without this reset, FP operations after exception handling would trigger exceptions.
; 0x1F80 = default MXCSR: all exception masks set, round to nearest, no exceptions pending
push 1F80h
Copy link
Member

Choose a reason for hiding this comment

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

I am not aware of any case that would have the CONTEXT_FLOATING_POINT set and not have the MXCSR valid in the CONTEXT. We've never had such a problem and you have initialization of that in your new code to update CONTEXT from the TransitionFrame.

Copy link
Member Author

Choose a reason for hiding this comment

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

Without 22571b2 and dd15723, one or more tests in JIT/Directed, JIT/CodeGenBringUpTests and Exceptions were failing (#123015 (comment)).

Copy link
Member

Choose a reason for hiding this comment

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

I think the problem is likely caused by something else. I don't see how your change (as a whole) could introduce such a problem.

PCODE pbRetVal = (PCODE)NULL;

#if defined(TARGET_AMD64) && defined(TARGET_WINDOWS)
// Reset MXCSR to default value to prevent FP exceptions during JIT compilation.
Copy link
Member

Choose a reason for hiding this comment

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

If we have a problem with MXCSR getting messed up, it is not sufficient to reset it in prestub. We need to reset it earlier before resuming execution of managed code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've moved it to CallEHFilterFunclet.

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

Labels

area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bring IL_{Throw,Rethrow,ThrowExact} to PUSH_COOP_PINVOKE_FRAME plan

3 participants