Skip to content

Assert fails (numGenericArgs > 0) when executing typeof(T) in a nonvirtual interface method, crossgen2. #37344

Description

@0xfk0

Description

Program containing call sealed function from generic base class crashes with assertion (see below) when compiled with crossgen2. The issue isn't reproduces when compiling test application with crossgen1 or running not compiled version.

Program crashes when executing typeof(T) operator.

Assertion is the following:

Assert failure(PID 17426 [0x00004412], Thread: 17426 [0x4412]): numGenericArgs > 0
    File: /home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp Line: 2987
    Image: /home/sysop/bin/clr/corerun

The issue is caused by presence of generic base class Base and sealed keyword applied to test funcion. If sealed keyword commented out, the issue isn't reproduces.

Source code of the test application:

using System;
using System.Runtime.CompilerServices;

public interface Base<T>
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    /* sealed*/ void test()
    {
        Console.Error.WriteLine("enter");
        Type t = typeof(T);
        Console.Error.WriteLine("type {0}", t.FullName);
    }
}

public class Impl : Base<string> {}

class Program
{
    static void Main()
    {
        Base<string> inst = new Impl();
        inst.test();
    }
}

Configuration

Situation repoduced on latest .NET version (commit e25517e) from master branch.

CoreCLR was build on x86 architecture in Debug mode. Issue is also reproducible, when CoreCLR is build in Checked mode. Also same or similar issue exists on ARM architecture: runtime crashes with segfault, no assertion message printed. But again, removing sealed keyword from test application "fixes" the issue.

Other information

Backtrace is the following:


Assert failure(PID 18159 [0x000046ef], Thread: 18159 [0x46ef]): numGenericArgs > 0
    File: /home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp Line: 2987
    Image: /home/sysop/bin/clr/corerun


Thread 1 "corerun" received signal SIGTRAP, Trace/breakpoint trap.
DBG_DebugBreak () at /home/sysop/dotnet-runtime/src/coreclr/src/pal/src/arch/amd64/debugbreak.S:10
10              ret
(gdb) bt
#0  DBG_DebugBreak () at /home/sysop/dotnet-runtime/src/coreclr/src/pal/src/arch/amd64/debugbreak.S:10
#1  0x00007ffff635f4d1 in DebugBreak () at /home/sysop/dotnet-runtime/src/coreclr/src/pal/src/debug/debug.cpp:405
#2  0x00007ffff5af3e3b in DbgAssertDialog (
    szFile=0x7ffff6543852 "/home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp", iLine=2987,
    szExpr=0x7ffff65441bd "numGenericArgs > 0") at /home/sysop/dotnet-runtime/src/coreclr/src/utilcode/debug.cpp:698
#3  0x00007ffff5bfba36 in ProcessDynamicDictionaryLookup (pTransitionBlock=0x7fffffffd0b8, pModule=0x7fff7cf52418,
    pInfoModule=0x7fff7cf52418, kind=8 '\b', pBlob=0x7fff7cf816ef "\020\023",
    pBlobStart=0x7fff7cf816ee "\b\020\023", pResult=0x7fffffffccc8, pDictionaryIndexAndSlot=0x7fffffffcbc4)
    at /home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp:2987
#4  0x00007ffff5bfc41c in DynamicHelperFixup (pTransitionBlock=0x7fffffffd0b8, pCell=0x7fff7cf81550,
    sectionIndex=2, pModule=0x7fff7cf52418, pKind=0x7fffffffcf74, pTH=0x7fffffffcf88, ppMD=0x7fffffffcf80,
    ppFD=0x7fffffffcf78) at /home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp:3191
#5  0x00007ffff5bfddeb in DynamicHelperWorker (pTransitionBlock=0x7fffffffd0b8, pCell=0x7fff7cf81550,
    sectionIndex=2, pModule=0x7fff7cf52418, frameFlags=0)
    at /home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp:3467
