Skip to content

Commit cc6e3d5

Browse files
ldionnellvmbot
authored andcommitted
[libc++] Add checks for misused hardening macros (#150669)
Libc++ hardening went through several iterations, sometimes within a single release. However, some folks in the wild have picked up these macros that were either public at some point or that were used temporarily on `main`, and unfortunately those are now ignored. This can lead to some users thinking they enable hardening when in reality they don't, which is a pretty big deal. This patch simply checks various old hardening-related macros and ensures that they are not set, which will catch such misuse. (cherry picked from commit 955ece4)
1 parent d8e9216 commit cc6e3d5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

libcxx/include/__config

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,21 @@
4040

4141
// HARDENING {
4242

43-
// TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated.
44-
# ifdef _LIBCPP_ENABLE_ASSERTIONS
45-
# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead"
43+
// TODO(LLVM 23): Remove this. We're making these an error to catch folks who might not have migrated.
44+
// Since hardening went through several changes (many of which impacted user-facing macros),
45+
// we're keeping these checks around for a bit longer than usual. Failure to properly configure
46+
// hardening results in checks being dropped silently, which is a pretty big deal.
47+
# if defined(_LIBCPP_ENABLE_ASSERTIONS)
48+
# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
49+
# endif
50+
# if defined(_LIBCPP_ENABLE_HARDENED_MODE)
51+
# error "_LIBCPP_ENABLE_HARDENED_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
52+
# endif
53+
# if defined(_LIBCPP_ENABLE_SAFE_MODE)
54+
# error "_LIBCPP_ENABLE_SAFE_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
55+
# endif
56+
# if defined(_LIBCPP_ENABLE_DEBUG_MODE)
57+
# error "_LIBCPP_ENABLE_DEBUG_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
4658
# endif
4759

4860
// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:

0 commit comments

Comments
 (0)