I want to enable asan on my main executable and a shared library that I build locally.
main linker flag I think relavent to the sanitizer is
-fuse-ld=lld -static-libstdc++ -static-libsan -fsanitize=address.
I put them on both the linker and compiler which is clang++
now when i run by execuatable, i got the message saying:
myExecutable: symbol lookup error: SDL2.so undefined symbol: __asan_init
it sounds like that the executable is looking for __asan_init in SDL2.so, which i do not understand why since it should have the same static-libasan and -fsanitize=address flag itself.
dumping the symbol from SDL2.so
i could see
00000025b7c0 000500000007 R_X86_64_JUMP_SLO 0000000000000000 __asan_init + 0
00000025b7c8 000600000007 R_X86_64_JUMP_SLO 0000000000000000 __asan_version_mi[...] + 0
00000025b9e8 000700000007 R_X86_64_JUMP_SLO 0000000000000000 __asan_register_g[...] + 0
00000025b9f0 000800000007 R_X86_64_JUMP_SLO 0000000000000000 __asan_unregister[...] + 0
5: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __asan_init
6: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __asan_version_m[...]
7: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __asan_register_[...]
8: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __asan_unregiste[...]
they are undefined for some reason although i told compiler to link it statically and it didn’t complain at compile time, but only when i start to run it.
if i remove the sanitizer flags when compiling SDL2.so, the executable would run perfectly, but no instrumentation by sanitizer in the SDL2.so happen at all, which is expected.
I do not know whether sanitizer would work with building it statically into a shared lib.
does anyone has experience with this? Thanks!