#6  0x00007ffff5ec5c27 in DelayLoad_Helper ()
    at /home/sysop/dotnet-runtime/src/coreclr/src/pal/inc/unixasmmacrosamd64.inc:837
#7  0x00007fff7cf70602 in test ()
#8  0x0000000000000000 in ?? ()

Activity

  1. changed the title [-]Assert fails (numGenericArgs > 0), crossgen2, generic base class.[/-] [+]Assert fails (numGenericArgs > 0) when executing typeof(T), crossgen2, generic base class.[/+] on Jun 3, 2020
  2. changed the title [-]Assert fails (numGenericArgs > 0) when executing typeof(T), crossgen2, generic base class.[/-] [+]Assert fails (numGenericArgs > 0) when executing typeof(T) in sealed function of generic base class, crossgen2.[/+] on Jun 3, 2020
  3. 0xfk0 commented on Jun 3, 2020

    @0xfk0
    ContributorAuthor
  4. 0xfk0 commented on Jun 3, 2020

    @0xfk0
    ContributorAuthor

    More verbose backtrace:

    #0  DBG_DebugBreak () at /home/sysop/dotnet-runtime/src/coreclr/src/pal/src/arch/amd64/debugbreak.S:10
    No locals.
    #1  0x00007ffff635f4d1 in DebugBreak () at /home/sysop/dotnet-runtime/src/coreclr/src/pal/src/debug/debug.cpp:405
    No locals.
    #2  0x00007ffff5af3e3b in DbgAssertDialog (
        szFile=0x7ffff6543852 "/home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp", iLine=2987,
        szExpr=0x7ffff65441bd "numGenericArgs > 0") at /home/sysop/dotnet-runtime/src/coreclr/src/utilcode/debug.cpp:698
            szExprToDisplay = 0x7ffff65441bd "numGenericArgs > 0"
            fGotStackTrace = 1
            fConstrained = 0
            dwAssertStacktrace = 1
            lAlreadyOwned = -1
    #3  0x00007ffff5bfba36 in ProcessDynamicDictionaryLookup (pTransitionBlock=0x7fffffffd0b8, pModule=0x7fff7cf52418,
        pInfoModule=0x7fff7cf52418, kind=8 '\b', pBlob=0x7fff7cf816ef "\020\023",
        pBlobStart=0x7fff7cf816ee "\b\020\023", pResult=0x7fffffffccc8, pDictionaryIndexAndSlot=0x7fffffffcbc4)
        at /home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp:2987
            genericContextPtr = 140734468488216
            numGenericArgs = 0
            pContextMT = 0x7fff4c007c18
            pContextMD = 0x0
            signatureKind = ENCODE_NONE
            dictionarySlot = 21898
    #4  0x00007ffff5bfc41c in DynamicHelperFixup (pTransitionBlock=0x7fffffffd0b8, pCell=0x7fff7cf81550,
        sectionIndex=2, pModule=0x7fff7cf52418, pKind=0x7fffffffcf74, pTH=0x7fffffffcf88, ppMD=0x7fffffffcf80,
        ppFD=0x7fffffffcf78) at /home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp:3191
            __alwayszero = false
            pNativeImage = 0x5555558a8b90
            rva = 136528
            pImportSection = 0x7fff7cf814a8
            index = 0
            pSignatures = 0x7fff7cf81608
            pBlob = 0x7fff7cf816ef "\020\023"
            pBlobStart = 0x7fff7cf816ee "\b\020\023"
            kind = 8 '\b'
            pInfoModule = 0x7fff7cf52418
            fReliable = false
            th = {{m_asTAddr = 0, m_asPtr = 0x0, m_asMT = 0x0, m_asTypeDesc = 0x0, m_asParamTypeDesc = 0x0,
                m_asTypeVarTypeDesc = 0x0, m_asFnPtrTypeDesc = 0x0}}
            pMD = 0x0
            pFD = 0x0
            genericLookup = {signature = 0x0, helper = CORINFO_HELP_RUNTIMEHANDLE_CLASS, indirections = 65535,
              testForNull = false, testForFixup = false, sizeOffset = 65535, offsets = {140737488342288,
                140737316387501, 140737488342288, 93824994927264}, indirectFirstOffset = false,
              indirectSecondOffset = false}
            dictionaryIndexAndSlot = 4294967295
            pHelper = 140735287693488
    #5  0x00007ffff5bfddeb in DynamicHelperWorker (pTransitionBlock=0x7fffffffd0b8, pCell=0x7fff7cf81550,
        sectionIndex=2, pModule=0x7fff7cf52418, frameFlags=0)
        at /home/sysop/dotnet-runtime/src/coreclr/src/vm/prestub.cpp:3467
            __gcHolder = {<GCHolderBase> = {m_Thread = 0x5555557e62a0, m_WasCoop = 1}, <No data fields>}
            th = {{m_asTAddr = 0, m_asPtr = 0x0, m_asMT = 0x0, m_asTypeDesc = 0x0, m_asParamTypeDesc = 0x0,
                m_asTypeVarTypeDesc = 0x0, m_asFnPtrTypeDesc = 0x0}}
            pMD = 0x0
            pFD = 0x0
            kind = ENCODE_NONE
            __pException = 0x1
            CURRENT_THREAD = 0x5555557e62a0
            CURRENT_THREAD_AVAILABLE = true
            __pUnCException = 0x0
            __fExceptionCatched = false
            __pThread = 0x5555557e62a0
            __pUnCEntryFrame = 0x7fffffffcff0
            pHelper = 0
            result = 0
            __pThread = 0x5555557e62a0
            CURRENT_THREAD = 0x5555557e62a0
            CURRENT_THREAD_AVAILABLE = true
            frame = {m_gsCookie = 11150031900141442680,
              m_frame = {<FramedMethodFrame> = {<TransitionFrame> = {<Frame> = {<FrameBase> = {
                        _vptr$FrameBase = 0x7ffff6bc2dd0 <vtable for DynamicHelperFrame+16>},
                      m_Next = 0xffffffffffffffff}, <No data fields>}, m_pTransitionBlock = 140737488343224,
                  m_pMD = 0x0}, m_dynamicHelperFrameFlags = 0}}
            pFrame = 0x7fffffffcff0
            exCopy = {static NoTargetFrameSp = 18446744073709551615, ExceptionPointers = {ExceptionRecord = 0x0,
                ContextRecord = 0x0}, TargetFrameSp = 18446744073709551615, RecordsOnStack = false}
            hasCaughtException = false
            ex = <error reading variable>
    #6  0x00007ffff5ec5c27 in DelayLoad_Helper ()
        at /home/sysop/dotnet-runtime/src/coreclr/src/pal/inc/unixasmmacrosamd64.inc:837
    No locals.
    #7  0x00007fff7cf70602 in test ()
    No symbol table info available.
    
  5. changed the title [-]Assert fails (numGenericArgs > 0) when executing typeof(T) in sealed function of generic base class, crossgen2.[/-] [+]Assert fails (numGenericArgs > 0) when executing typeof(T) in a nonvirtual interface method, crossgen2.[/+] on Jun 3, 2020
  6. removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 3, 2020
  7. added this to the 5.0 milestone on Jun 3, 2020
  8. self-assigned this
    on Jun 3, 2020
  9. mangod9 commented on Jun 29, 2020

    @mangod9
    Member

    debugged through why the call to test() is flagged as CORINFO_VIRTUALCALL_STUB rather than CORINFO_CALL. Its due to this check for Version Bubble equivalence between caller and target (VersionsWithMethodBody does contain Base<__Canon>.test(), but not Base.test()). Trying to determine whether this version bubble check needs to be updated.

  10. mangod9 commented on Jul 2, 2020

    @mangod9
    Member

    should now be fixed.

  11. ghost locked as resolved and limited conversation to collaborators on Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions