Skip to content

Assert failure: pMD->IsCtor() #114933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BruceForstall opened this issue Apr 22, 2025 · 11 comments · Fixed by #115009
Closed

Assert failure: pMD->IsCtor() #114933

BruceForstall opened this issue Apr 22, 2025 · 11 comments · Fixed by #115009
Labels
Milestone

Comments

@BruceForstall
Copy link
Member

Running 'PMI' on Dia2Lib.dll hits an assert. This causes the runtime superpmi-collect to fail the SuperPMI collect libraries pmi linux x64 checked collection job:

https://dev.azure.com/dnceng/internal/_build/results?buildId=2692581&view=logs&j=5562265b-363f-5c64-5cff-7b508c285721

To repro, build the https://github.com/dotnet/jitutils repo (clone, then run ./bootstrap.sh). Then, from a dotnet/runtime artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root directory:

~/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root$ ./corerun ~/gh/jitutils/bin/pmi.dll DRIVEALL Dia2Lib.dll
DRIVEALL: Invoking /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun /home/brucefo/gh/jitutils/bin/pmi.dll PREPALL Dia2Lib.dll 0
PrepAll for Dia2Lib
Start type Dia2Lib.DiaSourceClass
PREPALL type# 0 method# 0 Dia2Lib.DiaSourceClass::get_lastError
Assert failure(PID 71552 [0x00011780], Thread: 71552 [0x11780]): pMD->IsCtor()    File: /home/brucefo/gh/runtime/src/coreclr/vm/ecall.cpp:350    Image: /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun
Current Method: 0 nextMethodToPrep: 1
DRIVEALL: Invoking /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun /home/brucefo/gh/jitutils/bin/pmi.dll PREPALL Dia2Lib.dll 2
PrepAll for Dia2Lib
Start type Dia2Lib.DiaSourceClass
PREPALL type# 0 method# 2 Dia2Lib.DiaSourceClass::loadAndValidateDataFromPdb
Assert failure(PID 71568 [0x00011790], Thread: 71568 [0x11790]): pMD->IsCtor()    File: /home/brucefo/gh/runtime/src/coreclr/vm/ecall.cpp:350    Image: /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun
Current Method: 2 nextMethodToPrep: 3
DRIVEALL: Invoking /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun /home/brucefo/gh/jitutils/bin/pmi.dll PREPALL Dia2Lib.dll 4
PrepAll for Dia2Lib
Start type Dia2Lib.DiaSourceClass
PREPALL type# 0 method# 4 Dia2Lib.DiaSourceClass::loadDataFromIStream
Assert failure(PID 71579 [0x0001179b], Thread: 71579 [0x1179b]): pMD->IsCtor()    File: /home/brucefo/gh/runtime/src/coreclr/vm/ecall.cpp:350    Image: /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun
Current Method: 4 nextMethodToPrep: 5
DRIVEALL: Invoking /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun /home/brucefo/gh/jitutils/bin/pmi.dll PREPALL Dia2Lib.dll 6
PrepAll for Dia2Lib
Start type Dia2Lib.DiaSourceClass
PREPALL type# 0 method# 6 Dia2Lib.DiaSourceClass::loadDataFromCodeViewInfo
Assert failure(PID 71590 [0x000117a6], Thread: 71590 [0x117a6]): pMD->IsCtor()    File: /home/brucefo/gh/runtime/src/coreclr/vm/ecall.cpp:350    Image: /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun
Current Method: 6 nextMethodToPrep: 7
DRIVEALL: Invoking /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun /home/brucefo/gh/jitutils/bin/pmi.dll PREPALL Dia2Lib.dll 8
PrepAll for Dia2Lib
Start type Dia2Lib.DiaSourceClass
PREPALL type# 0 method# 8 Dia2Lib.DiaSourceClass::IDiaDataSource3_get_lastError
Assert failure(PID 71602 [0x000117b2], Thread: 71602 [0x117b2]): pMD->IsCtor()    File: /home/brucefo/gh/runtime/src/coreclr/vm/ecall.cpp:350    Image: /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun
Current Method: 8 nextMethodToPrep: 9
DRIVEALL: Invoking /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun /home/brucefo/gh/jitutils/bin/pmi.dll PREPALL Dia2Lib.dll 10
PrepAll for Dia2Lib
Start type Dia2Lib.DiaSourceClass
PREPALL type# 0 method# 10 Dia2Lib.DiaSourceClass::IDiaDataSource3_loadAndValidateDataFromPdb
Assert failure(PID 71614 [0x000117be], Thread: 71614 [0x117be]): pMD->IsCtor()    File: /home/brucefo/gh/runtime/src/coreclr/vm/ecall.cpp:350    Image: /home/brucefo/gh/runtime/artifacts/tests/coreclr/linux.x64.Checked/Tests/Core_Root/corerun
Current Method: 10 nextMethodToPrep: 11

