diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-02-03 13:57:09 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-02-03 13:57:09 +0000 |
commit | 7db79d9c13f1d643703e267f9886102bdbf6c9cf (patch) | |
tree | 24c72becba895612147e4c65f5974b309b55e345 /cmake | |
parent | 17fec838c461638fefb4c33ee242adb776b1b3d5 (diff) | |
download | llvm-7db79d9c13f1d643703e267f9886102bdbf6c9cf.tar.gz llvm-7db79d9c13f1d643703e267f9886102bdbf6c9cf.tar.bz2 llvm-7db79d9c13f1d643703e267f9886102bdbf6c9cf.tar.xz |
Don't use -ffunction-sections if -fno-function-sections is not supported in the compiler.
This will disable -ffunction-sections in older versions of Clang where it
breaks build of sanitizer runtime library.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200695 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/HandleLLVMOptions.cmake | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 47d3b2f79d..38bbd2ea7e 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -350,13 +350,23 @@ if (UNIX AND append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() +# Clang prior to 3.5 ignored -fno-function-sections. +# It's pretty hard to test directly, so we rely on the version number. +if( ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) ) + set(LLVM_COMPILER_HAS_BROKEN_FNO_FUNCTION_SECTIONS ON) +endif() + # Add flags for add_dead_strip(). # FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF? # But MinSizeRel seems to add that automatically, so maybe disable these # flags instead if LLVM_NO_DEAD_STRIP is set. if(NOT CYGWIN AND NOT WIN32) if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - append("-ffunction-sections -fdata-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + # Don't add -ffunction-section if it can be disabled with -fno-function-sections. + # Doing so will break sanitizers. + if (NOT LLVM_COMPILER_HAS_BROKEN_FNO_FUNCTION_SECTIONS) + append("-ffunction-sections -fdata-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + endif() endif() endif() |