[Bf-blender-cvs] [a4c5811e212] master: ASan/macOS: fix incomplete C/CXX compiler flags.

Ankit Meel noreply at git.blender.org
Tue Sep 15 22:49:05 CEST 2020


Commit: a4c5811e21271d0f26e0534f25800059c198982d
Author: Ankit Meel
Date:   Wed Sep 16 02:16:15 2020 +0530
Branches: master
https://developer.blender.org/rBa4c5811e21271d0f26e0534f25800059c198982d

ASan/macOS: fix incomplete C/CXX compiler flags.

While testing for {rB40dcf686f04f}, compiler flags got mixed up and
non-working ASan configuration was committed.

Platform file, which is `include`d after the `CMAKE_C_FLAGS_DEBUG` etc.,
are set, overwrites those flags instead of appending to them. To fix this,
`PLATFORM_CFLAGS` is used to pass the `-fsanitize=*` flags to the C/C++
compiler.

Tested on fresh build using both Xcode and Ninja, with & without ccache.

Also silence a clang warning for multi-config generators:
the object size sanitizer has no effect at -O0, but is explicitly
enabled: -fsanitize=object-size [-Winvalid-command-line-argument]

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D8879

===================================================================

M	CMakeLists.txt
M	build_files/cmake/platform/platform_apple.cmake

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6fc454a639c..c9a020ebbc3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -522,7 +522,8 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
       set(_asan_defaults "${_asan_defaults}")
     elseif(APPLE)
       # AppleClang doesn't support all sanitizers, but leak gives error.
-      if(CMAKE_BUILD_TYPE MATCHES "Debug")
+      # Build type is not known for multi-config generator, so don't add object-size sanitizer.
+      if(CMAKE_BUILD_TYPE MATCHES "Debug" OR GENERATOR_IS_MULTI_CONFIG)
         # Silence the warning that object-size is not effective in -O0.
         set(_asan_defaults "${_asan_defaults}")
       else()
@@ -553,9 +554,11 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
       )
       string(STRIP "${CLANG_LIB_DIR}" CLANG_LIB_DIR)
       find_library(
-        COMPILER_ASAN_LIBRARY NAMES libclang_rt.asan_osx_dynamic.dylib
+        COMPILER_ASAN_LIBRARY
+        NAMES
+          libclang_rt.asan_osx_dynamic.dylib
         PATHS
-        "${CLANG_LIB_DIR}/darwin/"
+          "${CLANG_LIB_DIR}/darwin/"
       )
       unset(CLANG_LIB_DIR)
     else()
@@ -858,6 +861,9 @@ if(NOT CMAKE_BUILD_TYPE MATCHES "Release")
       set(COMPILER_ASAN_LINKER_FLAGS "/FUNCTIONPADMIN:6")
     endif()
     if(APPLE)
+      # COMPILER_ASAN_CFLAGS and COMPILER_ASAN_CXXFLAGS are the same as of
+      # now, so use either for PLATFORM_CFLAGS.
+      set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} ${COMPILER_ASAN_CFLAGS}")
       set(COMPILER_ASAN_LINKER_FLAGS "-fno-omit-frame-pointer -fsanitize=address")
     endif(APPLE)
     if(COMPILER_ASAN_LIBRARY)
diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake
index 822110cb88f..c16fa4b2e30 100644
--- a/build_files/cmake/platform/platform_apple.cmake
+++ b/build_files/cmake/platform/platform_apple.cmake
@@ -190,7 +190,7 @@ if(SYSTEMSTUBS_LIBRARY)
   list(APPEND PLATFORM_LINKLIBS SystemStubs)
 endif()
 
-set(PLATFORM_CFLAGS "-pipe -funsigned-char")
+set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -pipe -funsigned-char")
 set(PLATFORM_LINKFLAGS
   "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework Metal -framework QuartzCore"
 )



More information about the Bf-blender-cvs mailing list