-
Notifications
You must be signed in to change notification settings - Fork 15.7k
[libc++][hardening] Rework how the assertion handler can be overridden. #77883
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 2 commits
e8e95c5
86fc352
216605f
692aac0
8981ef9
50282f3
deae2b8
d38fe7e
dc9d771
d83f5a1
48db22a
230de80
5dd7588
b6bcc16
1f5cab9
0bef0fb
cfa7d34
6cb68e6
8cc2fff
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 |
|---|---|---|
|
|
@@ -1019,9 +1019,12 @@ foreach(feature LIBCXX_ENABLE_FILESYSTEM LIBCXX_ENABLE_LOCALIZATION LIBCXX_ENABL | |
| endforeach() | ||
|
|
||
| configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY) | ||
| file(READ ${LIBCXX_ASSERTION_HANDLER_FILE} _LIBCPP_ASSERTION_HANDLER_OVERRIDE) | ||
|
||
| configure_file("__assertion_handler.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__assertion_handler" @ONLY) | ||
| configure_file("module.modulemap.in" "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap" @ONLY) | ||
|
|
||
| set(_all_includes "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" | ||
| "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__assertion_handler" | ||
| "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap") | ||
| foreach(f ${files}) | ||
| set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}") | ||
|
|
@@ -1059,6 +1062,12 @@ if (LIBCXX_INSTALL_HEADERS) | |
| PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ | ||
| COMPONENT cxx-headers) | ||
|
|
||
| # Install the generated __assertion_handler file to the per-target include dir. | ||
| install(FILES "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__assertion_handler" | ||
| DESTINATION "${LIBCXX_INSTALL_INCLUDE_TARGET_DIR}" | ||
| PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ | ||
var-const marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| COMPONENT cxx-headers) | ||
|
|
||
| # Install the generated modulemap file to the generic include dir. | ||
| install(FILES "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap" | ||
| DESTINATION "${LIBCXX_INSTALL_INCLUDE_DIR}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // -*- C++ -*- | ||
var-const marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #ifndef _LIBCPP___ASSERTION_HANDLER | ||
| #define _LIBCPP___ASSERTION_HANDLER | ||
|
|
||
| #include <__config> | ||
|
|
||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
| # pragma GCC system_header | ||
| #endif | ||
|
|
||
| @_LIBCPP_ASSERTION_HANDLER_OVERRIDE@ | ||
|
|
||
| #endif // _LIBCPP___ASSERTION_HANDLER | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // -*- C++ -*- | ||
|
Member
Author
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. Do we want to prefix this filename with
Member
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. We need to, if it gets installed into
Member
Author
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. Sorry, I mean this specific file. During installation, it gets renamed to
Member
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. I guess I would leave it without |
||
| #include <__config> | ||
| #include <__verbose_abort> | ||
|
|
||
| #if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG | ||
var-const marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #define _LIBCPP_ASSERTION_HANDLER(error_message, ...) ((void)error_message, _LIBCPP_VERBOSE_ABORT(__VA_ARGS__)) | ||
|
|
||
| #else | ||
|
|
||
| // TODO(hardening): in production, trap rather than abort. | ||
| #define _LIBCPP_ASSERTION_HANDLER(error_message, ...) ((void)error_message, _LIBCPP_VERBOSE_ABORT(__VA_ARGS__)) | ||
|
|
||
| #endif // #if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG | ||
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.
Looking at the code it feels somewhat clunky to me.
Why would the following approach not work?
Then in
libcxx/include/CMakeLists.txtyou copy this file and no configuring at all.The current approach would result in a file below or am I missing something.
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.
Injecting the contents of the header should give us a little more control over the custom handler. In particular, it is currently up to the vendor whether they want to allow users to override the macro. To support overriding, a custom implementation might first check that the macro isn't already defined, e.g. on the command line:
That way, a user can compile with
-D_LIBCPP_ASSERTION_HANDLER(...)=my_project::special_assert(__VA_ARGS__)and it will be honored. Or the vendor could do the opposite and explicitly forbid overriding:If in a future release we wanted to make sure that the handler can always be overridden by users, we could change our header to do something like:
We don't necessarily want to do that, but I think leaving us some degree of flexibility in this regard is useful.
Also, this allows us to provide some internal includes for the custom header in a supported manner. E.g. we can make
<__config>available without having the vendor include that internal header explicitly (which we generally don't support), and if in the future we decided to granularize<__config>, we could update the includes without the vendor having to update their code.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.
@mordante After writing this, I realized that we can just as well do something like:
which alleviates my concern. In fact, I think both approaches have equal expressive power and are not visible to the user/vendor. I think they're very similar, but having a single header seems to be a little simpler/cleaner, so I'll give it a shot based on your suggestion.