尝试使用Clang地址清理器时,获取未定义的符号:__asan_memset [英] Getting undefined symbol: __asan_memset when trying to use Clang address sanitizer

查看:308
本文介绍了尝试使用Clang地址清理器时,获取未定义的符号:__asan_memset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有clang的地址清理器来编译C ++应用程序,但出现以下错误:

/Class.so:未定义符号:__asan_memset

我在编译器标志中添加了-fsanitize = address

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

,并且我在链接器标志中添加了-fsanitize = address和-lasan:

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

要使它正常工作,我还需要做什么?

解决方案

您的主要可执行文件可能未与-fsanitize=address链接.默认情况下,Clang仅将Asan运行时库(提供__asan_memset和其他Asan符号的定义)链接到可执行文件,而不是共享库,这会导致错误.

要解决此问题,您可以使用-fsanitize=address重新链接可执行文件,或者使用-shared-libasan重新链接经过清理的shlib,然后使用LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)运行.

有关更多详细信息,请参见 AsanDSO维基页面.. >

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?

解决方案

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.

这篇关于尝试使用Clang地址清理器时,获取未定义的符号:__asan_memset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