diff options
author | Alexey Samsonov <samsonov@google.com> | 2013-03-26 07:49:46 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2013-03-26 07:49:46 +0000 |
commit | 777fccbe65f23d8a19bde1a8b69776c9a9209476 (patch) | |
tree | 2cec72d33df77a4ebaa676f91741bc93a4194c6d /cmake | |
parent | 0f3e4b149503d85403ec1181e5ffe9b60509c090 (diff) | |
download | external_llvm-777fccbe65f23d8a19bde1a8b69776c9a9209476.zip external_llvm-777fccbe65f23d8a19bde1a8b69776c9a9209476.tar.gz external_llvm-777fccbe65f23d8a19bde1a8b69776c9a9209476.tar.bz2 |
Add CMake option LLVM_USE_SANITIZER={Address,Memory,MemoryWithOrigins} to simplify bootstrap of LLVM/Clang under ASan/MSan
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177992 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/HandleLLVMOptions.cmake | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 528320b..4e59a3e 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -60,9 +60,9 @@ else(WIN32) endif(WIN32) function(add_flag_or_print_warning flag) - check_c_compiler_flag(${flag} C_SUPPORTS_${flag}) - check_cxx_compiler_flag(${flag} CXX_SUPPORTS_${flag}) - if (C_SUPPORTS_${flag} AND CXX_SUPPORTS_${flag}) + check_c_compiler_flag(${flag} C_SUPPORTS_FLAG) + check_cxx_compiler_flag(${flag} CXX_SUPPORTS_FLAG) + if (C_SUPPORTS_FLAG AND CXX_SUPPORTS_FLAG) message(STATUS "Building with ${flag}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE) @@ -85,6 +85,13 @@ function(append_if condition value) endif() endfunction() +macro(add_flag_if_supported flag) + check_c_compiler_flag(${flag} C_SUPPORTS_FLAG) + append_if(C_SUPPORTS_FLAG "${flag}" CMAKE_C_FLAGS) + check_cxx_compiler_flag(${flag} CXX_SUPPORTS_FLAG) + append_if(CXX_SUPPORTS_FLAG "${flag}" CMAKE_CXX_FLAGS) +endmacro() + if( LLVM_ENABLE_PIC ) if( XCODE ) # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't @@ -223,6 +230,38 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) endif (LLVM_ENABLE_WERROR) endif( MSVC ) +macro(append_common_sanitizer_flags) + # Append -fno-omit-frame-pointer and turn on debug info to get better + # stack traces. + add_flag_if_supported("-fno-omit-frame-pointer") + if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND + NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") + add_flag_if_supported("-gline-tables-only") + endif() +endmacro() + +# Turn on sanitizers if necessary. +if(LLVM_USE_SANITIZER) + if (LLVM_ON_UNIX) + if (LLVM_USE_SANITIZER STREQUAL "Address") + append_common_sanitizer_flags() + add_flag_or_print_warning("-fsanitize=address") + elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") + append_common_sanitizer_flags() + add_flag_or_print_warning("-fsanitize=memory") + # -pie is required for MSan. + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") + if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") + add_flag_or_print_warning("-fsanitize-memory-track-origins") + endif() + else() + message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") + endif() + else() + message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") + endif() +endif() + add_llvm_definitions( -D__STDC_CONSTANT_MACROS ) add_llvm_definitions( -D__STDC_FORMAT_MACROS ) add_llvm_definitions( -D__STDC_LIMIT_MACROS ) |