尝试使用Clang地址清理器时,获取未定义的符号:__asan_memset [英] Getting undefined symbol: __asan_memset when trying to use Clang address sanitizer
问题描述
我正在尝试使用带有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屋!