[RyuJit Wasm] Fix Signature Generation Bug with Un-called methods#125090
[RyuJit Wasm] Fix Signature Generation Bug with Un-called methods#125090adamperlin wants to merge 2 commits intodotnet:mainfrom
Conversation
…ithGCInfo on Wasm, clean up signature index assignment logic
There was a problem hiding this comment.
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 viaWasmLowering.GetSignature. - Add a static dependency from
MethodWithGCInfoto the method’sWasmTypeNodewhen targeting Wasm32. - Simplify signature index assignment in
WasmObjectWriter.RecordMethodSignatureby 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). |
...r/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs
Outdated
Show resolved
Hide resolved
...r/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs
Show resolved
Hide resolved
…yAnalysis/ReadyToRun/MethodWithGCInfo.cs Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
| dependencyList.Add(node, "classMustBeLoadedBeforeCodeIsRun"); | ||
| } | ||
|
|
||
| if (factory.Target.Architecture is TargetArchitecture.Wasm32) |
There was a problem hiding this comment.
| 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.
I don't think this is an unreasonable approach, but |
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. |
#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 addsWasmTypeNodeas a static dependency ofMethodWithGCInfoto make sure we always create a type signature node for every method we compile.