[libcxx-commits] [libcxxabi] 3de5e8b - [libc++abi] Build cxxabi with sanitizers (#119612)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Dec 12 18:03:16 PST 2024
Author: Vitaly Buka
Date: 2024-12-12T18:03:12-08:00
New Revision: 3de5e8b23f5c145b13d930eb5019566d3a6f88d5
URL: https://github.com/llvm/llvm-project/commit/3de5e8b23f5c145b13d930eb5019566d3a6f88d5
DIFF: https://github.com/llvm/llvm-project/commit/3de5e8b23f5c145b13d930eb5019566d3a6f88d5.diff
LOG: [libc++abi] Build cxxabi with sanitizers (#119612)
Added:
Modified:
libcxxabi/CMakeLists.txt
Removed:
################################################################################
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 158d61ff4fcb25..6dcfc51e553213 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -264,6 +264,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