问题
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=$(clang -print-file-name=libclang_rt.asan-x86_64.so)
.
For more details see AsanDSO wikipage.
来源:https://stackoverflow.com/questions/50621054/getting-undefined-symbol-asan-memset-when-trying-to-use-clang-address-sanitiz