Skip to content

Empty Main works for corerun on WASM - #119448

Merged
AaronRobinsonMSFT merged 18 commits into
dotnet:mainfrom
AaronRobinsonMSFT:array_alloc
Sep 9, 2025
Merged

Empty Main works for corerun on WASM#119448
AaronRobinsonMSFT merged 18 commits into
dotnet:mainfrom
AaronRobinsonMSFT:array_alloc

Conversation

@AaronRobinsonMSFT

@AaronRobinsonMSFTAaronRobinsonMSFT commented Sep 8, 2025

Copy link
Copy Markdown
Member

Implement array allocators for WASM.

Calling empty Main() works for corerun. Steps:

  1. Build coreclr and libs for browser
    • ./build.sh -os browser -c Debug -subset clr.runtime+libs
    • It is okay if the "libs" build fails. We just need System.Runtime.dll to build.
  2. Copy over System.Runtime.dll to the IL location containing System.Private.CoreLib.dll
  3. Build a simple C# application:
    publicstaticclassProgram{publicstaticvoidMain(){}}
  4. Copy the simple C# application to the IL location. It should now have System.Private.CoreLib.dll, System.Runtime.dll and <app>.dll.

Additional changes to get to where we need to execute
an unmanaged FCall implementation.
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Comment threadsrc/coreclr/vm/jitinterfacegen.cpp Outdated
Comment threadsrc/coreclr/vm/threads.cpp
Comment threadsrc/coreclr/vm/wasm/helpers.cpp Outdated
Comment threadsrc/coreclr/vm/jitinterfacegen.cpp Outdated
Comment threadsrc/coreclr/vm/object.h Outdated
Comment threadsrc/coreclr/vm/precode_portable.cpp Outdated
Comment threadsrc/coreclr/vm/wasm/helpers.cpp
Comment threadsrc/coreclr/runtime/portable/AllocFast.cpp Outdated
Comment threadsrc/coreclr/nativeaot/Runtime/ObjectLayout.h Outdated
Comment threadsrc/coreclr/vm/prestub.cpp Outdated
Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Comment threadsrc/coreclr/vm/method.cpp Outdated
Comment threadsrc/coreclr/vm/method.cpp Outdated
Comment threadsrc/coreclr/runtime/portable/AllocFast.cpp Outdated
Comment threadsrc/coreclr/runtime/portable/AllocFast.cpp Outdated

CopilotAI 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 implements essential array allocation functionality for WebAssembly (WASM) to enable empty Main() method execution in corerun. The implementation provides basic memory allocation, method invocation infrastructure, and interpreter support necessary for minimal CLR functionality on WASM.

Key changes include:

  • Implementation of array allocation helpers (RhpNewArrayFast, RhNewString) to support basic object creation
  • Addition of managed method invocation support through portable entry points and call stubs
  • Updates to method compilation and invocation infrastructure for WASM interpreter compatibility

Reviewed Changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 5 comments.

Show a summary per file
FileDescription
src/coreclr/vm/wasm/helpers.cppImplements calli stubs and managed method invocation for WASM interpreter
src/coreclr/vm/threads.cppFixes preprocessor directive placement for portable helpers
src/coreclr/vm/runtimehandles.cppAdds null check assertion for type handle validation
src/coreclr/vm/prestub.cppEnhances FCall handling with portable entry point support and managed implementation detection
src/coreclr/vm/precode_portable.hppAdds method for creating portable entry points from native code
src/coreclr/vm/precode_portable.cppImplements portable entry point creation and code address management
src/coreclr/vm/portable/AllocSlow.cppAdds allocation failure handler stub
src/coreclr/vm/object.hAdds SetNumComponents method and removes unused friend declarations
src/coreclr/vm/method.cppRefactors code entry point setting logic for portable entry points
src/coreclr/vm/jitinterface.cppOptimizes helper function entry point creation and caching
src/coreclr/vm/gchelpers.cppUpdates array allocation to use new SetNumComponents method
src/coreclr/vm/gcheaputilities.hRefactors allocation context methods for better encapsulation
src/coreclr/vm/finalizerthread.hMoves RaiseShutdownEvents implementation to source file
src/coreclr/vm/finalizerthread.cppImplements RaiseShutdownEvents with WASM-specific handling
src/coreclr/vm/ecall.hAdds optional output parameter for managed implementation detection
src/coreclr/vm/ecall.cppEnhances FCall implementation detection and managed constructor handling
src/coreclr/vm/callstubgenerator.cppFixes variable shadowing in call stub generation
src/coreclr/runtime/portable/AllocFast.cppImplements fast array and string allocation with allocation context management
src/coreclr/nativeaot/Runtime/portable.cppUpdates NativeAOT allocation helpers to use consistent method names
src/coreclr/nativeaot/Runtime/ObjectLayout.hStandardizes method naming for array initialization
src/coreclr/nativeaot/Runtime/ObjectLayout.cppUpdates method implementation to match new naming convention
src/coreclr/nativeaot/Runtime/GCHelpers.cppUpdates allocation helper to use SetMethodTable naming

Comment threadsrc/coreclr/vm/wasm/helpers.cpp
Comment threadsrc/coreclr/vm/wasm/helpers.cpp
Comment threadsrc/coreclr/vm/jitinterface.cpp
Comment threadsrc/coreclr/runtime/portable/AllocFast.cpp
Comment threadsrc/coreclr/runtime/portable/AllocFast.cpp
Comment threadsrc/coreclr/vm/finalizerthread.cpp
Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Comment threadsrc/coreclr/vm/jitinterface.cpp Outdated
Comment threadsrc/coreclr/vm/precode_portable.cpp Outdated

@jkotasjkotas 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.

Thank you!

pavelsavaraand others added 3 commits September 9, 2025 09:50
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@pavelsavara

Copy link
Copy Markdown
Member

I tested it and it works 🎉

@jkotas

Copy link
Copy Markdown
Member

Revert "Update src/coreclr/vm/jitinterface.cpp"

This hit a buggy path discussed in #119355 (comment) . I have reapplied the feedback with additional fix.

@radekdoulikradekdoulik 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, I will address the remaining feedback on caching cookie in another PR

@AaronRobinsonMSFT

Copy link
Copy Markdown
MemberAuthor

Revert "Update src/coreclr/vm/jitinterface.cpp"

This hit a buggy path discussed in #119355 (comment) . I have reapplied the feedback with additional fix.

FYI @kotlarmilos

@AaronRobinsonMSFT
AaronRobinsonMSFT enabled auto-merge (squash) September 9, 2025 15:12
@AaronRobinsonMSFT
AaronRobinsonMSFT merged commit 51ff53f into dotnet:mainSep 9, 2025
99 checks passed
@AaronRobinsonMSFT
AaronRobinsonMSFT deleted the array_alloc branch September 9, 2025 15:28
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Oct 10, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasmWebAssembly architecturearea-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@AaronRobinsonMSFT@pavelsavara@jkotas@radekdoulik