-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Crossgen Wasm Object Writer V0 #122111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crossgen Wasm Object Writer V0 #122111
Conversation
…-r2r-object-writer
…x wasm arch+os target validation, add obj-format option for Wasm
It currently only handles writing method body nodes to the code section, in addition to building the type, function, and exports section. It will export all written methods so that they can be called when the module is loaded.
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces the first prototype of a WebAssembly object writer for crossgen2, enabling the compilation toolchain to output Wasm modules. The implementation focuses on emitting method bodies with minimal module structure required for loading and calling exported functions, while deferring relocations, R2R metadata, and proper ABI signature handling to future work.
Key Changes
- Added support for Wasm as a valid target architecture and container format in crossgen2
- Implemented core Wasm module writing infrastructure including section builders for Type, Function, Export, and Code sections
- Created a temporary stub mechanism to bypass JIT compilation for Wasm32 architecture until proper codegen support is available
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/aot/crossgen2/Program.cs | Added Wasm to allowed non-composite container formats |
| src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs | Added "wasm" architecture and "wasi" OS to valid options, plus "wasm" output format |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj | Included new Wasm object writer files (contains developer-specific path that should be removed) |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs | Added factory method to create WasmObjectWriter with ABI context |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunContainerFormat.cs | Added Wasm enum value to container format options |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/ClassDiagram1.cd | Added class diagram file (appears unrelated to Wasm implementation) |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Implemented CompileWasmStub to emit placeholder bytecode for Wasm methods |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Core Wasm module writer implementation handling section generation and export |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmNative.cs | Wasm type system definitions and encoding utilities |
| src/coreclr/tools/Common/Compiler/ObjectWriter/SectionWriter.cs | Added WriteUtf8StringNoNull helper method for Wasm string encoding |
| src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs | Changed visibility modifiers to enable WasmObjectWriter inheritance |
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
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
…WasmNative.cs Co-authored-by: Adeel Mujahid <[email protected]>
…WasmObjectWriter.cs Co-authored-by: Adeel Mujahid <[email protected]>
…r.cs Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…r.cs Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…r.cs Co-authored-by: Copilot <[email protected]>
…Run.csproj Co-authored-by: Copilot <[email protected]>
…r.cs Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
Co-authored-by: Adeel Mujahid <[email protected]>
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
|
@SingleAccretion thank you for your comments! I think I've addressed them, please feel free to take another look! |
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
jkoritzinsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for a v0
SingleAccretion
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with some comments.
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
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs
Outdated
Show resolved
Hide resolved
This PR reverts the behavior from #122111 which stubs out a method instead of calling the JIT for the crossgen Wasm target. Now, the JIT will be invoked as normal so that the output of method codegen can be placed in a simple object file. Output code currently won't run (I tried this) because we aren't yet emitting a correct local count at the beginning of compiled methods.
This is the first prototype of a Wasm object writer for crossgen that only writes out method bodies. It builds the minimum module structure which is needed to declare and export the module bodies so that the resulting module can be loaded and method bodies can be called by an external loader. I have tested the output with a simple JavaScript loader that instantiates the module and calls one of the exports.
What IS handled
Emitting simple method bodies from an assembly that have no relocations or external dependencies of any kind.
What is NOT handled
Relocations and any metadata attached to compiled methods.
R2R format envelope (the plan is to embed this in the data section in a future PR)
R2R metadata is currently unused.
Signature generation to meet ABI requirements
Right now, there is a single
i32 -> i32signature which is used as a placeholder for any method. Later work will need to build support for generating and storing wasm-level type signatures for JIT compiled methods.JIT Integration
Currently, the JIT is not called (I believe it will hit asserts on the Wasm target until #121973 is in). Instead, a simple
(i32.const 0) (return)stub is emitted for any JIT calls.