Uh oh!
There was an error while loading. Please reload this page.
Add WASM PerfMap support: OS/arch constants and correct R2R offsets - #132693
Conversation
Crossgen2 R2R compilation for browser-wasm and wasi-wasm targets threw System.NotImplementedException from PerfMapWriter.TranslateTargetDetailsToPerfmapConstants because PerfMapOSToken had no Browser/Wasi members and PerfMapArchitectureToken had no Wasm member, so the switch expressions hit their throwing default arms when PublishReadyToRunPerfmapFormatVersion was set. Add Browser/Wasi to PerfMapOSToken, Wasm to PerfMapArchitectureToken, map the corresponding TargetOS/TargetArchitecture values, and update the r2r-perfmap-format doc to match (also filling in the already-shipped OpenBSD/RiscV64/LoongArch64 rows). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 4 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. |
There was a problem hiding this comment.
Pull request overview
Adds missing PerfMap v1 target OS/architecture tokens and wiring so Crossgen2 ReadyToRun perfmap emission can support WebAssembly targets (Browser/WASI) without falling into the “unknown target” throwing paths. Also updates the design doc to reflect the expanded token sets.
Changes:
- Extend
PerfMapOSTokenwithBrowser/WasiandPerfMapArchitectureTokenwithWasm. - Map
TargetOS.Browser/TargetOS.WasiandTargetArchitecture.Wasm32to the new tokens inPerfMapWriter. - Update
r2r-perfmap-format.mdto include the current token tables.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.Diagnostics/ReadyToRunDiagnosticsConstants.cs | Adds new perfmap OS/arch enum values used as the on-disk perfmap contract. |
| src/coreclr/tools/aot/ILCompiler.Diagnostics/PerfMapWriter.cs | Extends target-to-token translation to cover Browser/WASI and Wasm32. |
| docs/design/coreclr/botr/r2r-perfmap-format.md | Documents the updated token values for perfmap v1 headers. |
Uh oh!
There was an error while loading. Please reload this page.
Populate the output section layout for the wasm/webcil object writer so OutputInfoBuilder.EnumerateMethods can resolve each method node's section; it previously threw ArgumentOutOfRangeException because the wasm writers never populated _outputSectionLayout. Remap each method node's offset and length to its post-shrink position (the code section is LEB128-shrunk during final emission) so perfmap entries point at the method's real file offset in the emitted module. Document the perfmap offset scheme in webcil.md.
|
Azure Pipelines: Successfully started running 4 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. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
adamperlin
left a comment
There was a problem hiding this comment.
Overall looks good to me, I just had a suggestion to clarify a comment.
Uh oh!
There was an error while loading. Please reload this page.
…ter.cs Co-authored-by: Adam Perlin <adamp@nanosoft.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/coreclr/tools/Common/Compiler/ObjectWriter/OutputInfoBuilder.cs:185
RemapMethodNodeOffsetsupdatesOutputNode.Offset/Length, but leavesOutputSymbol.Offsetunchanged. This makes the node/symbol lists inconsistent, andMapFileBuilder’sFindSymbol(node, ...)binary search can stop finding the corresponding symbol for code-section nodes once node offsets are remapped (affecting--map/--mapcsvoutput for wasm). Also considercheckedwhen recomputingnode.Offset + node.Length/ casting the new length back tointto avoid silent wrap/truncation on unexpectedly large sections.
internal void RemapMethodNodeOffsets(int sectionIndex, IReadOnlyDictionary<ulong, ulong> offsetMap)
{
foreach (OutputNode node in _nodes)
{
if (node.SectionIndex == sectionIndex
&& offsetMap.TryGetValue(node.Offset, out ulong postStart)
&& offsetMap.TryGetValue(node.Offset + (ulong)node.Length, out ulong postEnd))
{
Summary
Enables the ReadyToRun perfmap (
.ni.r2rmap) forbrowser-wasm/wasi-wasmtargets. Two sequential crashes were blocking it whenPublishReadyToRunPerfmapFormatVersionwas set:NotImplementedExceptioninPerfMapWriter.TranslateTargetDetailsToPerfmapConstants—PerfMapOSTokenhad noBrowser/Wasimembers andPerfMapArchitectureTokenhad noWasmmember, so theswitchexpressions hit their throwing default arms.ArgumentOutOfRangeExceptioninOutputInfoBuilder.EnumerateMethods(_sections[node.SectionIndex]) — the wasm object writers never populated_outputSectionLayout, unlike COFF/ELF/Mach-O/PE, so method nodes carried a validSectionIndexbut there were noOutputSections to index.Changes
PerfMap constants
Browser = 8andWasi = 9toPerfMapOSToken, andWasm = 7toPerfMapArchitectureToken(appended after the highest existing value to preserve the numeric contract consumed by symbol-upload / PerfView tooling).TargetOS.Browser/TargetOS.WasiandTargetArchitecture.Wasm32in thePerfMapWriterswitches.docs/design/coreclr/botr/r2r-perfmap-format.md, also filling in the already-shippedOpenBSD/RiscV64/LoongArch64rows.Correct wasm R2R offsets
_outputSectionLayoutinWebCilObjectWriter.EmitObjectFile(index-aligned with the wasm section table); the code section records the module-file offset where its function-body content lands.ResolveCodeRelocations), so each method's recorded (pre-shrink) offset no longer matches the final module. Build a pre→post entry-boundary offset map and remap every method node's offset and length to its post-shrink position, so a method'sRVA + Lengthequals the next code entry's offset.docs/design/mono/webcil.md.Address space / consumers
For wasm, a method's perfmap
RVAis the byte offset from the start of the.wasmmodule to its function entry in the Code section — a file offset into the module, not a virtual address or a Webcil payload RVA.Note
The only meaningful consumer of these wasm file offsets is a native-wasm profiler that keys frames by a code offset within the module (e.g. a wasm sampling profiler / DevTools-style correlation). EventPipe- and dotnet-trace-based symbolication identifies managed methods by module MVID + metadata token via method-load events and does not rely on these perfmap offsets. The perfmap is opt-in diagnostics; nothing in the runtime reads it.
Validation
ILCompiler.ReadyToRunbuilds clean (Release).System.Private.CoreLib.dllwith--perfmap --perfmap-format-version:1 --obj-format:wasm --targetarch:wasm --targetos:browser: exit 0 (previouslyArgumentOutOfRangeException), produced a.ni.r2rmapwith 47,731 methods, header tokens OS=8 (Browser) / arch=7 (Wasm) / version 1, and contiguous, non-overlapping method RVAs (confirming both offset and length are post-shrink correct).Note
This PR description and the code changes were generated with the assistance of GitHub Copilot.