Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[wasm] Emit webcil-in-wasm component stubs for composite R2R - #130394

#130394
Merged
lewing merged 2 commits into
dotnet:maindotnet/runtime:mainfrom
lewing:lewing-wasm-composite-component-stubslewing/runtime:lewing-wasm-composite-component-stubsCopy head branch name to clipboard
Jul 13, 2026
Merged

[wasm] Emit webcil-in-wasm component stubs for composite R2R#130394
lewing merged 2 commits into
dotnet:maindotnet/runtime:mainfrom
lewing:lewing-wasm-composite-component-stubslewing/runtime:lewing-wasm-composite-component-stubsCopy head branch name to clipboard

Conversation

@lewing

@lewing lewing commented Jul 9, 2026

Copy link
Copy Markdown
Member

Composite ReadyToRun builds rewrite each input assembly into a small per-assembly component stub that forwards to the composite image. In RewriteComponentFile, the container format for these stubs was hardcoded to ReadyToRunContainerFormat.PE.

On a wasm build this routes the stub through PEObjectWriterCoffObjectWriter, which throws for the Wasm32 architecture, so a composite crossgen2 build fails after successfully emitting the composite-r2r.wasm image:

Emitting R2R Wasm file: .../composite-r2r.wasm
Error: Unsupported architecture
System.NotSupportedException: Unsupported architecture
   at ILCompiler.ObjectWriter.CoffObjectWriter..ctor(...)
   at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.CreatePEObjectWriter()
   at ILCompiler.ReadyToRunCodegenCompilation.RewriteComponentFile(...)

As a result, composite mode could not complete a crossgen2 build for any wasm target (browser or wasi).

Fix

Use the composite image's own container format for the per-assembly component stubs:

  • wasm targets emit webcil-in-wasm stubs, written as <assembly>.wasm (loaded by name via the browser/wasi external-assembly probe, matching how the composite image itself is loaded).
  • PE / Apple targets keep emitting PE stubs exactly as before (componentFormat resolves to PE for any non-wasm format).

This is a small change (15 insertions) local to RewriteComponentFile and its output-path selection; non-wasm behavior is unchanged.

Validation

With this change, crossgen2 --composite --targetos wasi --targetarch wasm (and --targetos browser) on a set of assemblies emits the composite-r2r.wasm image plus one webcil-in-wasm stub per input assembly, all passing wasm-tools validate. Verified locally on macOS/arm64.

Note

This change was authored with the assistance of GitHub Copilot.

Composite ReadyToRun builds rewrite each input assembly into a small
per-assembly component stub that forwards to the composite image. The
container format for these stubs was hardcoded to PE
(ReadyToRunContainerFormat.PE) in RewriteComponentFile. On a wasm build
that routes the stub through PEObjectWriter -> CoffObjectWriter, which
throws "Unsupported architecture" for Wasm32, so composite crossgen2
fails after successfully emitting the composite-r2r.wasm image:

    System.NotSupportedException: Unsupported architecture
       at ILCompiler.ObjectWriter.CoffObjectWriter..ctor(...)

Use the composite image's own container format for the component stubs:
wasm targets emit webcil-in-wasm stubs (loaded by name as
"<assembly>.wasm", matching the browser/wasi external-assembly probe),
while PE/Apple targets keep emitting PE stubs as before. This is not
wasm-arch specific to any single target OS - it fixes composite mode for
both browser and wasi, which previously could not complete a composite
crossgen2 build at all.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 9, 2026 03:06
@github-actions github-actions Bot added the area-crossgen2-coreclr only use for closed issues label Jul 9, 2026
@lewing lewing added the arch-wasm WebAssembly architecture label Jul 9, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@lewing
lewing marked this pull request as draft July 9, 2026 03:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates crossgen2 composite ReadyToRun component-stub emission so that when the compilation container format is Wasm, the per-assembly forwarding “component stubs” are emitted as webcil-in-wasm modules (.wasm) rather than being forced through the PE/COFF pipeline.

Changes:

  • When emitting standalone component stubs in composite mode, switch their output filename extension to .wasm for ReadyToRunContainerFormat.Wasm.
  • Pass a componentFormat into the component-stub emission pipeline so Wasm uses ReadyToRunContainerFormat.Wasm and non-Wasm continues to use PE.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 9, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 1 out of 1 changed files in this pull request and generated 1 comment.

@lewing
lewing requested review from a team and AndyAyersMS July 10, 2026 19:29
@lewing
lewing enabled auto-merge (squash) July 11, 2026 04:06
@lewing
lewing requested review from maraf and radekdoulik July 11, 2026 05:36

@radekdoulik radekdoulik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lewing
lewing merged commit 89828fb into dotnet:main Jul 13, 2026
107 of 109 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 14, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Composite ReadyToRun builds rewrite each input assembly into a small
per-assembly *component stub* that forwards to the composite image. In
`RewriteComponentFile`, the container format for these stubs was
hardcoded to `ReadyToRunContainerFormat.PE`.

On a wasm build this routes the stub through `PEObjectWriter` →
`CoffObjectWriter`, which throws for the Wasm32 architecture, so a
composite crossgen2 build fails **after** successfully emitting the
`composite-r2r.wasm` image:

```
Emitting R2R Wasm file: .../composite-r2r.wasm
Error: Unsupported architecture
System.NotSupportedException: Unsupported architecture
   at ILCompiler.ObjectWriter.CoffObjectWriter..ctor(...)
   at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.CreatePEObjectWriter()
   at ILCompiler.ReadyToRunCodegenCompilation.RewriteComponentFile(...)
```

As a result, composite mode could not complete a crossgen2 build for
**any** wasm target (browser or wasi).

## Fix

Use the composite image's own container format for the per-assembly
component stubs:

- **wasm** targets emit webcil-in-wasm stubs, written as
`<assembly>.wasm` (loaded by name via the browser/wasi external-assembly
probe, matching how the composite image itself is loaded).
- **PE / Apple** targets keep emitting PE stubs exactly as before
(`componentFormat` resolves to `PE` for any non-wasm format).

This is a small change (15 insertions) local to `RewriteComponentFile`
and its output-path selection; non-wasm behavior is unchanged.

## Validation

With this change, `crossgen2 --composite --targetos wasi --targetarch
wasm` (and `--targetos browser`) on a set of assemblies emits the
`composite-r2r.wasm` image plus one webcil-in-wasm stub per input
assembly, all passing `wasm-tools validate`. Verified locally on
macOS/arm64.

> [!NOTE]
> This change was authored with the assistance of GitHub Copilot.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Pavel Savara <pavelsavara@microsoft.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-crossgen2-coreclr only use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.