Skip to content

[cDAC][wasm] Native code addresses for portable entry points are not mapped to interpreter code or R2R virtual IPs #134753

Description

@lewing

Description

On FEATURE_PORTABLE_ENTRYPOINTS targets (currently WebAssembly), a method's entry point slot holds a PortableEntryPoint address. The native runtime maps that address to a resolvable code start before handing it to diagnostics:

  • GetInterpreterCodeFromEntryPointIfPresent (src/coreclr/vm/precode.cpp) returns the interpreter bytecode for interpreted methods.
  • GetDiagnosticCodeStartFromEntryPoint (same file, shared by EventPipe method events and RuntimeMethodHandle_GetNativeCode) additionally maps native R2R portable entry points, whose actual code is a function-table index, to the synthetic virtual IP registered through ExecutionManager::AddVirtualIPRange.

The cDAC does neither:

  • RuntimeTypeSystem_1.GetNativeCode returns the raw entry-point slot value.
  • PrecodeStubs_1.GetInterpreterCodeFromInterpreterPrecodeIfPresent only recognizes interpreter StubPrecodes and has no portable-entry-point case, so it returns the PortableEntryPoint address unchanged.

As a result, SOS method data such as DacpMethodDescData.NativeCodeAddr and rejit NativeCodeAddr (SOSDacImpl.cs) should report a PortableEntryPoint address on wasm for both interpreted and R2R methods. That address does not resolve through ExecutionManager lookups (GetCodeBlockHandle, FindVirtualIPRangeSection).

This was found by code inspection while fixing #134145. It has not been reproduced against a live wasm target.

Suggested direction

When the portable-entrypoints feature flag is enabled, mirror the native mapping for a portable entry point:

  1. If the method has interpreter code, return the bytecode start.
  2. Otherwise, if it has a native entry point, map the function-table index to its virtual IP. Use FunctionTableIndexRangeSection data (already read by the wasm stack walk), the owning ReadyToRunInfo.MinVirtualIP, and the containing non-funclet RUNTIME_FUNCTION, matching ExecutionManager::GetWasmVirtualIPFromFunctionTableIndex.

The pieces are already exposed: Data.PortableEntryPoint (used by NonVirtualEntry2MethodDesc), FunctionTableIndexRangeSection, and the virtual-IP range list added in #133917. The contract docs under docs/design/datacontracts would need a matching update.

Note

This issue was drafted with GitHub Copilot.

Activity

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