Repository navigation
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Member
Author
|
I'm exploring options here, there will likely be other changes even if we take this form now. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Debug and debugger-enabled WASI builds still receive flags that strip R2R debug information, while the component rewrite and symbol-map generation lack automated regression coverage.
2 open issues
What changed in this PR
This PR reduces CoreCLR WASI app size by stripping native debug information from per-app hosts and optionally preserving function names in a symbol-map sidecar.
Changes:
- Adds component symbol stripping and
corerun.symbolsgeneration after ReadyToRun composition. - Introduces configuration-sensitive stripping defaults and ReadyToRun debug-information options.
- Keeps function names in library-test hosts while removing DWARF, and documents the WASI-specific settings.
| File | Description |
|---|---|
src/tasks/WasmAppBuilder/StripWasiComponentSymbols.cs |
Adds the MSBuild task for stripping host symbols and tracking outputs. |
src/tasks/Microsoft.NET.WebAssembly.Webcil/WasmModuleInfoReader.cs |
Shares component rewriting logic and adds symbol extraction and removal. |
src/mono/wasm/build/WasmApp.Common.targets |
Documents CoreCLR WASI stripping and symbol-map defaults. |
src/mono/wasi/build/WasiApp.CoreCLR.targets |
Integrates stripping defaults, linker options, ReadyToRun settings, and host finalization. |
eng/testing/tests.wasi.targets |
Configures test hosts to retain names without DWARF. |
Review effort: Balanced
The CoreCLR WASI build always relinks the wasihost per app, but the link
ignored WasmNativeStrip, so Release hosts carried the runtime pack's DWARF
(~29 MB of a 34 MB host for a hello world) and the wasm name section.
- Default WasmNativeStrip to false in Debug and true otherwise; WasmApp.Common
only applies its Debug default when WasmBuildNative is set, which CoreCLR
WASI forces to false.
- Link with --strip-debug when stripping (or when WasmNativeDebugSymbols is
false), and compile the generated callhelpers with -g when keeping symbols.
- Add _WasiCoreCLRFinalizeHost, which runs after the ReadyToRun composition
and, with WasmNativeStrip, drops the name section from the host's core
module and writes the names to managed/corerun.symbols ('index:name', the
emscripten symbol map format) unless WasmEmitSymbolMap is false.
- Keep function names (without DWARF) in the library test hosts so wasmtime
backtraces in test logs stay readable.
Co-authored-by: Copilot App <[email protected]>
- Strip the R2R debug and inlining info unless Configuration is Debug or DebuggerSupport is set, as browser does. This halves the composite payload of a hello world (1,188,208 to 598,848 bytes). - Pass --wasm-debug-info explicitly: 'name' when the merged host keeps its names or writes corerun.symbols, so managed R2R frames are symbolized, and 'none' otherwise. crossgen2's symbol-map sidecar numbers functions within the composite rather than the merged host, so it isn't used. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Microsoft.NET.CrossGen.targets already adds --strip-inlining-info and --strip-debug-info for wasi-* unless the properties are explicitly false (dotnet#134690), and it is imported before WasiApp.CoreCLR.targets, so the Debug/DebuggerSupport exemption here could never take effect. CoreCLR wasm does not consume that metadata, so drop the duplicate block and keep only --wasm-debug-info. Add a synthetic-component test for WasmComponentSymbols.StripFirstCoreModule covering name and DWARF section removal, preservation of other sections and later core modules, multibyte function indices, and the optional symbol map. Co-authored-by: Copilot App <[email protected]>
lewing
force-pushed
the
lewing-strip-debug-coreclr-wasi-relink
branch
from
November 25, 2026 03:19
64b798a to
ce31cf2
Compare
This was referenced Nov 25, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

CoreCLR WASI relinks the wasihost (
corerun) for every app, but that link ignoredWasmNativeStrip. Release hosts therefore shipped the runtime pack's DWARF and the wasmnamesection. For a trimmed hello world, 29.4 MB of the 33.9 MB host was DWARF; in a real app (NesmWasm, composite R2R) it was about 26 MB of a 47.6 MB host. Debug wasn't protected either: CoreCLR WASI forcesWasmBuildNative=false, so the WasmApp.Common rule that keeps symbols in Debug never applied, andWasmNativeStripresolved totruein every configuration.Changes
WasiApp.CoreCLR.targets):WasmNativeStripis false in Debug and true otherwise.WasmEmitSymbolMapdefaults to true; it's set beforeWasiApp.targetsis imported, because that file defaults it to false.-Wl,--strip-debugwhen stripping, or whenWasmNativeDebugSymbols=false. This drops DWARF at link time but keeps function names, so the R2R composition can still merge the composite's names in.-gwhen symbols are kept._WasiCoreCLRFinalizeHosttarget andStripWasiComponentSymbolstask:WasmNativeStrip=true, removes thenameand.debug_*custom sections from the component's first core module.managed/corerun.symbolsasindex:namelines, the emscripten symbol-map format browser uses fordotnet.native.js.symbols. The indices are the ones wasmtime prints as<wasm function N>.WasmEmitSymbolMap=falseskips the sidecar.ReplaceFirstCoreModuleinMicrosoft.NET.WebAssembly.Webcil.--wasm-debug-info:namewhen the merged host keeps names or writes the sidecar, otherwisenone. crossgen2's ownsymbol-mapsidecar isn't used, because it numbers functions within the composite, not the merged host. (R2R debug and inlining info is already stripped forwasi-*byMicrosoft.NET.CrossGen.targetssince Disable unused ReadyToRun metadata on WebAssembly #134690.)tests.wasi.targets): CoreCLR test hosts keep names but drop DWARF (WasmNativeStrip=falseandWasmNativeDebugSymbols=false), so wasmtime backtraces in Helix logs stay readable.Sizes
Trimmed console app on the
12.0.0-alpha.1.26574.109packs (their targets matchmain), wasi-sdk 34:mainKeeping names without DWARF (
WasmNativeStrip=false+WasmNativeDebugSymbols=false) adds roughly 0.6 MB (non-R2R) to 1.8 MB (R2R), measured on the earlier 26565 packs. The R2R payload (1,156,448 B) is unchanged here because the local 26565 SDK predates #134690; newer SDKs strip R2R debug info on their own.Validation
Baseline: the stock 26574.109
Microsoft.NET.Runtime.WebAssembly.Wasi.Sdkpack, whose targets are byte-identical tomain. This PR: the same pack with this branch'sWasiApp.CoreCLR.targets,WasmApp.Common.targets, and locally builtWasmAppBuilder/Webcil assemblies dropped in. SDK 26565, wasi-sdk 34, wasmtime 49.wasm-tools validate --features all, and the stripped hosts have nonameor.debug_*sections.Environment.FailFasttrap, symbolized throughcorerun.symbols, gives the same 16 frames as the unstripped baseline. With R2R this includes managed frames such asapp_Program__FailandS_P_CoreLib_System_Environment__FailFast.WasmEmitSymbolMap=falseandWasmNativeStrip=false(removes or restores the sidecar and DWARF correctly).WebcilInWasmSizesTests.WasmComponentSymbols_StripsFirstCoreModuleSymbolscovers the component rewrite and symbol map with a synthetic component. I ran it outside Wasm.Build.Tests (this worktree has nolibsbuild), compiled verbatim against the rebuilt Webcil assembly: 2/2 passed.Not done:
StripWasiComponentSymbols. Wasm.Build.Tests doesn't run for CoreCLR WASI, and the WasmAppBuilder tasks have no unit-test project.Notes
namesection. It can't load a symbol-map sidecar, and it ignores.dwpDWARF packages for components. So stripped Release hosts show<wasm function N>, andcorerun.symbolsmaps those back to names. This matches the default for NativeAOT on wasm and Mono WASI (-Wl,-s). To keep names in the host, setWasmNativeStrip=falseandWasmNativeDebugSymbols=false.corerunin the runtime pack also carries about 34 MB of DWARF. It's excluded from app bundles, so that's left for a separate change.Note
This pull request description was generated with GitHub Copilot.