[compiler-rt] r270076 - Revert "[sanitizer] Move *fstat to the common interceptors"

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Thu May 19 09:03:12 PDT 2016


Author: d0k
Date: Thu May 19 11:03:10 2016
New Revision: 270076

URL: http://llvm.org/viewvc/llvm-project?rev=270076&view=rev
Log:
Revert "[sanitizer] Move *fstat to the common interceptors"

This reverts commit r269981. Breaks msan tests on linux
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/24019/steps/test%20standalone%20compiler-rt/logs/stdio

Modified:
    compiler-rt/trunk/lib/asan/asan_interceptors.cc
    compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=270076&r1=270075&r2=270076&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Thu May 19 11:03:10 2016
@@ -168,9 +168,6 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free,
 #define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd) \
   do {                                         \
   } while (false)
-#define COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd) \
-  do {                                        \
-  } while (false)
 #define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd) \
   do {                                                      \
   } while (false)

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=270076&r1=270075&r2=270076&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu May 19 11:03:10 2016
@@ -684,6 +684,64 @@ INTERCEPTOR(int, putenv, char *string) {
   return res;
 }
 
+#if !SANITIZER_FREEBSD
+INTERCEPTOR(int, __fxstat, int magic, int fd, void *buf) {
+  ENSURE_MSAN_INITED();
+  int res = REAL(__fxstat)(magic, fd, buf);
+  if (!res)
+    __msan_unpoison(buf, __sanitizer::struct_stat_sz);
+  return res;
+}
+#define MSAN_MAYBE_INTERCEPT___FXSTAT INTERCEPT_FUNCTION(__fxstat)
+#else
+#define MSAN_MAYBE_INTERCEPT___FXSTAT
+#endif
+
+#if !SANITIZER_FREEBSD
+INTERCEPTOR(int, __fxstat64, int magic, int fd, void *buf) {
+  ENSURE_MSAN_INITED();
+  int res = REAL(__fxstat64)(magic, fd, buf);
+  if (!res)
+    __msan_unpoison(buf, __sanitizer::struct_stat64_sz);
+  return res;
+}
+#define MSAN_MAYBE_INTERCEPT___FXSTAT64 INTERCEPT_FUNCTION(__fxstat64)
+#else
+#define MSAN_MAYBE_INTERCEPT___FXSTAT64
+#endif
+
+#if SANITIZER_FREEBSD
+INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) {
+  ENSURE_MSAN_INITED();
+  int res = REAL(fstatat)(fd, pathname, buf, flags);
+  if (!res) __msan_unpoison(buf, __sanitizer::struct_stat_sz);
+  return res;
+}
+# define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(fstatat)
+#else
+INTERCEPTOR(int, __fxstatat, int magic, int fd, char *pathname, void *buf,
+            int flags) {
+  ENSURE_MSAN_INITED();
+  int res = REAL(__fxstatat)(magic, fd, pathname, buf, flags);
+  if (!res) __msan_unpoison(buf, __sanitizer::struct_stat_sz);
+  return res;
+}
+# define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(__fxstatat)
+#endif
+
+#if !SANITIZER_FREEBSD
+INTERCEPTOR(int, __fxstatat64, int magic, int fd, char *pathname, void *buf,
+            int flags) {
+  ENSURE_MSAN_INITED();
+  int res = REAL(__fxstatat64)(magic, fd, pathname, buf, flags);
+  if (!res) __msan_unpoison(buf, __sanitizer::struct_stat64_sz);
+  return res;
+}
+#define MSAN_MAYBE_INTERCEPT___FXSTATAT64 INTERCEPT_FUNCTION(__fxstatat64)
+#else
+#define MSAN_MAYBE_INTERCEPT___FXSTATAT64
+#endif
+
 INTERCEPTOR(int, pipe, int pipefd[2]) {
   if (msan_init_is_running)
     return REAL(pipe)(pipefd);
@@ -1245,9 +1303,6 @@ int OnExit() {
 #define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd) \
   do {                                         \
   } while (false)
-#define COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd) \
-  do {                                        \
-  } while (false)
 #define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd) \
   do {                                                      \
   } while (false)
@@ -1494,6 +1549,10 @@ void InitializeInterceptors() {
   INTERCEPT_FUNCTION(putenv);
   INTERCEPT_FUNCTION(gettimeofday);
   INTERCEPT_FUNCTION(fcvt);
+  MSAN_MAYBE_INTERCEPT___FXSTAT;
+  MSAN_INTERCEPT_FSTATAT;
+  MSAN_MAYBE_INTERCEPT___FXSTAT64;
+  MSAN_MAYBE_INTERCEPT___FXSTATAT64;
   INTERCEPT_FUNCTION(pipe);
   INTERCEPT_FUNCTION(pipe2);
   INTERCEPT_FUNCTION(socketpair);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=270076&r1=270075&r2=270076&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu May 19 11:03:10 2016
@@ -5609,106 +5609,7 @@ INTERCEPTOR(int, __lxstat64, int version
 #define INIT___LXSTAT64
 #endif
 
-#if SANITIZER_INTERCEPT_FSTAT
-INTERCEPTOR(int, fstat, int fd, void *buf) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, fstat, fd, buf);
-  if (common_flags()->intercept_stat && fd > 0)
-    COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
-  int res = REAL(fstat)(fd, buf);
-  if (!res)
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat_sz);
-  return res;
-}
-#define INIT_FSTAT COMMON_INTERCEPT_FUNCTION(fstat)
-#else
-#define INIT_FSTAT
-#endif
-
-#if SANITIZER_INTERCEPT___FXSTAT
-INTERCEPTOR(int, __fxstat, int version, int fd, void *buf) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, __fxstat, version, fd, buf);
-  if (common_flags()->intercept_stat && fd > 0)
-    COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
-  int res = REAL(__fxstat)(version, fd, buf);
-  if (!res)
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat_sz);
-  return res;
-}
-#define INIT___FXSTAT COMMON_INTERCEPT_FUNCTION(__fxstat)
-#else
-#define INIT___FXSTAT
-#endif
-
-#if SANITIZER_INTERCEPT___FXSTAT64
-INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, __fxstat64, version, fd, buf);
-  if (common_flags()->intercept_stat && fd > 0)
-    COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
-  int res = REAL(__fxstat64)(version, fd, buf);
-  if (!res)
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat64_sz);
-  return res;
-}
-#define INIT___FXSTAT64 COMMON_INTERCEPT_FUNCTION(__fxstat64)
-#else
-#define INIT___FXSTAT64
-#endif
-
-#if SANITIZER_INTERCEPT_FSTATAT
-INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, fstatat, fd, pathname, buf, flags);
-  if (common_flags()->intercept_stat)
-    COMMON_INTERCEPTOR_READ_STRING(ctx, pathname, 0);
-  int res = REAL(fstatat)(fd, pathname, buf, flags);
-  if (!res)
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat_sz);
-  return res;
-}
-#define INIT_FSTATAT COMMON_INTERCEPT_FUNCTION(fstatat);
-#else
-#define INIT_FSTATAT
-#endif
-
-#if SANITIZER_INTERCEPT___FXSTATAT
-INTERCEPTOR(int, __fxstatat, int version, int fd, char *pathname, void *buf,
-            int flags) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, __fxstatat, version, fd, pathname, buf, flags);
-  if (common_flags()->intercept_stat)
-    COMMON_INTERCEPTOR_READ_STRING(ctx, pathname, 0);
-  int res = REAL(__fxstatat)(fd, version, pathname, buf, flags);
-  if (!res) {
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat_sz);
-  }
-  return res;
-}
-#define INIT___FXSTATAT COMMON_INTERCEPT_FUNCTION(__fxstatat);
-#else
-#define INIT___FXSTATAT
-#endif
-
-#if SANITIZER_INTERCEPT___FXSTATAT64
-INTERCEPTOR(int, __fxstatat64, int version, int fd, char *pathname, void *buf,
-            int flags) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, __fxstatat64, version, fd, pathname, buf,
-                           flags);
-  if (common_flags()->intercept_stat)
-    COMMON_INTERCEPTOR_READ_STRING(ctx, pathname, 0);
-  int res = REAL(__fxstatat64)(fd, version, pathname, buf, flags);
-  if (!res) {
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat64_sz);
-  }
-  return res;
-}
-#define INIT___FXSTATAT64 COMMON_INTERCEPT_FUNCTION(__fxstatat64);
-#else
-#define INIT___FXSTATAT64
-#endif
+// FIXME: add other *stat interceptor
 
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
@@ -5900,10 +5801,5 @@ static void InitializeCommonInterceptors
   INIT___XSTAT64;
   INIT___LXSTAT;
   INIT___LXSTAT64;
-  INIT_FSTAT;
-  INIT___FXSTAT;
-  INIT___FXSTAT64;
-  INIT_FSTATAT;
-  INIT___FXSTATAT;
-  INIT___FXSTATAT64;
+  // FIXME: add other *stat interceptors.
 }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=270076&r1=270075&r2=270076&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu May 19 11:03:10 2016
@@ -306,10 +306,4 @@
 #define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
 #define SANITIZER_INTERCEPT___LXSTAT64 SI_LINUX_NOT_ANDROID
-#define SANITIZER_INTERCEPT_FSTAT SANITIZER_INTERCEPT_STAT
-#define SANITIZER_INTERCEPT___FXSTAT SANITIZER_INTERCEPT___XSTAT
-#define SANITIZER_INTERCEPT___FXSTAT64 SI_LINUX_NOT_ANDROID
-#define SANITIZER_INTERCEPT_FSTATAT SI_FREEBSD
-#define SANITIZER_INTERCEPT___FXSTATAT SANITIZER_INTERCEPT___XSTAT
-#define SANITIZER_INTERCEPT___FXSTATAT64 SI_LINUX_NOT_ANDROID
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=270076&r1=270075&r2=270076&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu May 19 11:03:10 2016
@@ -1358,6 +1358,56 @@ TSAN_INTERCEPTOR(int, pthread_once, void
   return 0;
 }
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+TSAN_INTERCEPTOR(int, __fxstat, int version, int fd, void *buf) {
+  SCOPED_TSAN_INTERCEPTOR(__fxstat, version, fd, buf);
+  if (fd > 0)
+    FdAccess(thr, pc, fd);
+  return REAL(__fxstat)(version, fd, buf);
+}
+#define TSAN_MAYBE_INTERCEPT___FXSTAT TSAN_INTERCEPT(__fxstat)
+#else
+#define TSAN_MAYBE_INTERCEPT___FXSTAT
+#endif
+
+TSAN_INTERCEPTOR(int, fstat, int fd, void *buf) {
+#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_ANDROID
+  SCOPED_TSAN_INTERCEPTOR(fstat, fd, buf);
+  if (fd > 0)
+    FdAccess(thr, pc, fd);
+  return REAL(fstat)(fd, buf);
+#else
+  SCOPED_TSAN_INTERCEPTOR(__fxstat, 0, fd, buf);
+  if (fd > 0)
+    FdAccess(thr, pc, fd);
+  return REAL(__fxstat)(0, fd, buf);
+#endif
+}
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+TSAN_INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) {
+  SCOPED_TSAN_INTERCEPTOR(__fxstat64, version, fd, buf);
+  if (fd > 0)
+    FdAccess(thr, pc, fd);
+  return REAL(__fxstat64)(version, fd, buf);
+}
+#define TSAN_MAYBE_INTERCEPT___FXSTAT64 TSAN_INTERCEPT(__fxstat64)
+#else
+#define TSAN_MAYBE_INTERCEPT___FXSTAT64
+#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+TSAN_INTERCEPTOR(int, fstat64, int fd, void *buf) {
+  SCOPED_TSAN_INTERCEPTOR(__fxstat64, 0, fd, buf);
+  if (fd > 0)
+    FdAccess(thr, pc, fd);
+  return REAL(__fxstat64)(0, fd, buf);
+}
+#define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64)
+#else
+#define TSAN_MAYBE_INTERCEPT_FSTAT64
+#endif
+
 TSAN_INTERCEPTOR(int, open, const char *name, int flags, int mode) {
   SCOPED_TSAN_INTERCEPTOR(open, name, flags, mode);
   READ_STRING(thr, pc, name, 0);
@@ -2486,6 +2536,10 @@ void InitializeInterceptors() {
 
   TSAN_INTERCEPT(pthread_once);
 
+  TSAN_INTERCEPT(fstat);
+  TSAN_MAYBE_INTERCEPT___FXSTAT;
+  TSAN_MAYBE_INTERCEPT_FSTAT64;
+  TSAN_MAYBE_INTERCEPT___FXSTAT64;
   TSAN_INTERCEPT(open);
   TSAN_MAYBE_INTERCEPT_OPEN64;
   TSAN_INTERCEPT(creat);




More information about the llvm-commits mailing list