Skip to content

[wasm][coreclr] Implement webcil V1 support in WebcilConverter and readers#126709

Merged
radekdoulik merged 1 commit intodotnet:mainfrom
radekdoulik:fix/webcil-v1-support
Apr 9, 2026
Merged

[wasm][coreclr] Implement webcil V1 support in WebcilConverter and readers#126709
radekdoulik merged 1 commit intodotnet:mainfrom
radekdoulik:fix/webcil-v1-support

Conversation

@radekdoulik
Copy link
Copy Markdown
Member

@radekdoulik radekdoulik commented Apr 9, 2026

PR #126388 bumped the shared webcil version from 0 to 1, we need to update the rest of webcil ecosystem

Changes

  • Webcil.cs: Add TableBase field to managed WebcilHeader struct (32 bytes for V1)
  • WebcilConverter.cs: Parameterize version (default V0), write V0 (28-byte) or V1 (32-byte) header based on webcilVersion parameter. Add version validation and WriteStructure bounds checks.
  • WebcilReader.cs: Read V0 header first (28 bytes), then conditionally read extra 4-byte TableBase for V1. Version-aware SectionDirectoryOffset.
  • webcil-loader.c (Mono): Accept both V0 and V1 headers with proper bounds checking, use correct header size for section offset calculation.

The WebcilConverter defaults to V0, which is what non-R2R builds use. The R2R/crossgen2 path (WasmObjectWriter + WebcilEncoder) produces V1 independently. Both CoreCLR and Mono decoders now handle V0 and V1.

Testing

  • CoreCLR browser-wasm library tests: 474/476 passed (2 skipped, 0 failed)
  • Mono browser-wasm library tests: 469/476 passed (5 pre-existing DateTime failures, 0 webcil-related)

Supersedes #126698

PR dotnet#126388 bumped the shared webcil version from 0 to 1 without updating
the WebcilConverter path, breaking all browser-wasm library tests with
COR_E_ASSEMBLYEXPECTED errors.

Changes:
- Add TableBase field to managed WebcilHeader struct (32 bytes for V1)
- WebcilConverter: parameterize version (default V0), write V0 (28-byte)
  or V1 (32-byte) header based on webcilVersion parameter
- WebcilReader: read V0 header first (28 bytes), then conditionally read
  extra 4-byte TableBase for V1; version-aware SectionDirectoryOffset
- Mono webcil-loader.c: accept both V0 and V1 headers, use correct
  header size for section offset calculation

The WebcilConverter defaults to V0, which is what non-R2R builds use.
The R2R/crossgen2 path (WasmObjectWriter + WebcilEncoder) produces V1
independently. Both CoreCLR and Mono decoders now handle V0 and V1.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 9, 2026 14:27
@radekdoulik radekdoulik added this to the Future milestone Apr 9, 2026
@radekdoulik radekdoulik changed the title Implement webcil V1 support in WebcilConverter and readers [wasm][coreclr] Implement webcil V1 support in WebcilConverter and readers Apr 9, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

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

Fixes browser-wasm test breakage caused by the Webcil header version bump (v0 → v1) by making the managed Webcil converter/reader and Mono loader accept and correctly process both v0 (28-byte) and v1 (32-byte) headers.

Changes:

  • Add TableBase to the managed WebcilHeader layout to support v1’s 32-byte header.
  • Make the managed Webcil converter and reader version-aware (read/write correct header sizes; validate version; adjust section directory offset).
  • Update Mono’s webcil-loader.c to accept both v0 and v1 and compute offsets using the correct header size.

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/tasks/WasmAppBuilder/WebcilConverter.cs Threads a webcilVersion parameter through the MSBuild task wrapper to control header version written.
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilReader.cs Reads v0 header first, conditionally reads v1 TableBase, and adjusts section directory offset based on version.
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs Adds version parameterization and writes v0/v1 headers with bounds checking when serializing.
src/mono/mono/metadata/webcil-loader.c Accepts both header versions with appropriate bounds checks and offset calculation.
src/coreclr/tools/Common/Wasm/Webcil.cs Extends WebcilHeader with TableBase to represent the v1 header layout.

@radekdoulik
Copy link
Copy Markdown
Member Author

/ba-g the build failures are infra issues

❌Remote machine provider issue: Agent failed with exception: Task agent exited with exit code -1073741502 
❌Remote machine provider issue: The remote provider was unable to process the request. ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants