[RyuJIT Wasm] Add Object Writer Imports Section + Constant Exprs to Encode R2R Payload Placement#123739
Conversation
…k pointer, and r2r start address by default
Lay out R2R data segments relative to imported __r2r_start global
|
I will try and update the test harness to be compatible with this |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
@kg I'd love a review on this when you have a chance! |
There was a problem hiding this comment.
Pull request overview
Adds initial support for emitting a Wasm import section from WasmObjectWriter, and switches R2R data segment placement to use constant expressions based on an imported __r2r_start symbol.
Changes:
- Introduces a new
wasm.importobject node section and emits it as Wasm section typeImport. - Reworks combined data segment placement to use an instruction expression (
global.get __r2r_start+i32.const offset+i32.add) instead of a fixedDataStartOffset. - Adds a small Wasm encoding model (imports, globals, memory type, expression/instruction encoding) and a helper to write UTF-8 strings with a length prefix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Adds import section emission and uses __r2r_start + offset constant expressions for data segment placement. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmNative.cs | Adds encodable abstractions/types for Wasm expressions and import encodings (memory/global types, etc.). |
| src/coreclr/tools/Common/Compiler/ObjectWriter/SectionWriter.cs | Adds WriteUtf8WithLength helper for Wasm-style length-prefixed strings. |
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
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
|
This looks fairly good, all of Copilot's feedback seemed accurate though so we need to address it. |
…classes in a separate file and namespace
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
e3da59a to
1d3f7fc
Compare
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
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
I think I'll address this as a refactor in a follow up. My thinking here is to create a lightweight wrapper type that can be consumed as a |
|
@kg This should be ready for another look when you have a moment! |
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
|
/ba-g unrelated failures |
…ncode R2R Payload Placement (dotnet#123739) This PR adds support for generating an import section to the WasmObjectWriter. We currently import: - `env.memory` - `__stack_pointer` - `__r2r_start` Which are all expected to be provided by the runtime. Various data segments are then placed into `__r2r_start + <segment_offset>`. We use the constant expressions extension for these address calculations. Notably this PR removes our export of the module memory, as we want to share memory with the runtime.
This PR adds support for generating an import section to the WasmObjectWriter. We currently import:
env.memory__stack_pointer__r2r_startWhich are all expected to be provided by the runtime. Various data segments are then placed into
__r2r_start + <segment_offset>. We use the constant expressions extension for these address calculations.Notably this PR removes our export of the module memory, as we want to share memory with the runtime.