Skip to content

Windows x86 Checked CLR build using -O2 hits runtime asserts #59845

Closed

Description

@BruceForstall

See #53888

Note that Windows Checked is currently built using the -O1 compiler switch.

E.g.,

Assert failure(PID 7704 [0x00001e18], Thread: 7708 [0x1e1c]): FastNExportSEH(pEHR) || IsComPlusNestedExceptionRecord(pEHR) || ((ExecuteHandler2Module != NULL) && IsIPInModule(ExecuteHandler2Module, (PCODE)pEHR->Handler))

CORECLR! PopNestedExceptionRecords + 0xA0 (0x71127c40)
CORECLR! COMPlusEndCatch + 0x4A (0x711285da)
CORECLR! JIT_EndCatch + 0xE (0x71199e41)
CORECLR! CallDescrWorkerInternal + 0x34 (0x71199121)
CORECLR! CallDescrWorker + 0x13E (0x70da52ee)
CORECLR! CallDescrWorkerWithHandler + 0x189 (0x70da5589)
CORECLR! MethodDescCallSite::CallTargetWorker + 0x7A7 (0x70da5d77)
CORECLR! RunMainInternal + 0x2FE (0x70ae232e)
CORECLR! ``RunMain'::29'::__Body::Run'::5'::__Body::Run + 0x86 (0x70ae1c36)
CORECLR! RunMain'::29'::__Body::Run + 0xA3 (0x70ae1d53)
File: D:\workspace_work\1\s\src\coreclr\vm\i386\excepx86.cpp Line: 2054
Image: C:\h\w\B10F09DA\p\corerun.exe

and:

Assert failure(PID 3932 [0x00000f5c], Thread: 5880 [0x16f8]): Consistency check failed: Invalid transition into managed code!

We're walking this thread's stack and we've reached a managed frame at Esp=0x00F7D338. (The method is EHTest::f1) The very next FS:0 record (0x00F7D460) up from this point on the stack should be one of our 'unmanaged to managed SEH handlers', but its not... its something else, and that's very bad. It indicates that someone managed to call into managed code without setting up the proper exception handling.

Get a good unmanaged stack trace for this thread. All FS:0 records are on the stack, so you can see who installed the last handler. Somewhere between that function and where the thread is now is where the bad transition occurred.

A little extra info: FS:0 = 0x00F7C35C, pEHR->Handler = 0x70D12C3A
FAILED: IsUnmanagedToManagedSEHHandler(pEHR)

CORECLR! CHECK::Trigger + 0x3C4 (0x70a75264)
CORECLR! VerifyValidTransitionFromManagedCode + 0x18A (0x709e856a)
CORECLR! StackFrameIterator::NextRaw + 0xAE4 (0x705ca434)
CORECLR! Thread::StackWalkFramesEx + 0x421 (0x705cb681)
CORECLR! Thread::StackWalkFrames + 0x159 (0x705cb1c9)
CORECLR! LookForHandler + 0x1A (0x704959da)
CORECLR! CPFH_RealFirstPassHandler + 0xF57 (0x709e6007)
CORECLR! CPFH_FirstPassHandler + 0x1C0 (0x709e5020)
CORECLR! COMPlusFrameHandler + 0x26B (0x709e88db)
CORECLR! COMPlusNestedExceptionHandler + 0x13B (0x709e8a6b)
File: D:\workspace_work\1\s\src\coreclr\vm\i386\excepx86.cpp Line: 329
Image: C:\h\w\B10F09DA\p\corerun.exe

Activity

  1. ghost added
    untriaged
    on Sep 30, 2021
  2. removed
    untriaged
    on Oct 4, 2021
  3. added this to the 7.0.0 milestone on Oct 4, 2021
  4. mangod9 commented on Oct 4, 2021

    @mangod9
    Member

    Hi @BruceForstall, assume this fix is required to switch to -O2, but looking through the PRs doesnt seem like there is consensus whether it should be switched?

  5. BruceForstall commented on Oct 4, 2021

    @BruceForstall
    ContributorAuthor

    I'm still working on switching to -O2 because it makes the JIT about 10% faster, but my current attempt in #59235 simply works around this issue by not switching x86. The CI has been very noisy with failures recently, so I don't know if there are other lurking issues yet.

    looking through the PRs doesnt seem like there is consensus whether it should be switched?

    I don't think there's any pushback; janvorli had some concerns about debuggability, but I think I addressed those.

  6. mangod9 commented on Oct 4, 2021

    @mangod9
    Member

    ok thanks for the context, so assume this issue isnt blocking your PR, but just something we should fix to enable O2 on x86 as well.

  7. modified the milestones: 7.0.0, Future on Jul 19, 2022
  8. added
    in-pr
    on Jan 4, 2026
  9. added a commit that references this issue on Jan 4, 2026
    5415a58
  10. locked and limited conversation to collaborators on Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-ExceptionHandling-coreclrin-pr

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions