Skip to content

[libc++][hardening] Check that _LIBCPP_HARDENING_MODE_DEFAULT is defined #80353

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

Conversation

var-const
Copy link
Member

If the _LIBCPP_HARDENING_MODE_DEFAULT macro is not defined, _LIBCPP_HARDENING_MODE will be considered defined but fail the check for a valid hardening mode, resulting in a slightly less understandable error (that error is really meant more to prevent users from passing incorrect values such as 0 or 1 directly rather than catching configuration issues).

…fined

If the `_LIBCPP_HARDENING_MODE_DEFAULT` macro is not defined,
`_LIBCPP_HARDENING_MODE` will be considered defined but fail the check
for a valid hardening mode, resulting in a slightly less understandable
error (that error is really meant more to prevent users from passing
incorrect values such as `0` or `1` directly rather than catching
configuration issues).
@var-const var-const added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. hardening Issues related to the hardening effort labels Feb 1, 2024
@var-const var-const requested a review from a team as a code owner February 1, 2024 22:11
@var-const var-const assigned var-const and ldionne and unassigned var-const and ldionne Feb 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 1, 2024

@llvm/pr-subscribers-libcxx

Author: Konstantin Varlamov (var-const)

Changes

If the _LIBCPP_HARDENING_MODE_DEFAULT macro is not defined, _LIBCPP_HARDENING_MODE will be considered defined but fail the check for a valid hardening mode, resulting in a slightly less understandable error (that error is really meant more to prevent users from passing incorrect values such as 0 or 1 directly rather than catching configuration issues).


Full diff: https://github.com/llvm/llvm-project/pull/80353.diff

1 Files Affected:

  • (modified) libcxx/include/__config (+5)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index d356960e9e62b..2101490c3a8c5 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -325,6 +325,11 @@
 // clang-format on
 
 #  ifndef _LIBCPP_HARDENING_MODE
+
+#    ifndef _LIBCPP_HARDENING_MODE_DEFAULT
+#      error _LIBCPP_HARDENING_MODE_DEFAULT is not defined.
+#    endif
+
 #    define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
 #  endif
 

@@ -325,6 +325,11 @@
// clang-format on

# ifndef _LIBCPP_HARDENING_MODE

# ifndef _LIBCPP_HARDENING_MODE_DEFAULT
# error _LIBCPP_HARDENING_MODE_DEFAULT is not defined.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to speculate in the comment as to why that might be the case? E.g.

// Normally this macro comes from the `__config_site` header which is generated via CMake.
// If you use a custom build system, please make sure to define `_LIBCPP_HARDENING_MODE_DEFAULT`
// to one of the valid hardening modes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say something like This definition should be set at configuration-time in the __config_site header, please ensure your installation of libc++ is not broken -- or something like that. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@var-const var-const merged commit 091fc81 into llvm:main Feb 6, 2024
@var-const var-const deleted the varconst/hardening-check-default-macro branch February 6, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hardening Issues related to the hardening effort libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants