[compiler-rt] r182851 - [nolibc] Unweak SymbolizerPrepareForSandboxing and move it to libc-independent part.

Peter Collingbourne peter at pcc.me.uk
Wed May 29 05:11:43 PDT 2013


Author: pcc
Date: Wed May 29 07:11:43 2013
New Revision: 182851

URL: http://llvm.org/viewvc/llvm-project?rev=182851&view=rev
Log:
[nolibc] Unweak SymbolizerPrepareForSandboxing and move it to libc-independent part.

Fixes the Go build.

Differential Revision: http://llvm-reviews.chandlerc.com/D877

Added:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux_libcdep.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=182851&r1=182850&r2=182851&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Wed May 29 07:11:43 2013
@@ -14,6 +14,7 @@ set(SANITIZER_SOURCES
   sanitizer_stackdepot.cc
   sanitizer_stacktrace.cc
   sanitizer_symbolizer_itanium.cc
+  sanitizer_symbolizer_linux.cc
   sanitizer_symbolizer_mac.cc
   sanitizer_symbolizer_win.cc
   sanitizer_thread_registry.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=182851&r1=182850&r2=182851&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Wed May 29 07:11:43 2013
@@ -307,8 +307,7 @@ void PrepareForSandboxing() {
   // cached mappings.
   MemoryMappingLayout::CacheMemoryMappings();
   // Same for /proc/self/exe in the symbolizer.
-  if (&SymbolizerPrepareForSandboxing)
-    SymbolizerPrepareForSandboxing();
+  SymbolizerPrepareForSandboxing();
 }
 
 // ----------------- sanitizer_procmaps.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h?rev=182851&r1=182850&r2=182851&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h Wed May 29 07:11:43 2013
@@ -60,6 +60,11 @@ uptr ThreadDescriptorSize();
 // information).
 bool LibraryNameIs(const char *full_name, const char *base_name);
 
+static const uptr kMaxPathLength = 512;
+
+// Read the name of the current binary from /proc/self/exe.
+uptr ReadBinaryName(/*out*/char *buf, uptr buf_len);
+
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_LINUX_H

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=182851&r1=182850&r2=182851&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h Wed May 29 07:11:43 2013
@@ -114,7 +114,7 @@ typedef bool (*string_predicate_t)(const
 uptr GetListOfModules(LoadedModule *modules, uptr max_modules,
                       string_predicate_t filter);
 
-void SymbolizerPrepareForSandboxing() SANITIZER_WEAK_ATTRIBUTE;
+void SymbolizerPrepareForSandboxing();
 
 }  // namespace __sanitizer
 

Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc?rev=182851&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc Wed May 29 07:11:43 2013
@@ -0,0 +1,63 @@
+//===-- sanitizer_symbolizer_linux.cc -------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is shared between AddressSanitizer and ThreadSanitizer
+// run-time libraries.
+// Linux-specific implementation of symbolizer parts.
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_platform.h"
+#if SANITIZER_LINUX
+#include "sanitizer_common.h"
+#include "sanitizer_linux.h"
+
+namespace __sanitizer {
+
+#if SANITIZER_ANDROID
+void SymbolizerPrepareForSandboxing() {
+  // Do nothing on Android.
+}
+#else
+static char proc_self_exe_cache_str[kMaxPathLength];
+static uptr proc_self_exe_cache_len = 0;
+
+uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
+  uptr module_name_len = internal_readlink(
+      "/proc/self/exe", buf, buf_len);
+  int readlink_error;
+  if (internal_iserror(buf_len, &readlink_error)) {
+    if (proc_self_exe_cache_len) {
+      // If available, use the cached module name.
+      CHECK_LE(proc_self_exe_cache_len, buf_len);
+      internal_strncpy(buf, proc_self_exe_cache_str, buf_len);
+      module_name_len = internal_strlen(proc_self_exe_cache_str);
+    } else {
+      // We can't read /proc/self/exe for some reason, assume the name of the
+      // binary is unknown.
+      Report("WARNING: readlink(\"/proc/self/exe\") failed with errno %d, "
+             "some stack frames may not be symbolized\n", readlink_error);
+      module_name_len = internal_snprintf(buf, buf_len, "/proc/self/exe");
+    }
+    CHECK_LT(module_name_len, buf_len);
+    buf[module_name_len] = '\0';
+  }
+  return module_name_len;
+}
+
+void SymbolizerPrepareForSandboxing() {
+  if (!proc_self_exe_cache_len) {
+    proc_self_exe_cache_len =
+        ReadBinaryName(proc_self_exe_cache_str, kMaxPathLength);
+  }
+}
+#endif  // SANITIZER_ANDROID
+
+}  // namespace __sanitizer
+
+#endif  // SANITIZER_LINUX

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux_libcdep.cc?rev=182851&r1=182850&r2=182851&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux_libcdep.cc Wed May 29 07:11:43 2013
@@ -17,6 +17,7 @@
 #include "sanitizer_common.h"
 #include "sanitizer_internal_defs.h"
 #include "sanitizer_libc.h"
+#include "sanitizer_linux.h"
 #include "sanitizer_placement_new.h"
 #include "sanitizer_symbolizer.h"
 
@@ -131,10 +132,6 @@ uptr GetListOfModules(LoadedModule *modu
                       string_predicate_t filter) {
   return 0;
 }
-
-void SymbolizerPrepareForSandboxing() {
-  // Do nothing on Android.
-}
 #else  // SANITIZER_ANDROID
 typedef ElfW(Phdr) Elf_Phdr;
 
@@ -146,34 +143,6 @@ struct DlIteratePhdrData {
   string_predicate_t filter;
 };
 
-static const uptr kMaxPathLength = 512;
-
-static char proc_self_exe_cache_str[kMaxPathLength];
-static uptr proc_self_exe_cache_len = 0;
-
-static uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
-  uptr module_name_len = internal_readlink(
-      "/proc/self/exe", buf, buf_len);
-  int readlink_error;
-  if (internal_iserror(buf_len, &readlink_error)) {
-    if (proc_self_exe_cache_len) {
-      // If available, use the cached module name.
-      CHECK_LE(proc_self_exe_cache_len, buf_len);
-      internal_strncpy(buf, proc_self_exe_cache_str, buf_len);
-      module_name_len = internal_strlen(proc_self_exe_cache_str);
-    } else {
-      // We can't read /proc/self/exe for some reason, assume the name of the
-      // binary is unknown.
-      Report("WARNING: readlink(\"/proc/self/exe\") failed with errno %d, "
-             "some stack frames may not be symbolized\n", readlink_error);
-      module_name_len = internal_snprintf(buf, buf_len, "/proc/self/exe");
-    }
-    CHECK_LT(module_name_len, buf_len);
-    buf[module_name_len] = '\0';
-  }
-  return module_name_len;
-}
-
 static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
   DlIteratePhdrData *data = (DlIteratePhdrData*)arg;
   if (data->current_n == data->max_n)
@@ -213,13 +182,6 @@ uptr GetListOfModules(LoadedModule *modu
   dl_iterate_phdr(dl_iterate_phdr_cb, &data);
   return data.current_n;
 }
-
-void SymbolizerPrepareForSandboxing() {
-  if (!proc_self_exe_cache_len) {
-    proc_self_exe_cache_len =
-        ReadBinaryName(proc_self_exe_cache_str, kMaxPathLength);
-  }
-}
 #endif  // SANITIZER_ANDROID
 
 }  // namespace __sanitizer





More information about the llvm-commits mailing list