15

My intent is to use Clang as a replacement for Valgrind on Windows to find buffer overflows, dynamic memory misuse etc. in C/C++ programs that I've written. I have successfully built Clang following the instructions provided here.

I attempted to compile a simple C program with the -faddress-sanitizer option (as specified here) and the following the error is thrown -

gcc.exe: error: unrecognized command line option '-faddress-sanitizer'
Using built-in specs.
COLLECT_GCC=C:/MinGW/bin/gcc.exe
Target: mingw32
Configured with: ../gcc-4.7.0/configure --enable-languages=c,c++,ada,fortran,objc,obj-      c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1-with-cxx --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.7.0 (GCC)
clang: error: assembler (via gcc) command failed with exit code 1 (use -v to see invocation)

Why is clang (as I understand it) invoking GCC? Of course GCC does not support the -faddress-sanitizer option.

I am really excited at the possibility of using this as I've been trying to find a good (free) substitute for Valgrind for a while. Can someone please help?

Community
  • 1
  • 1
thegreendroid
  • 3,239
  • 6
  • 31
  • 40

2 Answers2

9

AddressSanitizer works much better on Windows these days (but it's still a bit of a work-in-progress). There's some documentation at https://github.com/google/sanitizers/wiki/AddressSanitizerWindowsPort

milianw
  • 5,164
  • 2
  • 37
  • 41
thakis
  • 5,405
  • 1
  • 33
  • 33
  • 1
    I've fixed the link now to point to https://github.com/google/sanitizers/wiki/AddressSanitizerWindowsPort – milianw Nov 14 '16 at 16:37
8

Googling brought me to this page.

To quote,

AddressSanitizer is supported on

  • Linux x86_64 (tested on Ubuntu 10.04).
  • MacOS 10.6 and 10.7 (i386/x86_64).

Support for Linux i386/ARM is in progress (it may work, but is not guaranteed too).


On the topic of replacement, have you looked at Dr. Memory?

Community
  • 1
  • 1
obataku
  • 29,212
  • 3
  • 44
  • 57
  • Thanks but it appears that Address Sanitizer should work on Windows according to [this](http://code.google.com/p/address-sanitizer/wiki/WindowsPort). I did give Dr. Memory a try recently, it didn't catch buffer overflows but it did catch uninitialized reads in memory. The single most important feature I'm after is detection of buffer overflow. – thegreendroid Aug 04 '12 at 06:47
  • Did you follow those instructions fully? – obataku Aug 04 '12 at 06:49
  • I attempted to but stopped short because the instructions use MSVC to compile address sanitizer. I am using MinGW32. – thegreendroid Aug 04 '12 at 06:59
  • I will accept your answer until I can get it working myself. Thanks. – thegreendroid Aug 04 '12 at 11:11
  • 1
    No problem, I wish you luck. [Here](http://msdn.microsoft.com/en-us/library/9s7c9wdw.aspx) is a list of flags for `cl` so you can perhaps port whatever needs to be made to use MinGW. – obataku Aug 04 '12 at 16:45
  • That's exactly what I was looking at but I ran into a header file problem (intrin.h) that's only available on MSVC. It might require more hacking that I thought to get it compile using MinGW. But definitely worth the trouble if I can get it working. – thegreendroid Aug 05 '12 at 08:19
  • 1
    There appears to be a GCC-compatible port [here](http://www.koders.com/cpp/fidAD4BE239980B0FA1EC05A674929EFE86553B016E.aspx). – obataku Aug 05 '12 at 17:51
  • Gee, thanks! That's really helpful, I'll let you know how I get on. – thegreendroid Aug 05 '12 at 21:39
  • No problem; I'm only hoping I can provide as much help as possible. – obataku Aug 05 '12 at 21:40
  • 1
    Dr. Memory page says that it can't handle 64-bit applications, unfortunately. – Serge Rogatch Sep 28 '15 at 08:02