-
Couldn't load subscription status.
- Fork 15k
[libc++][hardening][NFC] Introduce _LIBCPP_VERBOSE_TRAP macro.
#148262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ldionne
merged 2 commits into
llvm:main
from
var-const:varconst/hardening-semantics-split-verbose_trap
Jul 14, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // -*- C++ -*- | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _LIBCPP___VERBOSE_TRAP | ||
| #define _LIBCPP___VERBOSE_TRAP | ||
|
|
||
| #include <__config> | ||
|
|
||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
| # pragma GCC system_header | ||
| #endif | ||
|
|
||
| _LIBCPP_BEGIN_NAMESPACE_STD | ||
|
|
||
| #if __has_builtin(__builtin_verbose_trap) | ||
| // AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream | ||
| // version before upstream Clang actually got the builtin. | ||
| // TODO: Remove once AppleClang supports the two-arguments version of the builtin. | ||
| # if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700 | ||
| # define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap(message) | ||
| # else | ||
| # define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap("libc++", message) | ||
| # endif | ||
| #else | ||
| # define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap()) | ||
| #endif | ||
|
|
||
| _LIBCPP_END_NAMESPACE_STD | ||
|
|
||
| #endif // _LIBCPP___VERBOSE_TRAP |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: what do we do about the frozen headers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good question, and actually it's not easy to answer IMO. CCing @philnik777 .
I see a few options:
<__cxx03/__verbose_trap>. This seems to go against the notion of having "frozen headers"._LIBCPP_VERBOSE_TRAPinline insidedefault_assertion_handler.ininside this#ifblock. This is equivalent to (1) except we don't introduce a new header under__cxx03.default_assertion_handler.in. So this means get rid of the#ifand always include<__config>and<__verbose_abort>, never their<__cxx03/...>counterparts. This would be doable since<__verbose_abort>doesn't actually need C++11, but it goes against the principle of the split and may cause other conflicts if we somehow end up including both<__config>and<__cxx03/__config>.default_assertion_handler.in, one normal and one for the frozen headers. This is a bit tricky sincedefault_assertion_handler.inis something we set up from CMake and expect vendors to be able to override.I think (1) is the best outcome here. We'll have to support these hardening improvements in frozen-C++03 anyways otherwise this'll be a regression in functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comprehensive overview of alternatives, this is super useful!
From what I gather, the frozen headers are still undergoing development, so them being completely frozen is the end goal rather than a description of the current state. If that perspective is valid, I also think that option (1) is the best, or at least the lesser evil out of the available options.