[wasm][coreclr] Fix browser-wasm library tests broken by webcil V1 version bump#126698
[wasm][coreclr] Fix browser-wasm library tests broken by webcil V1 version bump#126698radekdoulik wants to merge 1 commit intodotnet:mainfrom
Conversation
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>
|
Tagging subscribers to this area: @agocke, @dotnet/runtime-infrastructure |
1 similar comment
|
Tagging subscribers to this area: @agocke, @dotnet/runtime-infrastructure |
|
@pavelsavara this is quick fix for the libraries test regression to unblock the libraries tests work, could I leave the V1 support to you? |
There was a problem hiding this comment.
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
WebcilReaderto only accept Webcil major version0(reject v1 for now). - Force
WebcilConverterto emit Webcil major version0in 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. |
| 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; |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
|
@radekdoulik let's revert the offending PR instead |
|
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. |
|
R2R is not the only scenario. |
|
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. |
|
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. |
|
ok, the library tests pass here, which is good. lets close it now and wait for #126709 |
…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>
Note
This PR description was AI/Copilot-generated.
PR #126388 bumped
WC_VERSION_MAJORfrom 0 to 1 inWebcil.cs. That constant is shared by both the crossgen2 R2R path (fully updated for V1) and theWebcilConverterbuild task (still writes V0 28-byte headers). The mismatch caused the C++webcildecoderto misparse section headers at offset 32 instead of 28, breaking all browser-wasm library tests withCOR_E_ASSEMBLYEXPECTED.Pin
WebcilConverterandWebcilReaderto V0 until full V1 support is added to the managed converter and wasm wrapper.