Skip to content

Move shared WASM logic to base writer - #131778

Draft
jtschuster wants to merge 9 commits into
wasm-webcil-object-writerfrom
wasm-writer-shared-implementation
Draft

Move shared WASM logic to base writer#131778
jtschuster wants to merge 9 commits into
wasm-webcil-object-writerfrom
wasm-writer-shared-implementation

Conversation

@jtschuster

@jtschuster jtschuster commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

This is the fourth PR in the WASM object-writer stack and builds on #131772.

  • Move shared WebAssembly section mapping, ordering, and construction into WasmObjectWriter.
  • Move shared symbol/index-space, signature/funclet, typed-section row, stub, and symbol-table orchestration into the base writer.
  • Add a virtual data-section factory so WebCilObjectWriter can continue creating embedded WebcilSection instances.
  • Keep WebCIL headers, alignment, data layout, memory sizing, imports/exports/globals policy, payload emission, and relocation handling in WebCilObjectWriter.
  • Include defined Table and Memory sections in standard WebAssembly emission order for future derived writers.

This preserves current WebCIL behavior while leaving the generic writer implementation ready to be shared with a second WebAssembly object writer.

Stack

  1. Extract WASM section model #131770 — Extract WASM section model
  2. Add typed self-counting WASM sections #131771 — Add typed self-counting WASM sections
  3. Rename WasmObjectWriter to WebCilObjectWriter #131772 — Introduce WebCIL object writer type
  4. Move shared WASM logic to base writer #131778 — Move shared WASM logic to base writer (this PR)

Validation

  • ./build.sh clr+libs+libs.pretest+host completed with 0 warnings and 0 errors.
  • ILCompiler.ReadyToRun.Tests built with 0 warnings and 0 errors.
  • The focused WasmWebcilModule test ran exactly once and passed.
  • git diff --check passed.

Note

This PR description was generated with GitHub Copilot.


Stack created with GitHub Stacks CLIGive Feedback 💬

jtschuster and others added 4 commits August 3, 2026 13:41
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

jtschuster and others added 5 commits August 7, 2026 12:44
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 7, 2026 21:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors the WebAssembly object writer stack by extracting shared section creation/mapping, symbol/index-space management, and emission-order orchestration into a new WasmObjectWriter base class, while keeping WebCIL-specific behavior in WebCilObjectWriter.

Changes:

  • Introduces WasmObjectWriter as the shared base implementation for WASM section construction, symbol management, and emission ordering.
  • Updates WebCilObjectWriter to delegate shared behaviors to the base writer and provide a WebCIL-specific data-section factory.
  • Adjusts WASM section interfaces/implementation details and updates the ReadyToRun project to compile the new base writer.

Reviewed changes

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

File Description
src/coreclr/tools/Common/Compiler/ObjectWriter/WebCilObjectWriter.cs Moves shared WASM writer logic to the base class and adds an override factory for WebCIL data sections; retains WebCIL-specific import/export/global/layout behavior.
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs Adds new shared base writer encapsulating section typing/mapping, symbol/index-space management, and section emission order.
src/coreclr/tools/Common/Compiler/ObjectWriter/Wasm/WasmSection.cs Makes WASM emission/section interfaces explicitly internal and removes redundant bool initialization.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj Adds the new base writer to compilation inputs (but currently duplicates the WebCIL writer include).

<Compile Include="..\..\Common\Compiler\ObjectWriter\Wasm\WebcilSection.cs" Link="Compiler\ObjectWriter\Wasm\WebcilSection.cs" />
<Compile Include="..\..\Common\Compiler\ObjectWriter\WebCilObjectWriter.cs" Link="Compiler\ObjectWriter\WebCilObjectWriter.cs" />
<Compile Include="..\..\Common\Compiler\ObjectWriter\WasmObjectWriter.cs" Link="Compiler\ObjectWriter\WasmObjectWriter.cs" />
<Compile Include="..\..\Common\Compiler\ObjectWriter\WebCilObjectWriter.cs" Link="Compiler\ObjectWriter\WebCilObjectWriter.cs" />
Comment on lines +703 to +706
internal const int StackPointerGlobalIndex = 0;
internal const int ImageBaseGlobalIndex = 1;
internal const int TableBaseGlobalIndex = 2;
internal const int AsyncContinuationGlobalIndex = 3;
Comment on lines +77 to +83
if (_sectionEmitOrder is null)
{
_sectionEmitOrder = _sectionOrder
.Where(name => _sections.Contains(name))
.Select(name => _sections.GetSectionIndex(name))
.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants