16

I'm compiling my program with clang++ -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -g -O0 and when I run it, the output is:

matiu@matiu-laptop:~/projects/json++11/build$ ./tests 
.......==10534== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7fe7602d4a51 (/home/matiu/projects/json++11/build/tests+0x106a51)
    #1 0x7fe7602dfca6 (/home/matiu/projects/json++11/build/tests+0x111ca6)
    ...
    #31 0x7fe75edbaec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
    #32 0x7fe7602808dc (/home/matiu/projects/json++11/build/tests+0xb28dc)

  Uninitialized value was created by a heap allocation
    #0 0x7fe76026e7b3 (/home/matiu/projects/json++11/build/tests+0xa07b3)
    #1 0x7fe7602ee7da (/home/matiu/projects/json++11/build/tests+0x1207da)
    ...
    #18 0x7fe7602c1c4c (/home/matiu/projects/json++11/build/tests+0xf3c4c)
    #19 0x7fe7602873fa (/home/matiu/projects/json++11/build/tests+0xb93fa)

SUMMARY: MemorySanitizer: use-of-uninitialized-value ??:0 ??
Exiting

How can I make it show line numbers like in the beautiful examples: http://clang.llvm.org/docs/MemorySanitizer.html

I'm suspecting it might not be possible, due to my pragram being one giant nested bunch of lambdas: https://github.com/matiu2/json--11/blob/master/tests.cpp

jww
  • 97,681
  • 90
  • 411
  • 885
matiu
  • 7,469
  • 4
  • 44
  • 48
  • 1
    So it does print line numbers in examples, but not in your code? `addr2line` could be helpful, but not truly what you've asked for. – keltar Jun 25 '14 at 04:01
  • 1
    Thanks @keltar that definitely helps: $ addr2line -e tests 0x15c59a /.../bandit/src/bandit/bandit/grammar.h:126 – matiu Jun 25 '14 at 08:39

1 Answers1

14

With the address sanitizer I noticed that I needed to have these environment variables defined:

  • ASAN_OPTIONS=symbolize=1 (only needed when compiled with GCC > 4.8) and
  • ASAN_SYMBOLIZER_PATH=$(which llvm-symbolizer) I think the symbolizer is what you're looking for. It transforms symbols to file names with line numbers and columns.

On the memory sanitizer project website it reads:

Symbolization

Set MSAN_SYMBOLIZER_PATH environment variable to the path to llvm-symbolizer binary (normally built with LLVM). MemorySanitizer will use it to symbolize reports on-the-fly.

So you need MSAN_SYMBOLIZER_PATH to be set analogous to ASAN_SYMBOLIZER_PATH.

Konrad Kleine
  • 4,275
  • 3
  • 27
  • 35
  • 4
    Thanks Konrad, that was exactly what I needed :) It turns out, on my Ubuntu installation the llvm-symbolizer was named llvm-symbolizer-3.5 .. adding a symlink to it at /usr/bin/llvm-symbolizer and just having it in the path did the trick. – matiu Jul 18 '14 at 13:47
  • 2
    On Ubuntu, creating the symbolic link is still needed for the line numbers to be printed. – ekse Jun 15 '16 at 04:00
  • 3
    on ubuntu, you need `apt install llvm` (at least as of 18.04) – gluk47 Oct 20 '18 at 08:34
  • @matiu, in Ubuntu 20.10 the location is the expected one: `/usr/bin/llvm-symbolizer`. – alfC Sep 13 '21 at 20:47