Skip to content

[wasm][coreclr] Fix browser-wasm library tests broken by webcil V1 version bump#126698

Closed
radekdoulik wants to merge 1 commit intodotnet:mainfrom
radekdoulik:fix/webcil-v0-libs-tests
Closed

[wasm][coreclr] Fix browser-wasm library tests broken by webcil V1 version bump#126698
radekdoulik wants to merge 1 commit intodotnet:mainfrom
radekdoulik:fix/webcil-v0-libs-tests

Conversation

@radekdoulik
Copy link
Copy Markdown
Member

Note

This PR description was AI/Copilot-generated.

PR #126388 bumped WC_VERSION_MAJOR from 0 to 1 in Webcil.cs. That constant is shared by both the crossgen2 R2R path (fully updated for V1) and the WebcilConverter build task (still writes V0 28-byte headers). The mismatch caused the C++ webcildecoder to misparse section headers at offset 32 instead of 28, breaking all browser-wasm library tests with COR_E_ASSEMBLYEXPECTED.

Pin WebcilConverter and WebcilReader to V0 until full V1 support is added to the managed converter and wasm wrapper.

WebcilConverter and WebcilReader still use the V0 28-byte header format
but were picking up WC_VERSION_MAJOR=1 from the shared Webcil.cs constant,
causing webcildecoder to misparse section headers. Pin both to V0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@radekdoulik radekdoulik added this to the Future milestone Apr 9, 2026
Copilot AI review requested due to automatic review settings April 9, 2026 11:16
@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.

1 similar comment
@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.

@radekdoulik
Copy link
Copy Markdown
Member Author

@pavelsavara this is quick fix for the libraries test regression to unblock the libraries tests work, could I leave the V1 support to you?

@radekdoulik radekdoulik changed the title Fix browser-wasm library tests broken by webcil V1 version bump [wasm][coreclr] Fix browser-wasm library tests broken by webcil V1 version bump Apr 9, 2026
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

Pins the managed Webcil build-task tooling back to Webcil v0 to avoid generating/accepting “v1-labeled” images that still use the v0 (28-byte) header layout, which breaks browser-wasm library tests after WC_VERSION_MAJOR was bumped to 1 elsewhere.

Changes:

  • Force WebcilReader to only accept Webcil major version 0 (reject v1 for now).
  • Force WebcilConverter to emit Webcil major version 0 in the header.

Reviewed changes

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

File Description
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilReader.cs Pins header validation to Webcil v0 major version.
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs Pins emitted header major version to Webcil v0.

Comment on lines 81 to 85
if (header.Id != WebcilConstants.WEBCIL_MAGIC
|| header.VersionMajor != WebcilConstants.WC_VERSION_MAJOR
|| header.VersionMajor != 0 // WASM-TODO: add webcil V1 support
|| header.VersionMinor != WebcilConstants.WC_VERSION_MINOR)
{
return false;
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadHeader() returning false on a version mismatch causes the constructor to throw "Stream does not contain a valid Webcil file". With Webcil v1 now existing, a v1 image is valid but unsupported here, so the exception is misleading. Consider detecting the version mismatch explicitly and throwing a BadImageFormatException (or similar) that reports the unsupported version (e.g., major/minor) to make failures actionable.

Copilot uses AI. Check for mistakes.
Comment on lines 118 to 122
WebcilHeader header = default;
header.Id = WebcilConstants.WEBCIL_MAGIC;
header.VersionMajor = WebcilConstants.WC_VERSION_MAJOR;
header.VersionMajor = 0; // WASM-TODO: add webcil V1 support
header.VersionMinor = WebcilConstants.WC_VERSION_MINOR;
header.CoffSections = (ushort)coffHeader.NumberOfSections;
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coding 0 for VersionMajor here works, but it introduces a magic number that’s now duplicated with WebcilReader. To keep this easier to update when v1 support is added, consider introducing a named constant in this project (e.g., const ushort SupportedWebcilVersionMajor = 0) and using it in both reader and converter.

Copilot uses AI. Check for mistakes.
Comment on lines 81 to 83
if (header.Id != WebcilConstants.WEBCIL_MAGIC
|| header.VersionMajor != WebcilConstants.WC_VERSION_MAJOR
|| header.VersionMajor != 0 // WASM-TODO: add webcil V1 support
|| header.VersionMinor != WebcilConstants.WC_VERSION_MINOR)
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coding 0 for VersionMajor is intentional for now, but it creates a duplicated magic number (also in WebcilConverter). Consider using a shared named constant (within this project) for the supported major version to reduce the chance of future inconsistencies when v1 support is implemented.

Copilot uses AI. Check for mistakes.
@pavelsavara
Copy link
Copy Markdown
Member

@radekdoulik let's revert the offending PR instead
@davidwrighton would know what needs to be fixed in the webcildecoder before merging his PR again

@davidwrighton
Copy link
Copy Markdown
Member

I'd rather see a PR which just moves WC_VERSION_MAJOR back to zero. Or this PR. The only change I'm going to do after a revert would likely be to make these tasks be version 0 specific, since I don't think they are relevant in the Coreclr path.

@pavelsavara
Copy link
Copy Markdown
Member

R2R is not the only scenario.
The webCIL wrapper/covertor is used by WASM SDK to conver IL only assemblies for both VMs.
a) we could give it a version parameter to produce different layouts for each VM
b) teach both VMs to accept the new layout

@radekdoulik
Copy link
Copy Markdown
Member Author

We discussed it with @pavelsavara offline before and we will try to add V1 support to the rest of webcil ecosystem. I will open another PR for it.

@radekdoulik
Copy link
Copy Markdown
Member Author

It is implemented and I am now testing it.

Remaining question is whether to let mono write and use V1 files now, or whether leave it at V0. @lewing @pavelsavara what is your opinion on that?

@pavelsavara
Copy link
Copy Markdown
Member

It is implemented and I am now testing it.

Remaining question is whether to let mono write and use V1 files now, or whether leave it at V0. @lewing @pavelsavara what is your opinion on that?

Keep mono on V0 is easier because it would not force re-wrapping of existing (CDN) deployed binaries in Net11.

@radekdoulik
Copy link
Copy Markdown
Member Author

ok, the library tests pass here, which is good. lets close it now and wait for #126709

radekdoulik added a commit that referenced this pull request Apr 9, 2026
…aders (#126709)

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants