Skip to content

[wasm][R2R] Request flat layout for composite image on WebAssembly#131354

Open
lewing wants to merge 1 commit into
dotnet:mainfrom
lewing:wasm-r2r-composite-flat-layout
Open

[wasm][R2R] Request flat layout for composite image on WebAssembly#131354
lewing wants to merge 1 commit into
dotnet:mainfrom
lewing:wasm-r2r-composite-flat-layout

Conversation

@lewing

@lewing lewing commented Jul 24, 2026

Copy link
Copy Markdown
Member

On WebAssembly, PE images are flat-layout only (PEIMAGE_FLAT_LAYOUT_ONLY). A webcil composite R2R image has no OS-loadable/mapped layout, so requesting LAYOUT_LOADED yields no layout and trips the flat-suitability assert in GetOrCreateLayoutInternal. Request the flat layout explicitly under TARGET_WASM when obtaining the composite image layout in NativeImage::Open.

Guarded by #ifdef TARGET_WASM, so no behavior change on any other target.

Note

This pull request was authored with assistance from GitHub Copilot.

OpenR2RFromPE requested PEImageLayout::LAYOUT_LOADED for the composite R2R
container. On WebAssembly (PEIMAGE_FLAT_LAYOUT_ONLY) there is no OS-loadable
mapped layout, so the loaded-layout branch in GetOrCreateLayoutInternal is
compiled out and the request degrades to nothing, tripping the
_ASSERTE(bIsFlatLayoutSuitable) consistency check in Debug builds (and only
silently degrading in Release). Every other wasm image open uses LAYOUT_ANY.

Request LAYOUT_FLAT explicitly on TARGET_WASM so a webcil composite loads via
the flat layout, matching the rest of the wasm image-load paths.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 50ddfb2c-b6f8-4847-81e7-44d37d44a175
Copilot AI review requested due to automatic review settings July 24, 2026 23:03
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

Updates CoreCLR’s composite R2R loading path on WebAssembly to request a flat PE layout explicitly when opening the composite image, avoiding a debug assert caused by requesting a loaded/mapped layout on a flat-only platform.

Changes:

  • Under TARGET_WASM, call PEImage::GetOrCreateLayout(PEImageLayout::LAYOUT_FLAT) instead of LAYOUT_LOADED when opening the composite image.
  • Add in-code rationale explaining why the flat layout is required on WASM for webcil composites.

Comment on lines +141 to +148
#ifdef TARGET_WASM
// WebAssembly is flat-layout only (PEIMAGE_FLAT_LAYOUT_ONLY): a webcil composite has no
// OS-loadable/mapped layout, so requesting LAYOUT_LOADED yields no layout and trips the
// flat-suitability assert in GetOrCreateLayoutInternal. Request the flat layout explicitly.
PEImageLayout* loaded = pImage->GetOrCreateLayout(PEImageLayout::LAYOUT_FLAT);
#else
PEImageLayout* loaded = pImage->GetOrCreateLayout(PEImageLayout::LAYOUT_LOADED);
#endif // TARGET_WASM
@lewing lewing added the arch-wasm WebAssembly architecture label Jul 24, 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.

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

Labels

arch-wasm WebAssembly architecture area-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants