WIP Apply Base Relocs For Webcil in Wasm CoreCLR#126436
Merged
davidwrighton merged 22 commits intodotnet:mainfrom Apr 3, 2026
Merged
WIP Apply Base Relocs For Webcil in Wasm CoreCLR#126436davidwrighton merged 22 commits intodotnet:mainfrom
davidwrighton merged 22 commits intodotnet:mainfrom
Conversation
…X, WASM_FUNCTION_INDEX type relocs
baseRelocsMap in WasmObjectWriter
…-object-writer-runtime-relocs
… segment description after we've recorded all possible base relocs, and we must re-order when we can write the memory import as a result
…ldWebcilDataSegment()
…w Wasm table-based relocs
Contributor
|
Tagging subscribers to this area: @agocke |
adamperlin
commented
Apr 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Implements an initial WebAssembly/Webcil runtime base relocation scheme by emitting PE-style base relocation blocks in the Webcil payload and teaching CoreCLR’s Webcil loader path to apply those relocations (including new Wasm table-base fixups).
Changes:
- Emit a PE-style
.reloc-equivalent Webcil section and encode relocation entries (including new Wasm table-base relocation kinds). - Enable
ApplyBaseRelocationsfor Webcil images and apply both image-base and table-base relocation deltas. - Extend Webcil decoding and documentation to expose base relocation presence and locate relocation data.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/peimagelayout.inl | Adds decoder-dispatched relocation helpers (e.g., SetRelocated, HasBaseRelocations) for PE/Webcil. |
| src/coreclr/vm/peimagelayout.h | Adds temporary table-base offset plumbing and switches SetRelocated to decoder dispatch. |
| src/coreclr/vm/peimagelayout.cpp | Runs base relocations for Webcil and adds handling for Wasm table-base relocation types. |
| src/coreclr/utilcode/webcildecoder.cpp | Exposes Webcil base relocation presence and supports BASERELOC directory-style access. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WebcilEncoder.cs | Minor formatting adjustments in Webcil section header encoding size helper. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Emits Webcil relocation section data and records base relocation entries from certain relocation types. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs | Adds Webcil relocation kinds and maps Wasm table index relocations to file/base-reloc types. |
| src/coreclr/pal/inc/rt/ntimage.h | Defines Webcil-specific base relocation type codes for Wasm table-base fixups. |
| src/coreclr/inc/webcildecoder.h | Adds relocated-state tracking and a HasBaseRelocations API for Webcil. |
| docs/design/mono/webcil.md | Documents Reserved0 usage for base reloc section indexing and the relocation block/entry encoding. |
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
…r.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…r.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
…r.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
When emitting base relocations, webcil section addresses were not yet assigned, leading to a bug where base relocations were not properly offset by the section they apply to. This commit re-orders our base relocation construction/emission so that we construct our base relocations AFTER Webcil sections have been assigned addresses
….com:adamperlin/runtime into adamperlin/wasm-object-writer-runtime-relocs
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
- peimagelayout.inl: Use DECODER_DISPATCH for IsRelocated() so Webcil images correctly report relocated state instead of always FALSE - peimagelayout.cpp: Gate PAL_LOADMarkSectionAsNotNeeded with !TARGET_WASM to avoid operating on Webcil payload pointers - webcildecoder.cpp: Delegate HasDirectoryEntry(BASERELOC) to HasBaseRelocations() for consistent Reserved0 range validation - WasmObjectWriter.cs: Use SortedDictionary for _baseRelocMap to ensure deterministic reloc block emission order - WasmObjectWriter.cs: Replace redundant pattern match on GetFileRelocationType with direct assignment - WasmObjectWriter.cs: Use explicit cast instead of as-cast for WebcilSection, add Debug.Assert for non-negative offset Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
/ba-g Build analysis seems to have hung. Maybe this will unstick it. |
This was referenced Apr 3, 2026
radekdoulik
pushed a commit
to radekdoulik/runtime
that referenced
this pull request
Apr 9, 2026
This PR is currently testable only with future follow on work, but is an implementation for a runtime base relocation scheme for Webcil. The WasmObjectWriter has been updated to emit PE-style base relocs into a `reloc` webcil section (the last section in the webcil payload). The relocations use an encoding identical to that used by PE image base style relocs. New base relocation types have been added to represent "wasm function pointer table base" fixups for wasm32 and wasm64. The Webcil loader path in CoreCLR has been updated to interpret these relocs. In particular `ApplyBaseRelocations` will now run in the Webcil case, and will handle applying both standard image base style relocations and the new table base relocs. The real table base used at load time is not yet being plumbed through; this will eventually be set as a field in the webcil header itself and is dependent on dotnet#126388. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is currently untested, but is a WIP implementation for a runtime base relocation scheme for Webcil.
The WasmObjectWriter has been updated to emit PE-style base relocs into a
relocwebcil section (the last section in the webcil payload). The relocations use an encoding identical to that used by PE image base style relocs. New base relocation types have been added to represent "wasm function pointer table base" fixups for wasm32 and wasm64.The Webcil loader path in CoreCLR has been updated to interpret these relocs. In particular
ApplyBaseRelocationswill now run in the Webcil case, and will handle applying both standard image base style relocations and the new table base relocs. The real table base used at load time is not yet being plumbed through; this will eventually be set as a field in the webcil header itself and is dependent on #126388.