[PATCH] Clear LD_PRELOAD when forking external symbolizer.

Sergey Matveev earthdok at google.com
Tue Apr 23 06:10:14 PDT 2013


    - reverted to a custom implementation of unsetenv
  Also, modified the implementation to allow multiple entries for the same
  variable.

Hi glider, kcc, samsonov,

http://llvm-reviews.chandlerc.com/D704

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D704?vs=1725&id=1728#toc

BRANCH
  ld_preload_in_symbolizer

ARCANIST PROJECT
  compiler-rt

Files:
  lib/sanitizer_common/sanitizer_common.h
  lib/sanitizer_common/sanitizer_linux.cc
  lib/sanitizer_common/sanitizer_symbolizer_linux.cc

Index: lib/sanitizer_common/sanitizer_common.h
===================================================================
--- lib/sanitizer_common/sanitizer_common.h
+++ lib/sanitizer_common/sanitizer_common.h
@@ -131,6 +131,7 @@
 bool FileExists(const char *filename);
 const char *GetEnv(const char *name);
 bool SetEnv(const char *name, const char *value);
+void UnsetEnv(const char *name);
 const char *GetPwd();
 u32 GetUid();
 void ReExec();
Index: lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -278,6 +278,20 @@
 }
 #endif
 
+void UnsetEnv(const char *name) {
+  uptr name_length = internal_strlen(name);
+  uptr last = 0;
+  while (environ[last]) last++;
+  for (uptr i = 0; environ[i]; i++)
+    if (internal_strlen(environ[i]) >= name_length + 1 &&
+        internal_strncmp(environ[i], name, name_length) == 0 &&
+        environ[i][name_length] == '=') {
+      last--;
+      environ[i] = environ[last];
+      environ[last] = 0;
+    }
+}
+
 #ifdef __GLIBC__
 
 extern "C" {
Index: lib/sanitizer_common/sanitizer_symbolizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_symbolizer_linux.cc
+++ lib/sanitizer_common/sanitizer_symbolizer_linux.cc
@@ -100,6 +100,11 @@
     internal_close(infd[1]);
     for (int fd = getdtablesize(); fd > 2; fd--)
       internal_close(fd);
+    // If the parent tool is used as a preloadable library, do not apply it to
+    // the symbolizer.
+    // FIXME: If LD_PRELOAD contains more than one object, we should keep those
+    // that have nothing to do with us.
+    UnsetEnv("LD_PRELOAD");
     execl(path_to_symbolizer, path_to_symbolizer, (char*)0);
     internal__exit(1);
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D704.3.patch
Type: text/x-patch
Size: 1845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130423/64a5c2fb/attachment.bin>


More information about the llvm-commits mailing list