2

my test code is the following:

#include <string>
#include <iostream>


int main()
{
  std::string mylongstring("This is a test string");
  std::cout << mylongstring << std::endl;
}

and I compile with the latest clang, using a GCC 7.2 toolchain.
clang++ -fsanitize=memory msan.cp

This is essentially a reproducer for a problem that I see trying to integrate the memory sanitizer in a big software stack running on a centos 7 server.

And this little example code produces the following error:

Uninitialized bytes in __interceptor_fwrite at offset 0 inside [0x702000000000, 21)
==34234==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f2acebbd9f3 in std::basic_streambuf<char, std::char_traits<char> >::sputn(char const*, long) /build/*----*/build-gcc710/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:451
    #1 0x7f2acebbd9f3 in void std::__ostream_write<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) /build/*----*/build-gcc710/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:50
    #2 0x7f2acebbd9f3 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) /build/*----*/build-gcc710/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:101
    #3 0x4ab06d in main (/home/*----*/intelhackathon/a.out+0x4ab06d)
    #4 0x7f2acdbcdc04 in __libc_start_main (/lib64/libc.so.6+0x21c04)
    #5 0x41b323 in _start (/home/*----*/intelhackathon/a.out+0x41b323)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /build/*----*/build-gcc710/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:451 in std::basic_streambuf<char, std::char_traits<char> >::sputn(char const*, long)
Exiting

However, this only happens on the centos server, when trying this on my local arch linux system I don't see any errors and it works as expected.

Server details:
glibc : 2.17-196.el7
uname -a:
Linux servername 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

I'm mostly out of ideas so would be happy for any help or even suggestions of what I could try.

Thanks! :)

hassec
  • 686
  • 4
  • 18
  • Feel free to submit a bug report. However, I would suggest you to play with preprocessed files on your server and your local system first, in order to understand where is the problem: in memory sanitizer or in libstdc++. – Nikolai Nov 24 '17 at 22:37
  • Thanks for the tip, I hadn't actually tried that. Will report back once I have results. – hassec Nov 25 '17 at 13:31
  • @Nikolai I've played a bit with the preprocessed files and if I preprocess on my machine, copy to the server, and then run I still get the error. Files preprocessed on the server and run on my machine run fine. I guess this means it's not a problem with the libstdc++. – hassec Nov 25 '17 at 17:31
  • 3
    I can't remember which, but at least one of address or memory sanitizer need a a standard library that is compiled with support for the sanitizer. – MikeMB Nov 26 '17 at 22:27
  • 1
    @MikeMB is right, it is [MemorySanitizer](https://clang.llvm.org/docs/MemorySanitizer.html#handling-external-code) Could it be that the standard library on the server is not compiled with memory sanitizer support? – PaulR Nov 27 '17 at 16:29
  • Hi guys, thanks that was indeed the problem and I am now able to compile the simple test case. Does anyone know of an up to date way how to compile libstdc++ with MemorySanitizer? (currently only managed libc++) – hassec Nov 28 '17 at 09:48
  • oh and @MikeMB if you make an answer out of your comment I'll accept it ;) – hassec Nov 28 '17 at 10:36

0 Answers0