I am working on a product that is composed of multiple C++ executables and libraries that have various dependencies on one another. I am building them all with GCC and
TLDR:
-fsanitize=address
.-fsanitize=address
and additionally export LD_PRELOAD=$(gcc -print-file-name=libasan.so)
when running your application.-fsanitize-address -shared-libasan
and additionally export LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)
when running the app.Now some explanations. Originally Asan existed only in Clang which by default used (and still uses) -static-libasan
. When it was ported to GCC, GCC developers decided that shared runtime is preferred (e.g. because it allows one to sanitize just one shared library and keep main executable unsanitized e.g. sanitize Python module without recompiling python.exe, see wiki for other examples). Both approaches are binary incompatible so you can't link part of your applications with static runtime and part with dynamic runtime.
Roughly
-fsanitize=address
is equivalent to Clangs -fsanitize=address -shared-libasan
(and -shared-libasan
is second-class citizen in Clang so not as well supported)-fsanitize=address
is equivalent to GCCs -fsanitize=address -static-libasan
(and again, -static-libasan
is second-class citizen in GCC so has some issues)As a side note, for other GCC/Clang Asan differences see this helpful wiki.