1 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
2 index c3e08f58c2ce..b5c5b9e3e74a 100644
3 --- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
4 +++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
6 #include "sanitizer_file.h"
7 # include "sanitizer_interface_internal.h"
10 +#include "sanitizer_posix.h"
13 namespace __sanitizer {
15 void CatastrophicErrorWrite(const char *buffer, uptr length) {
16 @@ -222,6 +226,34 @@ char *FindPathToBinary(const char *name) {
17 if (*end == '\0') break;
22 + // If we cannot find the requested binary in PATH, we should try to locate
23 + // it next to the binary, in case it is shipped with the build itself
24 + // (e.g. llvm-symbolizer shipped with sanitizer build to symbolize on client.
25 + if (internal_readlink("/proc/self/exe", buffer.data(), kMaxPathLength) < 0)
28 + uptr buf_len = internal_strlen(buffer.data());
30 + /* Avoid using dirname() here */
31 + while (buf_len > 0) {
32 + if (buffer[buf_len - 1] == '/')
40 + if (buf_len + name_len + 1 <= kMaxPathLength) {
41 + internal_memcpy(&buffer[buf_len], name, name_len);
42 + buffer[buf_len + name_len] = '\0';
43 + if (FileExists(buffer.data()))
44 + return internal_strdup(buffer.data());