Skip to content

Fix: Add cxxabi fallback to buffer-based demangle function#2582

Open
SHH123-crypto wants to merge 1 commit into
facebook:mainfrom
SHH123-crypto:fix-demangle-cxxabi-fallback
Open

Fix: Add cxxabi fallback to buffer-based demangle function#2582
SHH123-crypto wants to merge 1 commit into
facebook:mainfrom
SHH123-crypto:fix-demangle-cxxabi-fallback

Conversation

@SHH123-crypto

Copy link
Copy Markdown

Fixes #2546

The buffer-based demangle() function now falls back to cxxabi when libiberty is not available, matching the behavior of the string-based version. This ensures stack traces are readable even without binutils-dev.

@meta-cla meta-cla Bot added the CLA Signed label Feb 6, 2026
@yfeldblum

Copy link
Copy Markdown
Contributor
  • Every line shows as changed in the Files changed view.
  • The demangle overload which writes to the argument out-buffer is called in signal handlers. It must not allocate.
@SHH123-crypto SHH123-crypto force-pushed the fix-demangle-cxxabi-fallback branch from 2e075c3 to 60fb359 Compare February 20, 2026 21:29
The buffer-based demangle() function now falls back to cxxabi when
libiberty is not available, matching the behavior of the string-based
version. This ensures stack traces are readable even without binutils-dev.

Key changes:
- Pass the user-provided buffer to __cxa_demangle instead of nullptr
- This avoids allocation while still enabling demangling
- Maintains async-signal-safety as required for signal handlers
- Updates tests to expect demangling with either liberty or cxxabi

Fixes facebook#2546
@SHH123-crypto SHH123-crypto reopened this Feb 20, 2026
@yfeldblum

Copy link
Copy Markdown
Contributor

__cxa_demangle may and typically does allocate internally, even when it is provided with an output buffer. This would be forbidden when invoked within a signal handler.

The overload of demangle which returns fbstring already allocates for the fbstring and is therefore already forbidden in signal handlers. So that overload has a fallback to __cxa_demangle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants