Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable sanitizers in QMake?

How do I enable usage of sanitizers in QMake's .pro files?

I found several ressources that modify QMAKE_CXXFLAGS themselves but the introductory blogpost says:

It is scheduled for the dev branch (Qt 5.2) because it’s a new feature, but you should be fine cherry-picking it to e.g. Qt 5.0. You can then configure Qt with -address-sanitizer, and run qmake CONFIG+=address_sanitizer for your own applications.

However, adding CONFIG+=address_sanitizer does not seem to have an effect.

like image 206
Nobody moving away from SE Avatar asked Aug 19 '16 14:08

Nobody moving away from SE


1 Answers

To enable, e.g., address sanitizer you have to write:

CONFIG += sanitizer sanitize_address

The sanitizer options are defined in Qt's mkspecs (mkspecs/features/sanitizer.prf and mkspecs/common/sanitize.conf), which gets loaded when you add CONFIG += sanitizer. A quick look into my sanitizer.prf (Qt 5.7.0) shows that the specific sanitizers are:

  • sanitize_address
  • sanitize_memory
  • sanitize_thread
  • sanitize_undefined
like image 128
Nobody moving away from SE Avatar answered Sep 18 '22 14:09

Nobody moving away from SE