1 We currently need this patch because ASan only searches PATH to find the
2 llvm-symbolizer binary to symbolize ASan traces. On testing machines, this
3 can be installed in PATH easily. However, for e.g. the ASan Nightly Project,
4 where we ship an ASan build, including llvm-symbolizer, to the user, we
5 cannot expect llvm-symbolizer to be on PATH. Instead, we should try to look
6 it up next to the binary. This patch implements the functionality for Linux
7 only until there is similar functionality provided upstream.
9 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
10 index 79930d79425..cfb4f90c0d5 100644
11 --- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
12 +++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
14 #include "sanitizer_common.h"
15 #include "sanitizer_file.h"
18 +#include "sanitizer_posix.h"
21 namespace __sanitizer {
23 void CatastrophicErrorWrite(const char *buffer, uptr length) {
24 @@ -194,6 +198,34 @@ char *FindPathToBinary(const char *name) {
25 if (*end == '\0') break;
30 + // If we cannot find the requested binary in PATH, we should try to locate
31 + // it next to the binary, in case it is shipped with the build itself
32 + // (e.g. llvm-symbolizer shipped with sanitizer build to symbolize on client.
33 + if (internal_readlink("/proc/self/exe", buffer.data(), kMaxPathLength) < 0)
36 + uptr buf_len = internal_strlen(buffer.data());
38 + /* Avoid using dirname() here */
39 + while (buf_len > 0) {
40 + if (buffer[buf_len - 1] == '/')
48 + if (buf_len + name_len + 1 <= kMaxPathLength) {
49 + internal_memcpy(&buffer[buf_len], name, name_len);
50 + buffer[buf_len + name_len] = '\0';
51 + if (FileExists(buffer.data()))
52 + return internal_strdup(buffer.data());