Skip to content

Commit 23a242a

Browse files
committed
[wasm] Make the finalizer slot's portable entrypoint callable from R2R
On FEATURE_PORTABLE_ENTRYPOINTS (wasm) targets, System.GC.RunFinalizers invokes each object's Finalize via a typed call_indirect on the finalizer method's portable entrypoint (PEP). GCInterface_GetNextFinalizableObject returned the raw GetRestoredSlot result, which for a not-yet-prepared method is a cold PEP (_pActualCode == 0, prefers the interpreter). A call_indirect on a cold PEP targets wasm table slot 0 (the reserved null slot) and traps with "null function or function signature mismatch". Make the slot callable explicitly, mirroring the class-constructor slot in MethodTable::CallClassConstructor. EnsurePortableEntryPointIsCallableFromR2R wires the R2R->interpreter thunk (or leaves already-published native code in place) so the call_indirect resolves to real code. This adds the finalizer QCall to the documented "call site makes the target callable before an R2R call_indirect" pattern used by GetMultiCallableAddrOfCode, the cctor slot, the managed main entry, the default ctor, P/Invoke, ExternalMethodFixupWorker, and EnC. Fixes the browser-wasm R2R crash in JIT/Regression b12795 and b38269 in both R2R-corelib mode (interpreted finalizer, wired via the R2R->interpreter thunk) and R2R-full mode (crossgen'd finalizer); the interpreter is unaffected. Same cold-first-call family as dotnet#130634. Fixes dotnet#130839.
1 parent f2281d5 commit 23a242a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎src/coreclr/vm/comutilnative.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,15 @@ extern "C" void* QCALLTYPE GCInterface_GetNextFinalizableObject(QCall::ObjectHan
786786
MethodTable* pMT = target->GetMethodTable();
787787

788788
funcPtr = pMT->GetRestoredSlot(g_pObjectFinalizerMD->GetSlot());
789+
790+
#ifdef FEATURE_PORTABLE_ENTRYPOINTS
791+
// On portable-entrypoint (wasm) targets, RunFinalizers invokes the finalizer via a typed
792+
// call_indirect, so the slot's portable entry point must resolve to real code (native R2R
793+
// code or a correctly-typed interpreter thunk) rather than the temporary precode. The normal
794+
// R2R method-entry fixups perform this for direct calls, but the finalizer slot is fetched
795+
// directly here and so must be made callable explicitly, mirroring CallClassConstructor.
796+
MethodDesc::EnsurePortableEntryPointIsCallableFromR2R(funcPtr);
797+
#endif // FEATURE_PORTABLE_ENTRYPOINTS
789798
}
790799

791800
END_QCALL;

0 commit comments

Comments
 (0)