Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use ubsan on gcc (windows 8.1)

In order to have a better protection against UB cases like:

#include <stdio.h>
int f(){
  int x;
  return x;
}
int main()
{
   f();
   while(1);
   return 0;
}

I've updated my GCC today so I could use ubsan. My current version is 5.3.0 according to gcc --version. I thought ubsan will be added by this update, but it seems that it was not because after compiling with C:\Users\my_name\Desktop>gcc -fsanitize=undefined a.c this is what I get:

c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot fin d -lubsan

Now, I've seen this post but the OS is Ubuntu 15.04 and I use Win 8.1 so that didn't help me. One of the comments here says:

You will need to install the libubsan package.

but I don't know if it was meant for windows/ubuntu, and even if it was for windows users, I don't understand how to do it.

edit: I tried also compiling gcc -fno-sanitize=all a.c (there are a lot of options in here) and this compiled with no warning, so I guess GCC recognizes the sanitizer somehow (because it compiled OK) but rejects my original compilation try for some reason

like image 513
CIsForCookies Avatar asked May 16 '17 08:05

CIsForCookies


1 Answers

For GCC on x86_64 sanitizer runtime libraries (including -lubsan) are only supported for Linux, OSX, FreeBSD and Solaris (see https://github.com/gcc-mirror/gcc/blob/master/libsanitizer/configure.tg for details). So unfortunately you can not yet use UBsan on Windows.

like image 196
yugr Avatar answered Nov 16 '22 12:11

yugr