crossgen2: Add Length Prefix to Crossgen-Generated Wasm#127936
Open
adamperlin wants to merge 2 commits intodotnet:mainfrom
Open
crossgen2: Add Length Prefix to Crossgen-Generated Wasm#127936adamperlin wants to merge 2 commits intodotnet:mainfrom
adamperlin wants to merge 2 commits intodotnet:mainfrom
Conversation
Remove now-unused SectionWriter.Params
Contributor
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. |
Comment on lines
14
to
16
| internal struct SectionWriter | ||
| { | ||
| private readonly ObjectWriter _objectWriter; |
Comment on lines
+28
to
+31
| int bodySize = FunctionBody.EncodeSize(); | ||
| int sizePrefixLength = (int)DwarfHelper.SizeOfULEB128((ulong)bodySize); | ||
| byte[] encodedThunk = new byte[bodySize + sizePrefixLength]; | ||
|
|
AndyAyersMS
reviewed
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#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.