Using the AddressSanitizer under Windows

Hello everyone,

I heard a lot of good things about clangs “Sanitizer” so I wanted to test the “AddressSanitizer” with clang-cl. I complied LLVM7, Clang and Compiler-rt on my machine, wrote a simple test application and passed “-Xclang -fsanitize=address” to clang-cl. The linker then complained about undefined references. Because I’m on a Windows7 x64 machine I then linked “clang_rt.asan-x86_64.lib” to my project.

When I now execute my test application I get the messages:

==8160==AddressSanitizer CHECK failed: \compiler-rt-7.0.0.src\lib\sanitizer_common\ “((__interception::real_memcpy)) != (0)” (0x0, 0x0)

==8004==AddressSanitizer CHECK failed: \compiler-rt-7.0.0.src\lib\asan\ “((AddrIsInMem(addr))) != (0)” (0x0, 0x0)

What am I doing wrong?

Kind greetings


The first error message indicates that the ASan runtime failed to intercept memcpy. The code in question looks like this:

do {
} else {
ASSIGN_REAL(memcpy, memmove);
} while (false)

If you run with ASAN_OPTIONS=verbosity=3 you will get more information about interception failures. ASan on Windows uses various hotpatching techniques to intercept and override the default application memcpy, but they often fail on different versions of Windows DLLs with novel code patterns in the prologue. It is very fragile and I would love for it to be replaced with something more robust.

The follow-on CHECK failure is probably not important.

If you’re interested, I’d recommend putting together a bug report. It’s worth including the versions of Windows and the Visual C++ runtime that you are using. Either the or are reasonable places for it.

I recently started to try to use asan on Windows too.

You need to use different asan libraries depending on whether which windows runtime you use etc. You can see which ones clang uses under which flags if you run it with `-v`.

I pasted some cmake code to use asan here:



Hello Stephen,

Adding the libraries:

fixed my problem! Thank you! But now I have to use the "clang_rt.asan_dynamic-x86_64.dll" - is there a way to use static libraries rather than the DLL?

Kind greetings