Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang with -faddress-sanitizer on Windows

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?

like image 513
thegreendroid Avatar asked Aug 04 '12 06:08

thegreendroid


People also ask

Can I use Clang on Windows?

This wikiHow will teach you how to install Clang on Windows using Visual Studio 2019 version 16.1 Preview 2. When you install the preview of Visual Studio, you will also be able to install Clang.

Does Microsoft use Clang?

Development of Microsoft Game Development Kit (GDK) titles using Clang/LLVM is officially supported using Visual Studio 2019 or 2022 and the clang/LLVM for Windows toolset v11 or later. This toolset uses the Visual C/C++ Runtime (the Universal CRT library + the Microsoft STL).

Is Clang only on Mac?

Clang is released as part of regular LLVM releases. You can download the release versions from https://llvm.org/releases/. Clang is also provided in all major BSD or GNU/Linux distributions as part of their respective packaging systems. From Xcode 4.2, Clang is the default compiler for Mac OS X.


2 Answers

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

like image 179
thakis Avatar answered Oct 07 '22 17:10

thakis


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?

like image 32
obataku Avatar answered Oct 07 '22 17:10

obataku