[英]Getting undefined symbol: __asan_memset when trying to use Clang address sanitizer
I'm trying to use address sanitizer with clang to compile a C++ application but getting the following error:我正在尝试使用带有 clang 的地址清理程序来编译 C++ 应用程序,但出现以下错误:
/Class.so: undefined symbol: __asan_memset
/Class.so:未定义符号:__asan_memset
I have added -fsanitize=address to the compiler flags我已将 -fsanitize=address 添加到编译器标志
/opt/llvm-3.8.0/bin/clang++ -M --gcc-toolchain=/opt/gcc-5.2.0 -fsanitize=address
/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 添加到链接器标志中:
-fsanitize=address -lasan -shared -fuse-ld=gold-2.25 -o Class.so Class.o
-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?我还需要做什么才能让它发挥作用?
You main executable is probly not linked with -fsanitize=address
.您的主要可执行文件可能未与
-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.默认情况下,Clang 仅将 Asan 运行时库(它提供
__asan_memset
和其他 Asan 符号的定义)链接到可执行文件,而不是共享库,这会在您的情况下导致错误。
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)
.要解决此问题,您可以使用
-fsanitize=address
重新链接可执行文件,或者使用-fsanitize=address
-shared-libasan
重新链接经过消毒的 shlib,并使用LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)
。
For more details see AsanDSO wikipage .有关更多详细信息,请参阅AsanDSO 维基页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.