简体   繁体   中英

How can I practically use AddressSanitizer and MemorySanitizer?

AddressSanitizer and MemorySanitizer are very useful tools, but they require that the whole program be appropriately instrumented. (At least, for the Clang version of AddressSanitizer; see here in the MemorySanitizer docs and the "using private aliases for globals" section of AddressSanitizerClangVsGCC .)

If taken at its word, this means that all library dependencies need to be built with the appropriate compiler flags to enable ASan or MSan. For a typical Linux application that requires various third-party dependencies, what's a practical way of doing this? The Sanitizers are apparently a Google project, and I get the impression that Google code mostly just uses their own monorepo and their own build tools , but this may be outside of the reach of the average developer. Is there a simple way of getting libraries built with the Sanitizers without investing in a lot of extra infrastructure or build scripts?

AddressSanitizer supports separate instrumentation ie you can instrument just parts of your program with it (separate DSOs or even separate object files). Note however that if you use static Asan runtime (which is default on Clang, unless you build with -shared-libasan ) you must instrument main executable. Shared runtime (default in GCC) does not have this problem but you'll need to LD_PRELOAD it if executable isn't instrumented. See discussion in wiki for details.

As for MemorySanitizer, it indeed requires all of it's dependencies to be rebuilt. This is the major reason why the tool isn't widely used outside Google.

The sanitizers can easily be used on your own code without rebuilding system dependencies. I do so routinely with a large(ish) 2M line code base on RHEL 6 & 7 using both GCC and Clang - it's not a problem. If it is a problem; you are doing it wrong (or there is a bug somewhere that needs fixing).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM