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\sanitizer_common_interceptors.inc:7265 “((__interception::real_memcpy)) != (0)” (0x0, 0x0)

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

What am I doing wrong?

Kind greetings

Björn

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

#define INIT_MEMCPY
do {
if (PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE) {
COMMON_INTERCEPT_FUNCTION(memcpy);
} else {
ASSIGN_REAL(memcpy, memmove);
}
CHECK(REAL(memcpy));
} 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 https://bugs.llvm.org or https://github.com/google/sanitizers/ 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:

https://bugs.llvm.org/show_bug.cgi?id=40320

Thanks,

Stephen.

Hello Stephen,

Adding the libraries:
clang_rt.asan_dynamic-x86_64.lib
clang_rt.asan_dynamic_runtime_thunk-x86_64.lib

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
Björn