Leo*_*Leo 4 c qt visual-studio address-sanitizer cl
下面的简单程序
#include <malloc.h>
int main(int argc, char **argv)
{
    char* arr=malloc(10);
    arr[10]='\0';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
在 32 位动态链接中与 VC2019 16.8.2 构建良好
cl -Zi -fsanitize=address -MD clang_rt.asan_dynamic-i386.lib xx.c
并在运行程序时报告内存错误。但是,当使用 64 位变体时,我收到链接错误
> cl -Zi -fsanitize=address -MD clang_rt.asan_dynamic-x86_64.lib xx.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29336 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.
xx.c
Microsoft (R) Incremental Linker Version 14.28.29336.0
Copyright (C) Microsoft Corporation.  All rights reserved.
/out:xx.exe
/debug
clang_rt.asan_dynamic-x86_64.lib
xx.obj
xx.obj : error LNK2019: unresolved external symbol __asan_shadow_memory_dynamic_address referenced in function main
xx.exe : fatal error LNK1120: 1 unresolved externals
Run Code Online (Sandbox Code Playgroud)
查看时clang_rt.asan_dynamic-x86_64.lib会dumpbin出现缺少的符号。请注意,在两种体系结构上,示例的静态链接(没有 _dynamic 库)都有效,但由于依赖项较大(Qt dll),我需要动态链接。有人已经偶然发现了吗?
问候,利奥
原来我还需要另一个64 位链接库clang_rt.asan_dynamic_runtime_thunk-x86_64.lib
cl -MD -fsanitize=address clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib xx.c
正确链接程序并在启动程序后出现消毒剂错误。
页面https://devblogs.microsoft.com/cppblog/asan-for-windows-x64-and-debug-build-support/有一个很好的表格,其中枚举了所有不同的构建模型以及需要哪些 asan 库。