Add WASM_MEMORY_ADDR_REL_LEB Relocation Type#126676
Open
adamperlin wants to merge 7 commits intodotnet:mainfrom
Open
Add WASM_MEMORY_ADDR_REL_LEB Relocation Type#126676adamperlin wants to merge 7 commits intodotnet:mainfrom
WASM_MEMORY_ADDR_REL_LEB Relocation Type#126676adamperlin wants to merge 7 commits intodotnet:mainfrom
Conversation
- This is used to make loads/stores more efficient. loads/stores have an offset baked into them, so instead of global.get 1 i32.const <reloc> add i32.load We can do global.get 1 i32.load offset=<reloc> Overall this saves 3 bytes of space per load from an RVA relative address
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new WebAssembly relocation kind to represent an image-base-relative memory offset encoded as ULEB128, enabling R2R scenarios where the relocation can be used directly as the offset immediate of a load/store (paired with global.get $__image_base).
Changes:
- Introduces
WASM_MEMORY_ADDR_REL_LEBinCorInfoRelocandRelocType, plus the managed JIT-interface mapping. - Extends the Wasm object writer relocation resolver to apply
WASM_MEMORY_ADDR_REL_LEB. - Refactors Wasm instruction encoding to allow memory-arg offsets to be either constants or relocatable symbols; adds
I32.LoadWithRVAOffset(...). - Bumps the JIT/EE versioning GUID for the interface change.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs | Adds new CorInfoReloc enum member for wasm relative memory offset (ULEB). |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Maps new CorInfoReloc to RelocType. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Adds relocation resolution logic for WASM_MEMORY_ADDR_REL_LEB. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs | Generalizes memory-arg encoding to support relocatable offsets; adds helper API. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs | Adds RelocType value and read/write/size support for the new relocation. |
| src/coreclr/inc/jiteeversionguid.h | Updates JIT/EE version GUID due to interface change. |
| src/coreclr/inc/corinfo.h | Adds the native CorInfoReloc enum member. |
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs
Outdated
Show resolved
Hide resolved
This was referenced Apr 9, 2026
Open
…n.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…erlin/runtime into adamperlin/wasm-addr-rel-leb-reloc
3197172 to
bddab45
Compare
kg
approved these changes
Apr 9, 2026
kg
reviewed
Apr 9, 2026
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
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 contains one of @davidwrighton's commits extracted from #126662 to reduce the PR size and complexity. It adds a relocation type that is essentially
R_WASM_MEMORY_ADDR_REL_LEB, so that a relocation corresponding to a relative offset from r2rimageBasecan be used directly as theoffsetin a load, like:The functionality isn't used yet, but will be in #126662.