-
Notifications
You must be signed in to change notification settings - Fork 13.5k
WIP [libc++][hardening] Overhaul the termination mechanism for hardening #77823
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// -*- C++ -*- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per our live review just now, we explored the following alternatives (using chrome as an example since we know they override verbose abort right now):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Further discussion: Since we may want to have use cases where the "verbose trap handler" doesn't actually abort the program (effectively deciding to ignore library-level UB), it would probably make sense to rename this. Suggestions:
There's probably more. The point is that if we use one of these names, using an implementation where don't actually terminate the program is now more natural. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More discussion! We could actually always use the overriding mechanism but provide our default definition for the assertion handler. That way, the code path for customizing the handler would always be tested, by definition. Something like: // in CMakeLists.txt
set(LIBCXX_ASSERTION_HANDLER "libcxx/vendor/llvm/assertion_handler.in" CACHE STR)
// in libcxx/include/__assertion_handler.in
#ifndef _LIBCPP___ASSERTION_HANDLER
#define _LIBCPP___ASSERTION_HANDLER
#include <__availability>
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
copy-paste the contents of @LIBCXX_ASSERTION_HANDLER@ at CMake configuration time
#endif // _LIBCPP___ASSERTION_HANDLER
// in libcxx/vendor/llvm/assertion_handler.in
#if HARDENING_MODE == DEBUG
# define _LIBCPP_VERBOSE_TRAP(message) ::std::__libcpp_verbose_abort(...)
#else
# define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
#endif |
||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 <__availability> | ||
#include <__config> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
// TODO: use `__builtin_verbose_trap(message) once available | ||
#define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap()) | ||
|
||
#endif // _LIBCPP___VERBOSE_TRAP |
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.
We should add a bit of documentation here that explains that
_LIBCPP_ASSERT(expr, msg)
is a no-op ifexpr
is true, and it's library-level UB in caseexpr
is false.