[libcxx-commits] [libcxx] [libc++] Build the dylib with sanitizers when requested (PR #73656)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 28 13:26:16 PST 2023


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/73656

>From f14d36a750b1fedd4013c938233610c2eb60014d Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 28 Nov 2023 10:00:37 -0500
Subject: [PATCH 1/2] [libc++] Build the dylib with sanitizers when requested

We were detecting which sanitizer flags to use when building libc++.dylib
but we were never actually adding those flags to the targets, which means
that our sanitized builds would basically build the dylib without any
sanitizers enabled.
---
 libcxx/CMakeLists.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 843ccbd0ed92edb..f32f9dc22e8bea6 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -639,6 +639,8 @@ function(get_sanitizer_flags OUT_VAR  USE_SANITIZER)
 endfunction()
 
 get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
+add_library(cxx-sanitizer-flags INTERFACE)
+target_compile_options(cxx-sanitizer-flags INTERFACE ${SANITIZER_FLAGS})
 
 # Link system libraries =======================================================
 function(cxx_link_system_libraries target)
@@ -821,6 +823,7 @@ function(cxx_add_common_build_flags target)
   cxx_add_rtti_flags(${target})
   cxx_add_module_flags(${target})
   cxx_link_system_libraries(${target})
+  target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)
 endfunction()
 
 #===============================================================================

>From 418b0aa0edcc2c75c16f109512b3061e9b86400c Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 28 Nov 2023 16:26:03 -0500
Subject: [PATCH 2/2] Fix quoting

---
 libcxx/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index f32f9dc22e8bea6..8572e7530fd363e 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -621,10 +621,10 @@ function(get_sanitizer_flags OUT_VAR  USE_SANITIZER)
         append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins")
       endif()
     elseif (USE_SANITIZER STREQUAL "Undefined")
-      append_flags(SANITIZER_FLAGS "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
+      append_flags(SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
     elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR
             USE_SANITIZER STREQUAL "Undefined;Address")
-      append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
+      append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all")
     elseif (USE_SANITIZER STREQUAL "Thread")
       append_flags(SANITIZER_FLAGS -fsanitize=thread)
     elseif (USE_SANITIZER STREQUAL "DataFlow")



More information about the libcxx-commits mailing list