标题:Using gcc’s 4.8.0 Address Sanitizer with Qt
作者:fanformylove
日期:2013-04-17 21:44
内容:
source: http://blog.qt.digia.com/blog/2013/04/17/using-gccs-4-8-0-address-sanitizer-with-qt/
Using gcc’s 4.8.0 Address Sanitizer with Qt
Published April 17, 2013 | By Kai Koehne
One of the cool new features of gcc 4.8 is thebuilt in “Address Sanitizer”: a memory error detector for C/C++ thatwill tell you instantly when you e.g. access already deleted memory.This is actually a Google projectfrom Clang/LLVM, so for LLVM users this might be old stuff, but it wasn’t for me
Since documentation on every day use is still a bit scarce on the web,I’m dumping the gist of how to put it to good use here, especially inthe Qt context …
How does it work?
It basically overwrites malloc and free, and does check the memory before every access (see the project wikifor the details). Apparently it does that in a very efficient manner,since the slow down is only about 2x compared to uninstrumentedexecution! Who knows, maybe we can enable it for the Qt-Project CIsystem at one point?
Be warned though that it only works so far on Linux and Mac. No luck for MinGW
How to enable it?
Since it is part of the compiler suite enabling it is easy: just add -fsanitize=address -fno-omit-frame-pointer to the compiler calls, and -fsanitize=addressto the linker calls. Anyhow, to catch issues where the memory isallocated, de-allocated or accessed by Qt you do not only have toinstrument your applic ..