Skip to content

feat(sframe): complete SFrame V2 parser — replace stub with full implementation#471

Draft
jbachorik wants to merge 3 commits into
mainfrom
jb/sframe
Draft

feat(sframe): complete SFrame V2 parser — replace stub with full implementation#471
jbachorik wants to merge 3 commits into
mainfrom
jb/sframe

Conversation

@jbachorik

@jbachorik jbachorik commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?:

Completes the SFrame V2 parser that was partially landed in #491 (stub parseFDE returning true, integration removed from parseDwarfInfo). This PR replaces the stub with the full implementation and restores the SFrame-before-DWARF fast path.

parseDwarfInfo() now checks for a .sframe section first via PT_GNU_SFRAME. If present and valid, it parses the SFrame data directly into the existing FrameDesc* table and returns. If absent or invalid, it falls back to the existing .eh_frame DWARF path. Walk-time code (StackWalker::walkDwarf(), CodeCache::findFrameDesc()) is completely unchanged.

Motivation:

SFrame is a simpler ELF section format that directly encodes CFA/FP/RA offsets in flat, binary-searchable tables without requiring a DWARF CFI bytecode interpreter. On modern Linux distros (Fedora 43+, glibc 2.42+, binutils 2.40+), libraries ship .sframe sections alongside .eh_frame. Parsing SFrame is faster than interpreting DWARF opcodes at library load time.

Additional Notes:

  • Linux/ELF only. macOS is unaffected (PT_GNU_SFRAME is never found on Mach-O).
  • No new user-visible CStack mode.
  • Both x86_64 and aarch64 supported, including aarch64 GCC vs Clang default frame detection.
  • SFrameParser is self-contained (sframe.h/sframe.cpp), depends only on dwarf.h.
  • No external dependencies. No build file changes (Gradle auto-discovers new files).
  • Includes hardening from code review: OOM detection in addRecord, fde->fre_off pre-check before pointer arithmetic, cfa_fixed_fp_offset applied symmetrically with cfa_fixed_ra_offset, unsigned loc arithmetic, CFA 24-bit overflow guard matching DwarfParser, may_alias annotation on packed structs, qsort skipped when SFRAME_F_FDE_SORTED is set.

How to test the change?:

  • 30+ unit tests in sframe_ut.cpp covering: header validation, FDE loop (empty/PCMASK/empty-FRE skip), FRE parsing (SP/FP-based CFA, fixed/per-FRE RA, leaf functions), offset encodings (1B, 2B, 4B), multiple FDEs with sort verification (including reverse-order input), address translation with non-zero section_offset, FRE bounds overrun recovery, destructor memory safety, aarch64 default frame detection, auxhdr_len positive path, reserved encoding rejection, and individual bounds guard coverage.
  • ./gradlew :ddprof-lib:gtestDebug — all SFrame tests pass, existing DWARF tests unaffected.
  • ./gradlew ddprof-lib:compileRelease — builds on both Linux and macOS.
  • Integration on modern Linux (Fedora 43+): profile a Java app with cstack=dwarf, verify native stacks are collected via the SFrame path.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: [JIRA-XXXX]

Unsure? Have a question? Request a review!

@jbachorik jbachorik added the AI label Apr 14, 2026
@dd-octo-sts

dd-octo-sts Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #27267281494 | Commit: 33843da | Duration: 2m 45s (longest job)

32 of 32 test jobs failed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - - -
8-ibm - - -
8-j9 - -
8-librca - -
8-orcl - - -
11 - - -
11-j9 - -
11-librca - -
17 - -
17-graal - -
17-j9 - -
17-librca - -
21 - -
21-graal - -
21-librca - -
25 - -
25-graal - -
25-librca - -

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Failed Tests

musl-aarch64/debug / 21-librca

Job: View logs

No detailed failure information available. Check the job logs.

musl-amd64/debug / 8-librca

Job: View logs

No detailed failure information available. Check the job logs.

musl-amd64/debug / 25-librca

Job: View logs

No detailed failure information available. Check the job logs.

musl-aarch64/debug / 11-librca

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 17-graal

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 21

Job: View logs

No detailed failure information available. Check the job logs.

musl-aarch64/debug / 25-librca

Job: View logs

No detailed failure information available. Check the job logs.

musl-aarch64/debug / 17-librca

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 8-j9

Job: View logs

No detailed failure information available. Check the job logs.

musl-aarch64/debug / 8-librca

Job: View logs

No detailed failure information available. Check the job logs.

musl-amd64/debug / 17-librca

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 11-j9

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 25-graal

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 17

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 17-j9

Job: View logs

No detailed failure information available. Check the job logs.

musl-amd64/debug / 21-librca

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 21-graal

Job: View logs

No detailed failure information available. Check the job logs.

musl-amd64/debug / 11-librca

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 8

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 25-graal

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 11

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 21-graal

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 8-j9

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 21

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 17-graal

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 25

Job: View logs

No detailed failure information available. Check the job logs.

glibc-aarch64/debug / 25

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 17

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 8-ibm

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 11-j9

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 8-orcl

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 17-j9

Job: View logs

No detailed failure information available. Check the job logs.

Summary: Total: 32 | Passed: 0 | Failed: 32


Updated: 2026-06-10 09:42:51 UTC

@jbachorik jbachorik changed the title Parse .sframe sections as alternative to .eh_frame feat(sframe): complete SFrame V2 parser — replace stub with full implementation Jun 10, 2026
@datadog-official

This comment has been minimized.

Replaces the stub parseFDE with the full implementation and
restores the SFrame-before-DWARF integration in parseDwarfInfo.

Includes fixes from sphinx review: OOM handling, fre_off bounds
check, cfa_fixed_fp_offset, unsigned loc arithmetic, CFA overflow
guard, may_alias annotation, qsort flag guard, and expanded tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant