[libcxx-commits] [libcxxabi] [libc++abi] Build cxxabi with sanitizers (PR #119612)
Vitaly Buka via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Dec 12 15:27:50 PST 2024
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/119612
>From a73451ad39931d230eb8cb87df8135e2a41b8999 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 11 Dec 2024 12:48:16 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
libcxxabi/CMakeLists.txt | 43 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index da0e8b286cddc1..ea59310de5e539 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -259,6 +259,49 @@ if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
+function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
+ set(SANITIZER_FLAGS)
+ set(USE_SANITIZER "${USE_SANITIZER}")
+ # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
+ # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
+ if (USE_SANITIZER AND NOT MSVC)
+ append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer")
+ append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
+
+ if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
+ NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
+ append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only")
+ endif()
+ if (USE_SANITIZER STREQUAL "Address")
+ append_flags(SANITIZER_FLAGS "-fsanitize=address")
+ elseif (USE_SANITIZER STREQUAL "HWAddress")
+ append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress")
+ elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?")
+ append_flags(SANITIZER_FLAGS -fsanitize=memory)
+ if (USE_SANITIZER STREQUAL "MemoryWithOrigins")
+ 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")
+ 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")
+ elseif (USE_SANITIZER STREQUAL "Thread")
+ append_flags(SANITIZER_FLAGS -fsanitize=thread)
+ elseif (USE_SANITIZER STREQUAL "DataFlow")
+ append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
+ else()
+ message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
+ endif()
+ elseif(USE_SANITIZER AND MSVC)
+ message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
+ endif()
+ set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE)
+endfunction()
+
+get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}")
+list(APPEND LIBCXXABI_COMPILE_FLAGS ${SANITIZER_FLAGS})
+
# Let the library headers know they are currently being used to build the
# library.
add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY)
More information about the libcxx-commits
mailing list