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 -fsanitize-address
.
From what I understand, if I want to use address sanitizer with a library I have to build it as a shared object (which is the default option for GCC). Because of this, I thought the best option would be to build address sanitizer statically with -static-libasan
for the executables and build it dinamically for the libraries. However, when I do that I get a link error when building one of the C++ executables:
==10823==Your application is linked against incompatible ASan runtimes
This makes me think that static and dynamic version of address sanitizer cannot be mixed with GCC, am I right? I was not able to find any information about this on the sanitizers GitHub page.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With