Skip to content

Fix spurious BROKEN frames on musl-based Linux stacks#2437

Merged
brianrob merged 1 commit into
microsoft:mainfrom
brianrob:brianrob/fix-musl-broken-stacks
Jun 24, 2026
Merged

Fix spurious BROKEN frames on musl-based Linux stacks#2437
brianrob merged 1 commit into
microsoft:mainfrom
brianrob:brianrob/fix-musl-broken-stacks

Conversation

@brianrob

Copy link
Copy Markdown
Member

Why

Traces captured with one-collect on musl-based Linux distros (e.g. Alpine) show a large fraction of stacks marked BROKEN when opened in PerfView or TraceEvent. On a real Alpine trace, about 18% of samples were broken. The root cause is that thread base frames on musl live in the combined libc + dynamic loader module, named like ld-musl-x86_64.so.1, which ReasonableTopFrame did not recognize as a legitimate thread-start module. We already special-case glibc's libc for the same reason; musl was simply missing.

What

  • TraceEventStacks.cs: In ReasonableTopFrame, treat any module whose name starts with ld-musl- (case-insensitive, so it covers x86_64, aarch64, etc.) as a valid top frame, mirroring the existing glibc libc handling. When matched, a stack rooted there is no longer wrapped in a BROKEN frame.

  • Added Universal/MuslBrokenStackTests.cs: a unit test that synthesizes a tiny in-memory V6 nettrace (no large trace binary added to the repo) containing a musl loader module, an ordinary library, and two cpu samples: one rooted in the musl module and one rooted in the ordinary library. It asserts the musl-rooted stack is not BROKEN while the ordinary-library-rooted stack still is, parameterized over both ld-musl-x86_64.so.1 and ld-musl-aarch64.so.1.

Validation

  • A throwaway TraceEvent-based console app run against the real Alpine trace confirmed broken stacks dropped from 18.4% to 3.7% (eliminating ~6,100 musl-rooted frames). The scratch app was not committed.
  • Confirmed the new test fails without the fix (musl stack marked BROKEN) and passes with it.
  • Full TraceEvent suite is green: 2272 passing on net8.0 and 2289 on net462, no regressions.

Notes for reviewers

The negative-case assertion (ordinary library still BROKEN) is intentional to guard against the match being too broad. The test writer emits a non-zero syncTimeQPC so iterating relative timestamps does not trip a Debug.Assert in QPCTimeToRelMSec; this is a test-harness detail only.

On musl distros (e.g. Alpine) libc and the dynamic loader are combined
into a single module named like ld-musl-x86_64.so.1, where threads start.
Treat it as a valid top frame so musl stacks aren't marked BROKEN, mirroring
the existing glibc libc handling. Add an in-memory nettrace unit test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@brianrob
brianrob marked this pull request as ready for review June 24, 2026 20:33
@brianrob
brianrob requested a review from a team as a code owner June 24, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants