find_symbolizer_linux_clang_15.patch (1809B)
1 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp 2 index 7ef499ce07b1..8fd682f943fe 100644 3 --- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp 4 +++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp 5 @@ -21,6 +21,10 @@ 6 #include "sanitizer_file.h" 7 # include "sanitizer_interface_internal.h" 8 9 +#if SANITIZER_LINUX 10 +#include "sanitizer_posix.h" 11 +#endif 12 + 13 namespace __sanitizer { 14 15 void CatastrophicErrorWrite(const char *buffer, uptr length) { 16 @@ -206,11 +210,35 @@ char *FindPathToBinary(const char *name) { 17 return internal_strdup(name); 18 } 19 20 + uptr name_len = internal_strlen(name); 21 + InternalMmapVector<char> buffer(kMaxPathLength); 22 + 23 +#if SANITIZER_LINUX 24 + // If we cannot find the requested binary in PATH, we should try to locate 25 + // it next to the binary, in case it is shipped with the build itself 26 + // (e.g. llvm-symbolizer shipped with sanitizer build to symbolize on client. 27 + if (internal_readlink("/proc/self/exe", buffer.data(), kMaxPathLength) >= 0) { 28 + uptr buf_len = internal_strlen(buffer.data()); 29 + 30 + /* Avoid using dirname() here */ 31 + while (buf_len > 0) { 32 + if (buffer[buf_len - 1] == '/') 33 + break; 34 + buf_len--; 35 + } 36 + 37 + if (buf_len && buf_len + name_len + 1 <= kMaxPathLength) { 38 + internal_memcpy(&buffer[buf_len], name, name_len); 39 + buffer[buf_len + name_len] = '\0'; 40 + if (FileExists(buffer.data())) 41 + return internal_strdup(buffer.data()); 42 + } 43 + } 44 +#endif 45 + 46 const char *path = GetEnv("PATH"); 47 if (!path) 48 return nullptr; 49 - uptr name_len = internal_strlen(name); 50 - InternalMmapVector<char> buffer(kMaxPathLength); 51 const char *beg = path; 52 while (true) { 53 const char *end = internal_strchrnul(beg, kPathSeparator);