[llvm] [llvm][CMake] Respect LIBCXX_HARDENING_MODE on command-line (PR #68541)

Will Hawkins via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 8 15:44:33 PDT 2023


https://github.com/hawkinsw created https://github.com/llvm/llvm-project/pull/68541

When the user specifies `LIBCXX_HARDENING_MODE` on the command line in a bootstrapping build, it should override the setting implied by `LLVM_ENABLE_ASSERTIONS`.

>From 0efa88c7d30a2f0ba47383f0ac000972c98a77b2 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Sun, 8 Oct 2023 18:40:19 -0400
Subject: [PATCH] [llvm][CMake] Respect LIBCXX_HARDENING_MODE on command-line

When the user specifies LIBCXX_HARDENING_MODE on the command line
in a bootstrapping build, it should override the setting implied
by LLVM_ENABLE_ASSERTIONS.
---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index c5142c9e660fba4..a06c9fae27ccdb9 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -85,8 +85,13 @@ if( LLVM_ENABLE_ASSERTIONS )
   endif()
   # Enable assertions in libstdc++.
   add_compile_definitions(_GLIBCXX_ASSERTIONS)
-  # Enable the hardened mode in libc++.
-  add_compile_definitions(_LIBCPP_ENABLE_HARDENED_MODE)
+  # Cautiously enable the safe hardened mode in libc++.
+  if((DEFINED LIBCXX_HARDENING_MODE) AND
+     (NOT LIBCXX_HARDENING_MODE STREQUAL "safe"))
+    message(WARNING "LLVM_ENABLE_ASSERTIONS implies LIBCXX_HARDENING_MODE \"safe\" but is overriden from command line with value \"${LIBCXX_HARDENING_MODE}\".")
+  else()
+    set(LIBCXX_HARDENING_MODE "safe")
+  endif()
 endif()
 
 if(LLVM_ENABLE_EXPENSIVE_CHECKS)



More information about the llvm-commits mailing list