Skip to content

[browser][coreCLR] no COM, no swift#125083

Open
pavelsavara wants to merge 31 commits intodotnet:mainfrom
pavelsavara:browser_trim_COM
Open

[browser][coreCLR] no COM, no swift#125083
pavelsavara wants to merge 31 commits intodotnet:mainfrom
pavelsavara:browser_trim_COM

Conversation

@pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Mar 2, 2026

Trim COM/SEH-related code for non-Windows targets (Browser WASM)

Summary

This PR conditionally compiles out COM interop, SEH exception, and Windows-only code paths from the CoreCLR runtime when targeting non-Windows platforms (primarily Browser/WASM). It also removes reverse P/Invoke thunks for ComActivator methods that are not applicable on Browser, and teaches the WASM PInvokeCollector to skip callbacks on types marked as unsupported on Browser.

Changes

SEH exception trimming (#ifdef TARGET_WINDOWS)

  • ex.h / ex.cpp: Wrap the SEHException class definition, constructors, and GetHR()/GetMessage() implementations in #ifdef TARGET_WINDOWS.
  • clrex.cpp: Wrap the SEHException handling path in GetThrowableFromException so non-Windows falls through to the generic HRException/COMException/DelegatingException handler.
  • dacfn.cpp: Wrap the SEHException rethrow logic in DacExceptionFilter in #ifdef TARGET_WINDOWS.
  • rexcep.h: Wrap the DEFINE_EXCEPTION for SEHException in #ifdef TARGET_WINDOWS.
  • excep.cpp:
    • MapWin32FaultToCOMPlusException default case: returns kSEHException on Windows, kException with _ASSERTE(!"Expected to be unreachable") on non-Windows.
    • Wrap SEHException references in DebugIsEECxxExceptionPointer in #ifdef TARGET_WINDOWS.

Move CallOutFilter / FilterAccessViolation from generic code

  • excep.cpp / excep.h: Remove CallOutFilter, CallOutFilterParam, and FilterAccessViolation — these are SEH-specific helpers only used from COM interop code.
  • interoputil.cpp: Move CallOutFilter and CallOutFilterParam here, where they are actually used (already inside #ifdef FEATURE_COMINTEROP compilation unit).

COM-specific type trimming (#ifdef FEATURE_COMINTEROP)

  • rexcep.h: Move InvalidOleVariantTypeException inside the existing #ifdef FEATURE_COMINTEROP block.
  • corelib.h: Wrap COMVARIANT class definition in #if defined(FEATURE_COMINTEROP).
  • metasig.h: Wrap ComVariant-related metasig definitions in #ifdef FEATURE_COMINTEROP.
  • olevariant.cpp: Wrap VT_VARIANTCLASS__COMVARIANT mapping in #ifdef FEATURE_COMINTEROP.
  • Marshal.cs (shared CoreLib): Wrap COR_E_INVALIDOLEVARIANTTYPEInvalidOleVariantTypeException mapping in #if FEATURE_COMINTEROP.

Swift types Apple-only (#ifdef TARGET_APPLE)

  • corelib.h: Wrap SwiftSelf, SwiftSelf<T>, SwiftError, SwiftIndirectResult class definitions in #ifdef TARGET_APPLE.

Platform annotation

  • ComActivator.PlatformNotSupported.cs: Add [SupportedOSPlatform("windows")] attribute so the WASM toolchain can detect it as unsupported.

WASM reverse call helpers

  • callhelpers-reverse.cpp: Remove three ComActivator reverse P/Invoke thunks (GetClassFactoryForTypeInternal, RegisterClassForTypeInternal, UnregisterClassForTypeInternal) and their entries in g_ReverseThunks. Rename OnThreadExitingOnThreadExited to match the upstream API rename.

WASM PInvoke collector - skip browser-unsupported types

  • PInvokeCollector.cs: Add IsUnsupportedOnBrowser method that checks for [UnsupportedOSPlatform("browser")] or [SupportedOSPlatform(...)] without "browser" on the declaring type. Callbacks on unsupported types are skipped during WASM app build, avoiding link errors for COM-related methods.

WASM call helper additions (unrelated fixups merged from main)

  • callhelpers-interp-to-managed.cpp: Add CallFunc_I32_I32_I32_RetI64 thunk and liii signature entry.
  • callhelpers-pinvoke.cpp: Add SystemNative_ReadV and SystemNative_WriteV P/Invoke declarations and table entries (count 92 → 94).

@pavelsavara pavelsavara added this to the 11.0.0 milestone Mar 2, 2026
@pavelsavara pavelsavara self-assigned this Mar 2, 2026
Copilot AI review requested due to automatic review settings March 2, 2026 23:23
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-VM-coreclr size-reduction Issues impacting final app size primary for size sensitive workloads os-browser Browser variant of arch-wasm labels Mar 2, 2026
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Mar 2, 2026
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Contributor

Copilot AI left a 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 aims to reduce trimmed size for browser-WASM CoreCLR builds by removing/gating roots and native support code for features that aren’t supported in the browser (COM/interop-related pieces, DynamicInterfaceCastable, Swift interop, and intrinsics metadata rooting).

Changes:

  • Filters reverse P/Invoke stub generation for types marked [UnsupportedOSPlatform("browser")] and annotates ComActivator accordingly.
  • Gates ILLink rooting for ComponentActivator.GetFunctionPointer behind the existing native-hosting feature switch.
  • Adds TARGET_WASM guards to exclude DynamicInterfaceCastable native support on WASM and trims related ILLink roots / metadata retention paths.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/tasks/WasmAppBuilder/generate-coreclr-helpers.cmd Updates helper generation script used for CoreCLR WASM callhelper regeneration.
src/tasks/WasmAppBuilder/coreclr/PInvokeCollector.cs Skips generating reverse P/Invoke callback stubs for types unsupported on browser.
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CompExactlyDependsOnAttribute.cs Removes CompExactlyDependsOnAttribute metadata for browser/WASI builds to improve trimming.
src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.Shared.xml Gates ComponentActivator.GetFunctionPointer rooting behind the native-hosting feature switch.
src/coreclr/vm/wasm/callhelpers-reverse.cpp Regenerated reverse thunk table reflecting removed callbacks.
src/coreclr/vm/wasm/callhelpers-pinvoke.cpp Regenerated P/Invoke table reflecting upstream removals.
src/coreclr/vm/virtualcallstub.cpp Removes DynamicInterfaceCastable resolver path from WASM builds.
src/coreclr/vm/rexcep.h Attempts to exclude interop exception types from WASM ILLink descriptor generation.
src/coreclr/vm/methodtable.cpp Removes IDynamicInterfaceCastable special method resolution on WASM.
src/coreclr/vm/jithelpers.cpp Removes IDynamicInterfaceCastable cast path on WASM.
src/coreclr/vm/dynamicinterfacecastable.h Wraps DynamicInterfaceCastable API surface out of WASM builds.
src/coreclr/vm/dynamicinterfacecastable.cpp Wraps DynamicInterfaceCastable implementation out of WASM builds.
src/coreclr/vm/corelib.h Attempts to exclude Swift interop and ComVariant from WASM ILLink descriptor generation; removes DynamicInterfaceCastableHelpers from WASM.
src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs Marks ComActivator as unsupported on browser to suppress reverse stub generation.

Copilot AI review requested due to automatic review settings March 13, 2026 15:29
Copy link
Contributor

Copilot AI left a comment

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 8 out of 8 changed files in this pull request and generated 2 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

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 17 out of 17 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings March 23, 2026 17:14
Copy link
Contributor

Copilot AI left a comment

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 17 out of 17 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings March 23, 2026 17:49
Copy link
Contributor

Copilot AI left a comment

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 17 out of 17 changed files in this pull request and generated 2 comments.

@jkotas
Copy link
Member

jkotas commented Mar 25, 2026

Any numbers for how much this saves? I like to have numbers for anything that claims to be a perf improvement.

@pavelsavara
Copy link
Member Author

Any numbers for how much this saves? I like to have numbers for anything that claims to be a perf improvement.

This is not about perf at all.
It started as much bigger IL trimming PR, but I was not able to reproduce Intrinsics at some point.
So, what we have right now is just cleanup. I can measure size difference, but it would not be big deal.

Copilot AI review requested due to automatic review settings March 25, 2026 16:53
Copy link
Contributor

Copilot AI left a comment

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

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 linkable-framework Issues associated with delivering a linker friendly framework os-browser Browser variant of arch-wasm size-reduction Issues impacting final app size primary for size sensitive workloads

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants