Skip to content

crossgen2: Add Length Prefix to Crossgen-Generated Wasm#127936

Open
adamperlin wants to merge 2 commits intodotnet:mainfrom
adamperlin:adamperlin/crossgen-wasm-emitter-length-prefix
Open

crossgen2: Add Length Prefix to Crossgen-Generated Wasm#127936
adamperlin wants to merge 2 commits intodotnet:mainfrom
adamperlin:adamperlin/crossgen-wasm-emitter-length-prefix

Conversation

@adamperlin
Copy link
Copy Markdown
Contributor

@adamperlin adamperlin commented May 8, 2026

#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 ObjectData itself.

Copilot AI review requested due to automatic review settings May 8, 2026 00:20
@github-actions github-actions Bot added the area-crossgen2-coreclr only use for closed issues label May 8, 2026
@adamperlin adamperlin added this to the 11.0.0 milestone May 8, 2026
@adamperlin adamperlin requested a review from davidwrighton May 8, 2026 00:20
Copy link
Copy Markdown
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

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 WasmFunctionBody relocation 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];

Comment thread src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs Outdated
@adamperlin adamperlin changed the title crossgen2: Add Length Prefix to Wasm Import Thunks crossgen2: Add Length Prefix to Crossgen-Generated Wasm May 8, 2026
@adamperlin adamperlin requested a review from AndyAyersMS May 8, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-crossgen2-coreclr only use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants