Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I initialize LLVM's external symbolizer?

When compiling with -fsanitize=memory I get WARNING: Trying to symbolize code, but external symbolizer is not initialized! when running the program. How do I initialize the external symbolizer?

like image 747
Janus Troelsen Avatar asked Jun 10 '14 16:06

Janus Troelsen


3 Answers

I solved my own problem using MSAN_SYMBOLIZER_PATH=$(which llvm-symbolizer-3.4) ./a.out. The problem is that Ubuntu postfixes the version number but the binary doesn't know that. Of course you need to use MSAN instead of ASAN when using the memory sanitizer.

like image 77
Janus Troelsen Avatar answered Nov 10 '22 06:11

Janus Troelsen


On my Ubuntu system, the issue is that LLVM's tools are installed under /usr/bin with version suffixes (like llvm-symbolizer-4.0), and the sanitizer tools are looking for them without version suffixes.

LLVM also installs its binaries to, e.g., /usr/lib/llvm-4.0/bin; the tools under /usr/bin are actually just symlinks. So an easy solution is to add the appropriate /usr/lib/llvm-*/bin directory to your path when working with sanitizers.

like image 30
Josh Kelley Avatar answered Nov 10 '22 06:11

Josh Kelley


You are supposed to be able to set the ASAN_FILTER environment variable to point at a symbolizer, but I could not get it to work. However, you can redirect stderr into a symbolizer after the fact. You'll still get the warnings about the uninitialized symbolizer, but the filenames and line numbers will be correct.

You can use asan_symbolizer.py as the external symbolizer. After downloading it from that link (to /tmp, for example), invoke your program like so (in bash, for this example):

./myprogram 2>&1 | /tmp/asan_symbolize.py | c++filt 
like image 3
Steve Broberg Avatar answered Nov 10 '22 07:11

Steve Broberg