Skip to content

Memory Sanitizer

Ashar edited this page Aug 25, 2020 · 1 revision

Memory Sanitizer helps in finding uninitialized use of variables, leaks and other memory-related behaviour that causes can cause UB.

Due to reasons mentioned below this work has been added to future work. It was originally intended to be completed with GSoC 2020 Phase II.

However, due to restricting nature of MEMSAN and limitations, it is only available with clang and is hard to set up correctly. See the discussion about it on this issue.

I have added the memory sanitizer but here is a problem.

Not uBLAS.tensor but Boost. Test framework has an issue of memory-sanitizer use of uninitialized value. I am not sure if it is really a true issue or false positive of MEMSAN. See this error report from Memory Sanitizer. However, I see many Stackoverflow questions that mention false positives for MEMSAN. Even its wiki says some things to do before using MEMSAN.

If you want MemorySanitizer to work properly and not produce any false positives, you must ensure that all the code in your program and in libraries it uses is instrumented (i.e. built with -fsanitize=memory). In particular, you would need to link against MSan-instrumented C++ standard library. We recommend using libc++ for that purpose. See https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo

I even tried using libc++ and linked a demo code to it with sanitizer enabled and got uninitialized use of memory error for std::cout<<"Hello world". See this:

image

The current CI is failing for Linux Clang due to the above sanitizer reported an error in Boost. Test