Using the AddressSanitizer under Windows

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Using the AddressSanitizer under Windows

David Blaikie via cfe-dev

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

Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using the AddressSanitizer under Windows

David Blaikie via cfe-dev
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.

On Wed, Jan 23, 2019 at 11:13 PM Gaier, Bjoern via cfe-dev <[hidden email]> wrote:

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

Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using the AddressSanitizer under Windows

David Blaikie via cfe-dev
In reply to this post by David Blaikie via cfe-dev
On 24/01/2019 07:13, Gaier, Bjoern via cfe-dev wrote:
> Because I'm on a Windows7 x64 machine I then linked
> "clang_rt.asan-x86_64.lib" to my project.

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.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using the AddressSanitizer under Windows

David Blaikie via cfe-dev
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

-----Original Message-----
From: cfe-dev <[hidden email]> On Behalf Of Stephen Kelly via cfe-dev
Sent: Samstag, 26. Januar 2019 17:25
To: [hidden email]
Subject: Re: [cfe-dev] Using the AddressSanitizer under Windows

On 24/01/2019 07:13, Gaier, Bjoern via cfe-dev wrote:
> Because I'm on a Windows7 x64 machine I then linked
> "clang_rt.asan-x86_64.lib" to my project.

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.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev