Skip to content

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

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

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

Conversation

@pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Mar 2, 2026

Trim dead interop/COM code from browser-WASM CoreCLR builds

Summary

This PR reduces the browser-WASM CoreCLR native binary size by excluding COM interop, SEH exception, and Swift interop code that cannot run on the browser platform.

Changes

1. Guard COM/Interop exception types with FEATURE_COMINTEROP (

excep.h)

  • Move InvalidOleVariantTypeException into the existing FEATURE_COMINTEROP block alongside InvalidComObjectException
  • Wrap ExternalException, and SEHException definitions with #ifdef FEATURE_COMINTEROP — these types only exist for COM interop scenarios

2. Guard SEHException handling block with TARGET_WASM (clrex.cpp)

  • Wrap the entire SEHException branch in CLRException::GetThrowableFromException with #ifndef TARGET_WASM. WASM has no hardware exception (signal) support, so SEHException objects are never produced on that platform.

3. Fix MapWin32FaultToCOMPlusException default case (�xcep.cpp)

  • The default case returned kSEHException, which is only defined under FEATURE_COMINTEROP. Guard the return with #ifdef FEATURE_COMINTEROP, falling back to kException on non-COM platforms.

4. Guard ComVariant references with FEATURE_COMINTEROP

  • corelib.h: Wrap DEFINE_CLASS(COMVARIANT, ...) with #if defined(FEATURE_COMINTEROP)
  • metasig.h: Wrap 3 COMVARIANT metasig entries with #ifdef FEATURE_COMINTEROP
  • olevariant.cpp: Wrap the VT_VARIANT → CLASS__COMVARIANT case with #ifdef FEATURE_COMINTEROP

5. Restrict Swift interop types to Apple platforms (corelib.h)

Guard SwiftSelf, SwiftSelf, SwiftError, and SwiftIndirectResult with #if defined(TARGET_APPLE). Swift interop is not supported on WASM or other non-Apple platforms.

6. Add [UnsupportedOSPlatform("browser")] to ComActivator

File: ComActivator.PlatformNotSupported.cs

Annotate ComActivator with [UnsupportedOSPlatform("browser")] so its [UnmanagedCallersOnly] methods are excluded from generated reverse P/Invoke stubs on browser builds.

7. Filter [UnsupportedOSPlatform("browser")] types from reverse P/Invoke stubs

File: PInvokeCollector.cs

Add IsUnsupportedOnBrowser() helper to DoesMethodHaveCallbacks() — skips generating reverse P/Invoke callback stubs for methods on types annotated with [UnsupportedOSPlatform("browser")].

8. Regenerated callhelpers files

Files: callhelpers-pinvoke.cpp, callhelpers-reverse.cpp, callhelpers-interp-to-managed.cpp

Regenerated to reflect the ComActivator exclusion and upstream changes.

Testing

Build verified with .\build.cmd -bl -os browser -subset clr -c Release /p:RuntimeFlavor=CoreCLR.

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

@pavelsavara pavelsavara requested a review from radekdoulik March 18, 2026 11:13
Copy link
Member

@radekdoulik radekdoulik left a comment

Choose a reason for hiding this comment

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

Beside the 2 comments it LGTM, thank you!

@jkotas
Copy link
Member

jkotas commented Mar 18, 2026

PR reduces the trimmed size of browser-WASM CoreCLR apps

Do you have any numbers for the size improvement?

Copilot AI review requested due to automatic review settings March 20, 2026 09:57
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.

- fallback to kException when not FEATURE_COMINTEROP instead of kSEHException and kCOMException
- revert of CompExactlyDependsOnAttribute, GetFunctionPointer
- regenerated helpers
@pavelsavara pavelsavara changed the title [browser][coreCLR] no COM, no swift, no x86 intrinsics [browser][coreCLR] no COM, no swift Mar 20, 2026
Copilot AI review requested due to automatic review settings March 20, 2026 15:43
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 11 out of 11 changed files in this pull request and generated 3 comments.

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.

5 participants