Skip to content

[RyuJit Wasm] Fix Signature Generation Bug with Un-called methods#125090

Open
adamperlin wants to merge 2 commits intodotnet:mainfrom
adamperlin:adamperlin/wasm-crossgen-method-typenode-deps
Open

[RyuJit Wasm] Fix Signature Generation Bug with Un-called methods#125090
adamperlin wants to merge 2 commits intodotnet:mainfrom
adamperlin:adamperlin/wasm-crossgen-method-typenode-deps

Conversation

@adamperlin
Copy link
Contributor

@adamperlin adamperlin commented Mar 3, 2026

#124685 changed our signature recording logic in favor of using WasmTypeNodes in the dependency graph. However, we do not create these nodes currently unless they are the target of a relocation, but every compiled method will need one. This PR adds WasmTypeNode as a static dependency of MethodWithGCInfo to make sure we always create a type signature node for every method we compile.

…ithGCInfo on Wasm, clean up signature index assignment logic
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ensures WebAssembly ReadyToRun compilation always materializes a WasmTypeNode (type signature) for every compiled managed method, fixing missing signature/type-section entries for methods that were compiled but never referenced by relocations.

Changes:

  • Add a NodeFactory.WasmTypeNode(MethodDesc) overload that derives the signature via WasmLowering.GetSignature.
  • Add a static dependency from MethodWithGCInfo to the method’s WasmTypeNode when targeting Wasm32.
  • Simplify signature index assignment in WasmObjectWriter.RecordMethodSignature by using _uniqueSignatures.Count.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs Adds a factory helper to create/cache WasmTypeNode from a MethodDesc signature.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs Ensures each compiled method depends on (and thus emits/records) its Wasm signature node.
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs Uses dictionary count as the next signature index (removes redundant counter).

…yAnalysis/ReadyToRun/MethodWithGCInfo.cs

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 3, 2026 01:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

dependencyList.Add(node, "classMustBeLoadedBeforeCodeIsRun");
}

if (factory.Target.Architecture is TargetArchitecture.Wasm32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (factory.Target.Architecture is TargetArchitecture.Wasm32)
if (factory.Target.IsWasm)

In general, we should use this accessor over TargetArchitecture.Wasm32 so that it is easier to add Wasm64 later.

@SingleAccretion
Copy link
Contributor

WasmTypeNode as a static dependency of MethodWithGCInfo to make sure we always create a type signature node for every method we compile.

I don't think this is an unreasonable approach, but MethodWithGCInfo is not going to be the only node that needs a signature in the long run. All nodes that may inspire imports need a signature. Hand-generated WASM helpers will need a signature. It is going to be quite pervasive, especially for NAOT. Still better than handling it implicitly in the object writer?

@adamperlin
Copy link
Contributor Author

adamperlin commented Mar 3, 2026

WasmTypeNode as a static dependency of MethodWithGCInfo to make sure we always create a type signature node for every method we compile.

I don't think this is an unreasonable approach, but MethodWithGCInfo is not going to be the only node that needs a signature in the long run. All nodes that may inspire imports need a signature. Hand-generated WASM helpers will need a signature. It is going to be quite pervasive, especially for NAOT. Still better than handling it implicitly in the object writer?

This is a good point, and I wasn't considering all the possible NAOT nodes nodes that may need to have this new dependency. The reason I decided on this approach was for clarity -- it seemed clearer to have all type signatures originate in the dependency graph and to simply process them in the object writer, as opposed to having some originate in the graph (for reloc targets) and others in the object writer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants