[CMake] Add ENABLE_ADDRESS_SANITIZER to make it easier to build with asan support
authormcatanzaro@igalia.com <mcatanzaro@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Feb 2018 23:23:28 +0000 (23:23 +0000)
committermcatanzaro@igalia.com <mcatanzaro@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Feb 2018 23:23:28 +0000 (23:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182400

Reviewed by Konstantin Tokarev.

* Source/cmake/OptionsGTK.cmake:
* Source/cmake/WebKitCompilerFlags.cmake:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228134 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
Source/cmake/OptionsGTK.cmake
Source/cmake/WebKitCompilerFlags.cmake

index e8a2145..4826faa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-02-05  Michael Catanzaro  <mcatanzaro@igalia.com>
+
+        [CMake] Add ENABLE_ADDRESS_SANITIZER to make it easier to build with asan support
+        https://bugs.webkit.org/show_bug.cgi?id=182400
+
+        Reviewed by Konstantin Tokarev.
+
+        * Source/cmake/OptionsGTK.cmake:
+        * Source/cmake/WebKitCompilerFlags.cmake:
+
 2018-01-31  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Update ReadMe.md
index bc54cb0..1b3cf14 100644 (file)
@@ -355,6 +355,11 @@ if (USE_WOFF2)
     endif ()
 endif ()
 
+# https://bugs.webkit.org/show_bug.cgi?id=182247
+if (ENABLED_COMPILER_SANITIZERS)
+    set(ENABLE_INTROSPECTION OFF)
+endif ()
+
 # Override the cached variables, gtk-doc and gobject-introspection do not really work when cross-building.
 if (CMAKE_CROSSCOMPILING)
     set(ENABLE_GTKDOC OFF)
index 7953a16..b778d79 100644 (file)
@@ -155,6 +155,21 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT "${LOWERCASE_CMAKE_HOST_SY
     set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "-Wl,--no-keep-memory ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
 endif ()
 
+if (COMPILER_IS_GCC_OR_CLANG)
+    # Careful: this needs to be above where ENABLED_COMPILER_SANITIZERS is set.
+    # Also, it's not possible to use the normal prepend/append macros for
+    # -fsanitize=address, because check_cxx_compiler_flag will report it's
+    # unsupported, because it causes the build to fail if not used when linking.
+    option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer" OFF)
+    if (ENABLE_ADDRESS_SANITIZER)
+        WEBKIT_PREPEND_GLOBAL_COMPILER_FLAGS(-fno-omit-frame-pointer
+                                             -fno-optimize-sibling-calls)
+        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_THREAD_LIBS_INIT} ${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
+        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_THREAD_LIBS_INIT} ${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
+    endif ()
+endif ()
 
 if (NOT MSVC)
     string(REGEX MATCHALL "-fsanitize=[^ ]*" ENABLED_COMPILER_SANITIZERS ${CMAKE_CXX_FLAGS})