@dotnet/jit-contrib

@BruceForstall BruceForstall added arch-x64 area-VM-coreclr blocking-clean-ci-optional Blocking optional rolling runs os-linux Linux OS (any supported distro) labels Apr 22, 2025
@BruceForstall BruceForstall added this to the 10.0.0 milestone Apr 22, 2025
Copy link
Contributor

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

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Apr 24, 2025

I see what is going on here, but it involves the application of MethodImpl(MethodImplOptions.InternalCall) to interface methods - which hasn't been needed since at least .NET Framework 3.5. I don't see why this hasn't been triggering for a long time.

@jkotas Can you shed some light on the code path below? The path is being taken for a non-ctor MethodDesc, a COM interface getter in this case. TlbImp always marks interface methods with the MethodImplOptions.InternalCall so I'm unclear why this assert isn't always triggered.

// COM imported classes have special constructors
if (pMT->IsComObjectType()
#ifdef FEATURE_COMINTEROP
&& (g_pBaseCOMObject == NULL || pMT != g_pBaseCOMObject)
#endif // FEATURE_COMINTEROP
)
{
if (pfSharedOrDynamicFCallImpl)
*pfSharedOrDynamicFCallImpl = TRUE;
// This has to be tlbimp constructor
_ASSERTE(pMD->IsCtor());
// FCComCtor does not need to be in the fcall hashtable since it does not erect frame.
return GetEEFuncEntryPoint(FCComCtor);
}

@AaronRobinsonMSFT
Copy link
Member

Just to be clear, this seems to work if I remove the assert. I'm unclear why this work at all since this is always returning FCComCtor.

@AaronRobinsonMSFT AaronRobinsonMSFT removed os-linux Linux OS (any supported distro) arch-x64 labels Apr 24, 2025
@jkotas
Copy link
Member

jkotas commented Apr 24, 2025

What's the stacktrace of the failure?

Regular interface methods are abstract. They do not have an implementation, and no code should be asking for the implementation. I think that the problem is somewhere in the code that ends up calling this method.

@jkotas
Copy link
Member

jkotas commented Apr 24, 2025

If this is hit on Linux only, it is likely inconsistent FEATURE_COMINTEROP ifdefs.

We have the whole special handling ifdefed out here:

#ifdef FEATURE_COMINTEROP
if (fIsClassComImport || bmtProp->fComEventItfType)
{
// ComImport classes have methods which are just used
// for implementing all interfaces the class supports
type = mcComInterop;
// constructor is special
if (IsMdRTSpecialName(dwMemberAttrs))
{
// Note: Method name (.ctor) will be checked in code:ValidateMethods
type = mcFCall;
}
}
else
#endif //FEATURE_COMINTEROP
, but it is partially enabled in the ecall.cpp code that you have linked.

@AaronRobinsonMSFT
Copy link
Member

If this is hit on Linux only, it is likely inconsistent FEATURE_COMINTEROP ifdefs.

Right, I see the issue now. Thanks.

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Apr 24, 2025

@BruceForstall This is an invalid codepath on non-Windows. PMI is attempting to generate methods for a COM activation class (i.e. Dia2Lib.DiaSourceClass). PMI shouldn't be touching this assembly on non-Windows. After #115009 is merged in, the following error will occur for PMI.

System.PlatformNotSupportedException: COM is not supported
   at System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation)
   at System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(RuntimeMethodHandle method)
   at PrepareBase.TryPrepareMethod(Type type, MethodBase method, TimeSpan& elapsedFunc) in .../src/jitutils/src/pmi/pmi.cs:line 444

Copy link
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

@AaronRobinsonMSFT
Copy link
Member

A way to detect this case would be to look for classes that are marked with ComImport. If so, they should be ignored on non-Windows.

@BruceForstall
Copy link
Member Author

PMI generally handles thrown exceptions fine, and we don't really expect a PMI run to be clean of exceptions. But assertions cause more problems, and are unexpected. It looks like #115009 will fix the problem for us.

@AaronRobinsonMSFT
Copy link
Member

But assertions cause more problems, and are unexpected.

Ah. That is a very helpful detail, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
3 participants