4

The following simple program

#include <malloc.h>
int main(int argc, char **argv)
{
    char* arr=malloc(10);
    arr[10]='\0';
    return 0;
}

builds fine with VC2019 16.8.2 in 32 bit dynamic linking

cl -Zi -fsanitize=address -MD clang_rt.asan_dynamic-i386.lib xx.c

and reports the memory error when running the program. However when using the 64bit variant I get a linking error

> 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

Looking in the clang_rt.asan_dynamic-x86_64.lib with dumpbin the missing symbol appears. Note that on both architectures static linking of the sample (without the _dynamic libs) works, but I need dynamic linking because of larger dependencies (Qt dlls). Anyone stumbled across that already ?

Regards, Leo

Leo
  • 925
  • 10
  • 24

1 Answers1

5

turned out I need another link library for 64 bit in addition 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

links the program correctly and brings up the sanitizer error after starting the program.

The page https://devblogs.microsoft.com/cppblog/asan-for-windows-x64-and-debug-build-support/ has a nice table which enumerates all the different build models and which asan libs are needed.

Leo
  • 925
  • 10
  • 24