Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find -lubsan on using -fsanitize=undefined (mingw-w64)

I'm using mingw-w64 (gcc 7.3.0) and when I compile any C++ program using the following command:

g++ file.cpp -fsanitize=undefined

I get the following error:

...mingw32/bin/ld.exe: cannot find -lubsan

I'm able to successfully compile and run my programs if I remove the -fsanitize=undefined flag, though. After some research I found out that this means the library ubsan (Undefined Behavior Sanitizer) is missing, but I couldn't find anything about the library. How do I fix this?

like image 730
muzaffarahmed75 Avatar asked Jan 03 '19 17:01

muzaffarahmed75


People also ask

Why MinGW-w64 is not installing?

It is essential that the installation path does not contain any spaces. Therefore, you cannot install MinGW-w64 in Program Files. We recommend to create a folder mingw-w64 on your system drive (e.g., C:\mingw). Install a current version and specify win32 as thread when requested.

How do I find my MinGW path?

Right-click on Computer in the Start Menu and select Properties. Click on "Advanced System Settings", choose the Advanced tab, then click Environment Variables. Under System Variables, scroll down and select Path, then click Edit.


1 Answers

This is well known issue with mingw see for instance this msys github issue. No proper solution known but there are several WAs.

  1. Install WSL, ubuntu over WSL and you will have ubsan inside it
  2. Build GCC under Windows from source enabling sanitizers build. They are present in GCC sources they are just not here in mingw.
  3. Use -fsanitize=undefined -fsanitize-undefined-trap-on-error to just not use libubsan rich logging capabilities but get it trap on undefined instruction.

Hope one of this helps.

like image 79
Konstantin Vladimirov Avatar answered Sep 25 '22 09:09

Konstantin Vladimirov