[browser][coreCLR] no COM, no swift#125083
Conversation
|
Tagging subscribers to this area: @agocke |
There was a problem hiding this comment.
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 annotatesComActivatoraccordingly. - Gates ILLink rooting for
ComponentActivator.GetFunctionPointerbehind the existing native-hosting feature switch. - Adds
TARGET_WASMguards 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. |
c066985 to
77b2da7
Compare
77b2da7 to
cb5be74
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
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. |
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
ComActivatormethods that are not applicable on Browser, and teaches the WASMPInvokeCollectorto skip callbacks on types marked as unsupported on Browser.Changes
SEH exception trimming (
#ifdef TARGET_WINDOWS)ex.h/ex.cpp: Wrap theSEHExceptionclass definition, constructors, andGetHR()/GetMessage()implementations in#ifdef TARGET_WINDOWS.clrex.cpp: Wrap theSEHExceptionhandling path inGetThrowableFromExceptionso non-Windows falls through to the genericHRException/COMException/DelegatingExceptionhandler.dacfn.cpp: Wrap theSEHExceptionrethrow logic inDacExceptionFilterin#ifdef TARGET_WINDOWS.rexcep.h: Wrap theDEFINE_EXCEPTIONforSEHExceptionin#ifdef TARGET_WINDOWS.excep.cpp:MapWin32FaultToCOMPlusExceptiondefault case: returnskSEHExceptionon Windows,kExceptionwith_ASSERTE(!"Expected to be unreachable")on non-Windows.SEHExceptionreferences inDebugIsEECxxExceptionPointerin#ifdef TARGET_WINDOWS.Move
CallOutFilter/FilterAccessViolationfrom generic codeexcep.cpp/excep.h: RemoveCallOutFilter,CallOutFilterParam, andFilterAccessViolation— these are SEH-specific helpers only used from COM interop code.interoputil.cpp: MoveCallOutFilterandCallOutFilterParamhere, where they are actually used (already inside#ifdef FEATURE_COMINTEROPcompilation unit).COM-specific type trimming (
#ifdef FEATURE_COMINTEROP)rexcep.h: MoveInvalidOleVariantTypeExceptioninside the existing#ifdef FEATURE_COMINTEROPblock.corelib.h: WrapCOMVARIANTclass definition in#if defined(FEATURE_COMINTEROP).metasig.h: WrapComVariant-related metasig definitions in#ifdef FEATURE_COMINTEROP.olevariant.cpp: WrapVT_VARIANT→CLASS__COMVARIANTmapping in#ifdef FEATURE_COMINTEROP.Marshal.cs(shared CoreLib): WrapCOR_E_INVALIDOLEVARIANTTYPE→InvalidOleVariantTypeExceptionmapping in#if FEATURE_COMINTEROP.Swift types Apple-only (
#ifdef TARGET_APPLE)corelib.h: WrapSwiftSelf,SwiftSelf<T>,SwiftError,SwiftIndirectResultclass 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 threeComActivatorreverse P/Invoke thunks (GetClassFactoryForTypeInternal,RegisterClassForTypeInternal,UnregisterClassForTypeInternal) and their entries ing_ReverseThunks. RenameOnThreadExiting→OnThreadExitedto match the upstream API rename.WASM PInvoke collector - skip browser-unsupported types
PInvokeCollector.cs: AddIsUnsupportedOnBrowsermethod 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: AddCallFunc_I32_I32_I32_RetI64thunk andliiisignature entry.callhelpers-pinvoke.cpp: AddSystemNative_ReadVandSystemNative_WriteVP/Invoke declarations and table entries (count 92 → 94).