Skip to content

Wasm NativeAOT: Add WASM_GLOBAL_INDEX_LEB relocation support + WasmNativeObjectWriter scaffold#90

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/jtschusterwasm-objectwriter-nativeaot
Draft

Wasm NativeAOT: Add WASM_GLOBAL_INDEX_LEB relocation support + WasmNativeObjectWriter scaffold#90
Copilot wants to merge 3 commits into
mainfrom
copilot/jtschusterwasm-objectwriter-nativeaot

Conversation

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown

Wires in WASM_GLOBAL_INDEX_LEB relocation handling for the R2R Webcil path and lays the groundwork for a NativeAOT relocatable wasm object writer.

R2R (WasmObjectWriter.cs)

  • Changed _definedSymbols[reloc.SymbolName] to TryGetValue — avoids KeyNotFoundException for non-ObjectNode symbols (e.g. WasmBaseGlobalSymbolNode) that are never added to _definedSymbols
  • Added WASM_GLOBAL_INDEX_LEB case: maps __stack_pointer → 0, __memory_base → 1, __table_base → 2 (matching _defaultGlobalImports fixed positions)

WasmInstructions.cs

  • Added Global.Get(ISymbolNode) / Global.Set(ISymbolNode) overloads using WasmLEBConstantReloc(..., WASM_GLOBAL_INDEX_LEB) — enables future code to reference base globals by symbol rather than hardcoded index

NativeAOT wasm writer scaffold

  • WasmNativeObjectWriter.cs (new, Common/): skeleton for a relocatable wasm object writer (wasm magic/version header; all section/debug/unwind methods stubbed TODO-Wasm)
  • ObjectWriter.cs: added static partial void TryCreateArchitectureSpecificWriter(...) hook using the existing partial method pattern
  • ObjectWriter.Aot.cs: implements the hook to dispatch to WasmNativeObjectWriter for TargetArchitecture.Wasm32

Project files

  • WasmBaseGlobalSymbolNode.cs added to both ILCompiler.ReadyToRun.csproj and ILCompiler.Compiler.csproj
  • WasmAbiConstants.cs and WasmNativeObjectWriter.cs added to ILCompiler.Compiler.csproj

Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com>
Copilot AI changed the title [WIP] Reconstruct wasm NativeAOT object writer from session logs [wasm] Reconstruct NativeAOT WebAssembly object writer bring-up branch Jun 11, 2026
Copilot AI requested a review from jtschuster June 11, 2026 13:56
… scaffold

Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com>
Copilot AI changed the title [wasm] Reconstruct NativeAOT WebAssembly object writer bring-up branch Wasm NativeAOT: Add WASM_GLOBAL_INDEX_LEB relocation support + WasmNativeObjectWriter scaffold Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants