ASAN_SYMBOLIZER_PATH improvements

When running code under sanitizers such as ASAN, you may wish to override the default symbolizer using:

ASAN_SYMBOLIZER_PATH=/path/to/llvm-symbolizer

(Although it’s currently not mentioned in the docs, there are equivalent LSAN_/MSAN_/UBSAN_ combinations should work with those respective sanitizers. Similarly you can even set ASAN_OPTIONS=external_symbolizer_path=/path/to/llvm-symbolizer. Regardless of variant, they all suffer from the same issue that I will describe below.)

Somewhat surprisingly, the implementation used to expect that the binary itself had to be named exactly llvm-symbolizer. Suppose you want to do the following because you built with clang-11, and the equivalent llvm-symbolizer binary name includes the version:

LLVM_SYMBOLIZER=/usr/bin/llvm-symbolizer-11.0.0

You would hit the following issue when starting a binary built with ASAN:

ERROR: External symbolizer path is set to '/usr/bin/llvm-symbolizer-11.0.0' which isn't a known symbolizer. Please set the path to the llvm-symbolizer binary or other known tool.

That’s a little irritating – and apparently I’m not the only one to think so [1][2]. (On some distros, the versioned path is just a symlink to a binary under /usr/lib/llvm-N/bin/llvm-symbolizer – hence you can just follow the link as a workaround – but on my distro llvm-symbolizer-N is the actual binary, and I’m hesitant to pollute my system with additional symlinks.)

I managed to hack together a fix, which has now landed in clang’s main branch – my understanding is that this will become part of clang 13:

https://github.com/llvm/llvm-project/commit/3d039f65015f0e7878b77c542a89493dcdd755d0

Posted in software