[compiler-rt] r240960 - [libsanitizer] Replace ReadBinaryName() with ReadBinaryNameCached(),
Alexander Potapenko
glider at google.com
Mon Jun 29 08:58:17 PDT 2015
Author: glider
Date: Mon Jun 29 10:58:16 2015
New Revision: 240960
URL: http://llvm.org/viewvc/llvm-project?rev=240960&view=rev
Log:
[libsanitizer] Replace ReadBinaryName() with ReadBinaryNameCached(),
which caches the executable name upon the first invocation.
This is necessary because Google Chrome (and potentially other programs)
restrict the access to /proc/self/exe on linux.
This change should fix https://code.google.com/p/chromium/issues/detail?id=502974
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=240960&r1=240959&r2=240960&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Mon Jun 29 10:58:16 2015
@@ -353,11 +353,23 @@ const char *GetBinaryBasename() {
// Call once to make sure that binary_name_cache_str is initialized
void CacheBinaryName() {
- CHECK_EQ('\0', binary_name_cache_str[0]);
+ if (binary_name_cache_str[0] != '\0')
+ return;
ReadBinaryName(binary_name_cache_str, sizeof(binary_name_cache_str));
binary_basename_cache_str = StripModuleName(binary_name_cache_str);
}
+uptr ReadBinaryNameCached(/*out*/char *buf, uptr buf_len) {
+ CacheBinaryName();
+ uptr name_len = internal_strlen(binary_name_cache_str);
+ name_len = (name_len < buf_len - 1) ? name_len : buf_len - 1;
+ if (buf_len == 0)
+ return 0;
+ internal_memcpy(buf, binary_name_cache_str, name_len);
+ buf[name_len] = '\0';
+ return name_len;
+}
+
} // namespace __sanitizer
using namespace __sanitizer; // NOLINT
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=240960&r1=240959&r2=240960&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon Jun 29 10:58:16 2015
@@ -243,6 +243,7 @@ const char *StripModuleName(const char *
// OS
uptr ReadBinaryName(/*out*/char *buf, uptr buf_len);
+uptr ReadBinaryNameCached(/*out*/char *buf, uptr buf_len);
const char *GetBinaryBasename();
void CacheBinaryName();
void DisableCoreDumperIfNecessary();
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=240960&r1=240959&r2=240960&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Mon Jun 29 10:58:16 2015
@@ -425,7 +425,7 @@ static int dl_iterate_phdr_cb(dl_phdr_in
if (data->first) {
data->first = false;
// First module is the binary itself.
- ReadBinaryName(module_name.data(), module_name.size());
+ ReadBinaryNameCached(module_name.data(), module_name.size());
} else if (info->dlpi_name) {
module_name.append("%s", info->dlpi_name);
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc?rev=240960&r1=240959&r2=240960&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc Mon Jun 29 10:58:16 2015
@@ -34,7 +34,7 @@ static bool GetPathAssumingFileIsRelativ
/*out*/char *new_file_path,
uptr new_file_path_size) {
InternalScopedString exec(kMaxPathLength);
- if (ReadBinaryName(exec.data(), exec.size())) {
+ if (ReadBinaryNameCached(exec.data(), exec.size())) {
const char *file_name_pos = StripModuleName(exec.data());
uptr path_to_exec_len = file_name_pos - exec.data();
internal_strncat(new_file_path, exec.data(),
More information about the llvm-commits
mailing list