Skip to content

Add WASM_MEMORY_ADDR_REL_LEB Relocation Type#126676

Open
adamperlin wants to merge 7 commits intodotnet:mainfrom
adamperlin:adamperlin/wasm-addr-rel-leb-reloc
Open

Add WASM_MEMORY_ADDR_REL_LEB Relocation Type#126676
adamperlin wants to merge 7 commits intodotnet:mainfrom
adamperlin:adamperlin/wasm-addr-rel-leb-reloc

Conversation

@adamperlin
Copy link
Copy Markdown
Contributor

@adamperlin adamperlin commented Apr 9, 2026

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 r2r imageBase can be used directly as the offset in a load, like:

global.get $imageBase
i32.load align=... offset=<reloc>

The functionality isn't used yet, but will be in #126662.

davidwrighton and others added 3 commits April 8, 2026 14:58
 - 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
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

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_LEB in CorInfoReloc and RelocType, 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.

…n.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 9, 2026 16:25
@adamperlin adamperlin requested review from davidwrighton and kg April 9, 2026 16:27
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

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

Copilot AI review requested due to automatic review settings April 9, 2026 20:29
@adamperlin adamperlin force-pushed the adamperlin/wasm-addr-rel-leb-reloc branch from 3197172 to bddab45 Compare April 9, 2026 20:29
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants