crossgen2: Add Length Prefix to Crossgen-Generated Wasm#127936
crossgen2: Add Length Prefix to Crossgen-Generated Wasm#127936adamperlin wants to merge 2 commits intodotnet:mainfrom
Conversation
Remove now-unused SectionWriter.Params
There was a problem hiding this comment.
Pull request overview
This PR updates the Wasm object writer pipeline so that Wasm function bodies carry their own ULEB128 length prefix in ObjectData, rather than relying on SectionWriter/ObjectWriter to inject prefixes and adjust relocation offsets. It also updates Crossgen2’s Wasm import thunk emission to include the prefix directly in the emitted thunk bytes.
Changes:
- Remove section-writer length-prefix support and the corresponding relocation-offset adjustment in
ObjectWriter. - Update
WasmFunctionBodyrelocation offset accounting to include the newly inlined body-size prefix. - Emit the body-size prefix directly into Crossgen2-generated Wasm import thunks.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Removes Wasm-specific section-writer length-prefix configuration now that prefixes are encoded into ObjectData. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs | Adjusts relocation offsets to account for the function-body length prefix being present in the encoded bytes. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/SectionWriter.cs | Removes length-prefix encoding support from SectionWriter.EmitData and related plumbing. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs | Removes the (Wasm-only) relocation offset adjustment that previously compensated for writer-inserted length prefixes. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WasmEmitter.cs | Prepends the ULEB128 body-size prefix when encoding Wasm import thunks. |
| internal struct SectionWriter | ||
| { | ||
| private readonly ObjectWriter _objectWriter; |
| int bodySize = FunctionBody.EncodeSize(); | ||
| int sizePrefixLength = (int)DwarfHelper.SizeOfULEB128((ulong)bodySize); | ||
| byte[] encodedThunk = new byte[bodySize + sizePrefixLength]; | ||
|
|
AndyAyersMS
left a comment
There was a problem hiding this comment.
Looks reasonable to me. Are you able to validate crossgen2 output with this change?
Yes, for a smaller test case that I have that does include crossgen-generated Wasm in the compilation! I haven't been able to get through an SPC compilation but I think that is due to other issues. |
|
/ba-g infrastructure issues |
#127773 adds length prefixes directly to emitted Wasm code in the JIT. This change is a follow up which adds length prefixes directly to generated wasm import thunks and stubs in crossgen. It also removes the logic in the Object Writer around handling length prefixes, since these will now be encoded in the
ObjectDataitself.