Getting undefined symbol: __asan_memset when trying to use Clang address sanitizer

倖福魔咒の 提交于 2019-12-11 01:17:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!