Add a CMake option for ASAN address sanitizer
ClosedPublic

Authored by dkazakov on Dec 29 2018, 12:57 PM.

Details

Summary

Activate sanitizer in CMake

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

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

Install symbolizer

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 :)

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
dkazakov created this revision.Dec 29 2018, 12:57 PM
Restricted Application added a project: Krita. · View Herald TranscriptDec 29 2018, 12:57 PM
dkazakov requested review of this revision.Dec 29 2018, 12:57 PM
dkazakov edited the summary of this revision. (Show Details)Dec 29 2018, 12:59 PM
dkazakov edited the summary of this revision. (Show Details)
rempt accepted this revision.Dec 31 2018, 12:27 PM

Looks good to me, but the part about installing llvm probably should be in the README.md or some place like that.

This revision is now accepted and ready to land.Dec 31 2018, 12:27 PM
This revision was automatically updated to reflect the committed changes.
pino added a subscriber: pino.Jan 8 2019, 10:10 AM

Just noticed this... note that ECM already provides it: https://api.kde.org/ecm/module/ECMEnableSanitizers.html

In D17853#388885, @pino wrote:

Just noticed this... note that ECM already provides it: https://api.kde.org/ecm/module/ECMEnableSanitizers.html

Oups, okay, I'll try to implement a new version of it :)