Getting undefined symbol: __asan_memset when tryin

2019-07-13 01:38发布

问题:

I'm trying to use address sanitizer with clang to compile a C++ application but getting the following error:

/Class.so: undefined symbol: __asan_memset

I have added -fsanitize=address to the compiler flags

/opt/llvm-3.8.0/bin/clang++ -M --gcc-toolchain=/opt/gcc-5.2.0 -fsanitize=address

and I have added -fsanitize=address and -lasan to the linker flags:

-fsanitize=address -lasan -shared -fuse-ld=gold-2.25 -o Class.so Class.o

What else do I need to do to get this to work?

回答1:

You main executable is probly not linked with -fsanitize=address. By default Clang links Asan runtime library (which provides definitions of __asan_memset and other Asan symbols) only to the executable, not shared libraries, and this causes errors in your case.

To work around this you can either relink executable with -fsanitize=address or relink sanitized shlibs with -shared-libasan and run with LD_PRELOAD=libclang_rt.asan.so.

For more details see AsanDSO wikipage.