Skip to content

Commit 955ece4

Browse files
authored
[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.
1 parent 0f35244 commit 955ece4

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
@@ -64,9 +64,21 @@
6464

6565
// HARDENING {
6666

67-
// TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated.
68-
# ifdef _LIBCPP_ENABLE_ASSERTIONS
69-
# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead"
67+
// TODO(LLVM 23): Remove this. We're making these an error to catch folks who might not have migrated.
68+
// Since hardening went through several changes (many of which impacted user-facing macros),
69+
// we're keeping these checks around for a bit longer than usual. Failure to properly configure
70+
// hardening results in checks being dropped silently, which is a pretty big deal.
71+
# if defined(_LIBCPP_ENABLE_ASSERTIONS)
72+
# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
73+
# endif
74+
# if defined(_LIBCPP_ENABLE_HARDENED_MODE)
75+
# error "_LIBCPP_ENABLE_HARDENED_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
76+
# endif
77+
# if defined(_LIBCPP_ENABLE_SAFE_MODE)
78+
# error "_LIBCPP_ENABLE_SAFE_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
79+
# endif
80+
# if defined(_LIBCPP_ENABLE_DEBUG_MODE)
81+
# error "_LIBCPP_ENABLE_DEBUG_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
7082
# endif
7183

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

0 commit comments

Comments
 (0)