Bug 1755076 - Adjust find_symbolizer_linux_clang patch to latest trunk. r=firefox-build-system-reviewers,mhentges

Differential Revision: https://phabricator.services.mozilla.com/D138592
This commit is contained in:
Mike Hommey 2022-02-12 05:52:14 +00:00
Родитель 476a867c3b
Коммит 00c007643b
2 изменённых файлов: 51 добавлений и 1 удалений

Просмотреть файл

@ -2,7 +2,7 @@
"patches": [
"static-llvm-symbolizer_clang_15.patch",
"compiler-rt-cross-compile.patch",
"find_symbolizer_linux_clang_10.patch",
"find_symbolizer_linux_clang_15.patch",
"android-mangling-error_clang_12.patch",
"unpoison-thread-stacks_clang_10.patch",
"downgrade-mangling-error_clang_12.patch",

Просмотреть файл

@ -0,0 +1,50 @@
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
index c3e08f58c2ce..b5c5b9e3e74a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
@@ -21,6 +21,10 @@
#include "sanitizer_file.h"
# include "sanitizer_interface_internal.h"
+#if SANITIZER_LINUX
+#include "sanitizer_posix.h"
+#endif
+
namespace __sanitizer {
void CatastrophicErrorWrite(const char *buffer, uptr length) {
@@ -222,6 +226,34 @@ char *FindPathToBinary(const char *name) {
if (*end == '\0') break;
beg = end + 1;
}
+
+#if SANITIZER_LINUX
+ // If we cannot find the requested binary in PATH, we should try to locate
+ // it next to the binary, in case it is shipped with the build itself
+ // (e.g. llvm-symbolizer shipped with sanitizer build to symbolize on client.
+ if (internal_readlink("/proc/self/exe", buffer.data(), kMaxPathLength) < 0)
+ return nullptr;
+
+ uptr buf_len = internal_strlen(buffer.data());
+
+ /* Avoid using dirname() here */
+ while (buf_len > 0) {
+ if (buffer[buf_len - 1] == '/')
+ break;
+ buf_len--;
+ }
+
+ if (!buf_len)
+ return nullptr;
+
+ if (buf_len + name_len + 1 <= kMaxPathLength) {
+ internal_memcpy(&buffer[buf_len], name, name_len);
+ buffer[buf_len + name_len] = '\0';
+ if (FileExists(buffer.data()))
+ return internal_strdup(buffer.data());
+ }
+#endif
+
return nullptr;
}