fix: guard abi::__forced_unwind catch behind __GLIBCXX__#505
Merged
Conversation
abi::__forced_unwind is declared by libstdc++ (any libc) but not by libc++, so the catch only compiles where libstdc++ is the active C++ stdlib. Guard on __GLIBCXX__ — defined by libstdc++ regardless of libc, undefined under libc++ — so the file compiles on macOS clang+libc++ (and any libc++ build) while keeping the cancellation cleanup wherever libstdc++ is in use. The exception itself is raised by glibc's pthread_cancel; on platforms with a different cancellation mechanism (musl, macOS, AIX) the catch is harmless dead code but compiles cleanly under libstdc++. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6c66bfe to
7583b8d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7583b8dffa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Drop the libstdc++-only try/catch around timerLoop's body and replace it with an RAII Cleanup struct. Destructors run during forced unwinding under any C++ stdlib, so the cleanup path is no longer compiled out on libc++ (macOS) and is preserved on glibc + libc++ — addressing the review comment from chatgpt-codex-connector on PR #505. Also drops the unused <cxxabi.h> include. Co-Authored-By: muse <muse@noreply>
Contributor
CI Test ResultsRun: #25170124398 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-04-30 18:28:42 UTC |
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.
What does this PR do?:
Wraps the
try { ... } catch (abi::__forced_unwind&) { ... }block inj9WallClock.cpp::timerLoop()with#if defined(__GLIBCXX__)so the file compiles on libc++ targets (macOS clang+libc++, Alpine clang+libc++).Motivation:
abi::__forced_unwindis a libstdc++ extension — declared in libstdc++'s<cxxabi.h>regardless of which libc is in use. libc++ (LLVM's C++ stdlib, the default on macOS clang) does not declare it. Commit25c702ba4(#492) introduced the catch without any guard, breaking builds on libc++ targets:Why GLIBCXX and not GLIBC
The compilation constraint is "is the C++ stdlib libstdc++?", not "is libc glibc?". The two are independent:
__GLIBCXX__is the precise predicate — it's defined by libstdc++ regardless of libc, undefined under libc++. The catch is harmless dead code on musl/macOS+libstdc++ but compiles cleanly there.The same pattern in
libraryPatcher_linux.cppis already inside#if defined(__linux__)so it compiles correctly. This change bringsj9WallClock.cppinto line.Additional Notes:
#include <cxxabi.h>is left unguarded — the header itself exists on libc++, it just doesn't declare theabi::__forced_unwindmember. Including it is harmless.OpenJ9 supports macOS, AIX, z/OS, Linux and Windows — but on every non-glibc platform J9's pthread_cancel uses a non-exception mechanism, so the catch is a no-op there regardless of whether it compiles. The guard is purely about compilation, not behaviour.
How to test the change?:
./gradlew :ddprof-lib:compileRelease— verified to succeed (Successfully compiled 59 files).forced_unwind_ut.cppunit test still exercises the catch path; behaviour unchanged.For Datadog employees:
@DataDog/security-design-and-guidance.🤖 Generated with Claude Code