简体   繁体   English

尝试使用 Clang 地址清理器时获取未定义符号:__asan_memset

[英]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.

相关问题 使用地址清理程序时的g ++ 5和6的错误以及静态初始化顺序的附加asan标志 - errors with g++ 5 and 6 when using address sanitizer and additional asan flags for static initialization order 使用Clang的“未定义”消毒剂时未定义符号 - Undefined symbols when using Clang's “undefined” sanitizer 当 clang 编译为目标 wasm 时未定义的符号 - Undefined symbol when clang compiling to target wasm 如果只有主应用程序是用 clang 编译的,可以使用 clang Address Sanitizer 吗? - Can clang Address Sanitizer be used if only main application was compiled with clang? gcc - 如何使用地址清理器 - gcc - how to use address sanitizer 我怎么应该在铿锵声中使用消毒杀菌剂? - How I'm supposed to use the sanitizer in clang? 未定义的符号:memset,版本GLIBC_2.2.5 - undefined symbol: memset, version GLIBC_2.2.5 为什么ulimit -v不能在clang的地址清洁剂下工作? - why does ulimit -v not work under clang's address sanitizer? 指针数组中的转换和写入报告使用clang消毒器的地址未对齐 - Casting and writing in pointer array reports misaligned address with clang sanitizer 为什么 clang 消毒剂认为这个无符号数的左移是未定义的? - Why does the clang sanitizer think this left shift of an unsigned number is undefined?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM