[compiler-rt] r177857 - tsan: add SetEnv() function that can be used in frontends

Dmitry Vyukov dvyukov at google.com
Mon Mar 25 02:56:46 PDT 2013


Author: dvyukov
Date: Mon Mar 25 04:56:45 2013
New Revision: 177857

URL: http://llvm.org/viewvc/llvm-project?rev=177857&view=rev
Log:
tsan: add SetEnv() function that can be used in frontends


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc

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=177857&r1=177856&r2=177857&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon Mar 25 04:56:45 2013
@@ -127,6 +127,7 @@ void DisableCoreDumper();
 void DumpProcessMap();
 bool FileExists(const char *filename);
 const char *GetEnv(const char *name);
+bool SetEnv(const char *name, const char *value);
 const char *GetPwd();
 u32 GetUid();
 void ReExec();

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=177857&r1=177856&r2=177857&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Mon Mar 25 04:56:45 2013
@@ -264,6 +264,20 @@ const char *GetEnv(const char *name) {
   return 0;  // Not found.
 }
 
+// Does not compile for Go because dlsym() requires -ldl
+#ifndef SANITIZER_GO
+bool SetEnv(const char *name, const char *value) {
+  void *f = dlsym(RTLD_NEXT, "setenv");
+  if (f == 0)
+    return false;
+  typedef int(*setenv_ft)(const char *name, const char *value, int overwrite);
+  setenv_ft setenv_f;
+  CHECK_EQ(sizeof(setenv_f), sizeof(f));
+  internal_memcpy(&setenv_f, &f, sizeof(f));
+  return setenv_f(name, value, 1) == 0;
+}
+#endif
+
 #ifdef __GLIBC__
 
 extern "C" {





More information about the llvm-commits mailing list