Skip to content

SIGSEGV in type loader when a struct wrapping a CRTP-constrained struct is loaded before its field type #130661

Closed

Description

@Xenoprimate

Description

Loading Res before Wrapper avoids the crash entirely, so the failure is load-order dependent. Reproduces on Linux x64 on .NET 9.0.0 through 10.0.9.

Real-world trigger: NUnit test discovery (RuntimeModule.GetDefinedTypes() loads types in TypeDef order), where merely renaming a test file changed the load order and crashed the test host.

Reproduction Steps

Single file in a standard C# project:

using System;
Console.Out.Write("Loading..."); Console.Out.Flush();
var t = Type.GetType("Wrapper", throwOnError: true)!;
Console.WriteLine(" OK: " + t.Name);
public interface IResource<TSelf> where TSelf : IResource<TSelf>;
public readonly struct Handle<TResource> where TResource : IResource<TResource>;
public readonly struct Res : IResource<Res> { readonly Handle<Res> _handle; }
public readonly struct Wrapper { readonly Res _res; }

Project file for posterity:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

Expected behavior

Run the program and see "OK: Wrapper" on console output.

Actual behavior

Segmentation fault

Regression?

Tried with .NET 9 and .NET 10; fails on both; haven't tried earlier SDK versions

Known Workarounds

No response

Configuration

dotnet --info

.NET SDK:
 Version:           10.0.301
 Commit:            96856fd726
 Workload version:  10.0.300-manifests.b0c14421
 MSBuild version:   18.6.4+96856fd72

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  25.10
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/lib/dotnet/sdk/10.0.301/

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
  Version:      10.0.9
  Architecture: x64
  Commit:       901ca94124

.NET SDKs installed:
  9.0.118 [/usr/lib/dotnet/sdk]
  10.0.109 [/usr/lib/dotnet/sdk]
  10.0.201 [/usr/lib/dotnet/sdk]
  10.0.301 [/usr/lib/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.17 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.5 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.9 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.17 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.5 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.9 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_BUNDLE_EXTRACT_BASE_DIR           [/home/ben/.cache/dotnet_bundle_extract]

global.json file:
  Not found

Other information

No response

Activity

  1. added
    untriaged
    on Jul 14, 2026
  2. dotnet-policy-service commented on Jul 14, 2026

    @dotnet-policy-service
    Contributor

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

  3. MichalStrehovsky commented on Jul 14, 2026

    @MichalStrehovsky
    Member

    Hits an assert while we do SysV ABI classification which explains why it's Unix-like only:

    #0  DBG_DebugBreak () at /home/michals/runtime/src/coreclr/pal/src/arch/amd64/debugbreak.S:9
    #1  0x00007ffff748db3b in DebugBreak () at /home/michals/runtime/src/coreclr/pal/src/debug/debug.cpp:414
    #2  0x00007ffff6ed45cb in FieldDesc::GetSize (this=0x7fff7990b148, pMTOfValueTypeField=0x0)
        at /home/michals/runtime/src/coreclr/vm/field.cpp:697
    #3  0x00007ffff6fb3cc8 in (anonymous namespace)::HasImpliedRepeatedFields (pMT=0x7fff7990b4c8,
        pFirstFieldValueType=0x0) at /home/michals/runtime/src/coreclr/vm/methodtable.cpp:2007
    #4  0x00007ffff6fb2536 in MethodTable::ClassifyEightBytesWithManagedLayout (this=0x7fff7990b4c8,
        helperPtr=0x7fffffff6a88, nestingLevel=1, startOffsetOfStruct=0, useNativeLayout=false, pByValueClassCache=0x0)
        at /home/michals/runtime/src/coreclr/vm/methodtable.cpp:2158
    #5  0x00007ffff6fb2959 in MethodTable::ClassifyEightBytesWithManagedLayout (this=0x7fff7990b5a8,
        helperPtr=0x7fffffff6a88, nestingLevel=0, startOffsetOfStruct=0, useNativeLayout=false,
        pByValueClassCache=0x7fffffff8a78) at /home/michals/runtime/src/coreclr/vm/methodtable.cpp:2224
    #6  0x00007ffff6fb1337 in MethodTable::ClassifyEightBytes (this=0x7fff7990b5a8, helperPtr=0x7fffffff6a88,
        useNativeLayout=false, pByValueClassCache=0x7fffffff8a78)
        at /home/michals/runtime/src/coreclr/vm/methodtable.cpp:2042
    #7  0x00007ffff7232b52 in MethodTableBuilder::SystemVAmd64CheckForPassStructInRegister (this=0x7fffffffa700,
        pByValueClassCache=0x7fffffff8a78) at /home/michals/runtime/src/coreclr/vm/methodtablebuilder.cpp:9000
    #8  0x00007ffff721e34e in MethodTableBuilder::BuildMethodTableThrowing (this=0x7fffffffa700,
        pAllocator=0x7ffff776dc10 <g_pSystemDomainMemory+16>, pLoaderModule=0x7fff797898f8, pModule=0x7fff797898f8,
        cl=33554438, pBuildingInterfaceList=0x0, initialLayoutInfo=0x7fffffffa858, pParentMethodTable=0x7fff778651c0,
        bmtGenericsInfo=0x7fffffffa8c0, parentInst=..., cBuildingInterfaceList=0)
        at /home/michals/runtime/src/coreclr/vm/methodtablebuilder.cpp:1879
    #9  0x00007ffff725055a in ClassLoader::CreateTypeHandleForTypeDefThrowing (pModule=0x7fff797898f8, cl=33554438,
        inst=..., pamTracker=0x7fffffffae80) at /home/michals/runtime/src/coreclr/vm/methodtablebuilder.cpp:13154
    #10 0x00007ffff6e66149 in ClassLoader::CreateTypeHandleForTypeKey (pKey=0x7fffffffbb88, pamTracker=0x7fffffffae80)
        at /home/michals/runtime/src/coreclr/vm/clsload.cpp:2644
    #11 0x00007ffff6e65cf2 in ClassLoader::DoIncrementalLoad (pTypeKey=0x7fffffffbb88, typeHnd=...,
        currentLevel=CLASS_LOAD_BEGIN) at /home/michals/runtime/src/coreclr/vm/clsload.cpp:2591
    

    This is very likely a duplicate of #127696.

  4. added this to the 11.0.0 milestone on Jul 14, 2026
  5. removed
    untriaged
    on Jul 14, 2026
  6. MichalStrehovsky commented on Jul 27, 2026

    @MichalStrehovsky
    Member

    This was fixed in #130088 and the regression test is inlined into src/tests/Loader/classloader/regressions/GitHub_127696/GitHub_127696.cs.

  7. locked and limited conversation to collaborators on Aug 27, 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

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions