Commit 05762b6e authored by Dmitry Kazakov's avatar Dmitry Kazakov

Add a CMake option for ASAN address sanitizer

Summary:
To activate sanitizer you should activate three options (it will cause
a full rebuild):

-DCMAKE_BUILD_TYPE=Debug \
-DKRITA_DEVS=ON \
-DKRITA_DEVS_SANITIZER

After that, yiou should install llvm to get pretty
backtrace output with resolved symbols:

# find out the version of llvm installed
sudo apt list 'libllvm*'

# install the corresponding llvm binaries
sudo apt install llvm-X.X # where X.X is a version of libllvm package

export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-X.X # where X.X is the verison of your llvm
export ASAN_OPTIONS=fast_unwind_on_malloc=1:symbolize=1:malloc_context_size=15

Test Plan:
Compile Krita and try to make it crash with a memory problem. Instead
of failing with SIGSEGV it should crash with ASAN backtrace :)

Reviewers: #krita, rempt

Tags: #krita

Differential Revision: https://phabricator.kde.org/D17853
parent 46cf08f0
......@@ -264,6 +264,7 @@ include(GenerateExportHeader)
include(ECMMarkAsTest)
include(ECMInstallIcons)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(WriteBasicConfigVersionFile)
include(CheckFunctionExists)
......@@ -406,8 +407,20 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif()
option(KRITA_DEVS "For Krita developers. This modifies the DEBUG build type to use -O3 -g, while still enabling Q_ASSERT. This is necessary because the Qt5 cmake modules normally append QT_NO_DEBUG to any build type that is not labeled Debug")
CMAKE_DEPENDENT_OPTION(KRITA_DEVS_SANITIZER "Activate ASAN memory sanitizer for the build (available only with KRITA_DEVS)" ON
"KRITA_DEVS" OFF)
if (KRITA_DEVS)
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -g" CACHE STRING "" FORCE)
if (NOT KRITA_DEVS_SANITIZER)
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -g " CACHE STRING "" FORCE)
else()
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -g -fsanitize=address -lasan -fno-omit-frame-pointer" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-O3 -g -fsanitize=address -lasan -fno-omit-frame-pointer" CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "-O3 -g -fsanitize=address -lasan -fno-omit-frame-pointer" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG "-O3 -g -fsanitize=address -lasan -fno-omit-frame-pointer" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "-O3 -g -fsanitize=address -lasan -fno-omit-frame-pointer" CACHE STRING "" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "-O3 -g -fsanitize=address -lasan -fno-omit-frame-pointer" CACHE STRING "" FORCE)
endif()
endif()
if(UNIX)
......@@ -428,6 +441,11 @@ if(MINGW)
string(REPLACE "-Wl,--export-all-symbols" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
endif(MINGW)
if (KRITA_DEVS_SANITIZER)
string(REPLACE "-Wl,--no-undefined" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
string(REPLACE "-Wl,--no-undefined" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
endif()
# enable exceptions globally
kde_enable_exceptions()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment