[llvm-commits] [compiler-rt] r172719 - in /compiler-rt/trunk/lib: asan/asan_intercepted_functions.h asan/asan_interceptors.cc sanitizer_common/sanitizer_common_interceptors.h sanitizer_common/sanitizer_platform_interceptors.h tsan/lit_tests/thread_name.cc tsan/rtl/tsan_interceptors.cc tsan/rtl/tsan_stat.cc tsan/rtl/tsan_stat.h

David Blaikie dblaikie at gmail.com
Sat Jan 19 14:59:22 PST 2013


On Thu, Jan 17, 2013 at 5:38 AM, Kostya Serebryany <kcc at google.com> wrote:
> Author: kcc
> Date: Thu Jan 17 07:38:16 2013
> New Revision: 172719
>
> URL: http://llvm.org/viewvc/llvm-project?rev=172719&view=rev
> Log:
> [tsan] move prctl interceptor from asan to common_interceptors thus enabling it for tsan too
>
> Modified:
>     compiler-rt/trunk/lib/asan/asan_intercepted_functions.h
>     compiler-rt/trunk/lib/asan/asan_interceptors.cc
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.h
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
>     compiler-rt/trunk/lib/tsan/lit_tests/thread_name.cc
>     compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
>     compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
>     compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
>
> Modified: compiler-rt/trunk/lib/asan/asan_intercepted_functions.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_intercepted_functions.h?rev=172719&r1=172718&r2=172719&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_intercepted_functions.h (original)
> +++ compiler-rt/trunk/lib/asan/asan_intercepted_functions.h Thu Jan 17 07:38:16 2013
> @@ -42,10 +42,8 @@
>
>  #if defined(__linux__)
>  # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1
> -# define ASAN_INTERCEPT_PRCTL 1
>  #else
>  # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
> -# define ASAN_INTERCEPT_PRCTL 0
>  #endif
>
>  #if !defined(__APPLE__)
>
> 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=172719&r1=172718&r2=172719&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
> +++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Thu Jan 17 07:38:16 2013
> @@ -75,6 +75,12 @@
>    return internal_strnlen(s, maxlen);
>  }
>
> +static void SetThreadName(const char *name) {
> +  AsanThread *t = asanThreadRegistry().GetCurrent();
> +  if (t)
> +    t->summary()->set_name(name);
> +}
> +
>  }  // namespace __asan
>
>  // ---------------------- Wrappers ---------------- {{{1
> @@ -83,8 +89,9 @@
>  #define COMMON_INTERCEPTOR_WRITE_RANGE(ptr, size) ASAN_WRITE_RANGE(ptr, size)
>  #define COMMON_INTERCEPTOR_READ_RANGE(ptr, size) ASAN_READ_RANGE(ptr, size)
>  #define COMMON_INTERCEPTOR_ENTER(func, ...) ENSURE_ASAN_INITED()
> -#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd)
> -#define COMMON_INTERCEPTOR_FD_RELEASE(fd)
> +#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd) do { } while (false)
> +#define COMMON_INTERCEPTOR_FD_RELEASE(fd) do { } while (false)
> +#define COMMON_INTERCEPTOR_SET_THREAD_NAME(name) SetThreadName(name)
>  #include "sanitizer_common/sanitizer_common_interceptors.h"
>
>  static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
> @@ -166,25 +173,6 @@
>  }
>  #endif
>
> -#if ASAN_INTERCEPT_PRCTL
> -#define PR_SET_NAME 15
> -INTERCEPTOR(int, prctl, int option,
> -            unsigned long arg2, unsigned long arg3,  // NOLINT
> -            unsigned long arg4, unsigned long arg5) {  // NOLINT
> -  int res = REAL(prctl(option, arg2, arg3, arg4, arg5));
> -  if (option == PR_SET_NAME) {
> -    AsanThread *t = asanThreadRegistry().GetCurrent();
> -    if (t) {
> -      char buff[17];
> -      internal_strncpy(buff, (char*)arg2, 16);
> -      buff[16] = 0;
> -      t->summary()->set_name(buff);
> -    }
> -  }
> -  return res;
> -}
> -#endif
> -
>  #if ASAN_INTERCEPT___CXA_THROW
>  INTERCEPTOR(void, __cxa_throw, void *a, void *b, void *c) {
>    CHECK(REAL(__cxa_throw));
> @@ -731,9 +719,6 @@
>  #if ASAN_INTERCEPT_SIGLONGJMP
>    ASAN_INTERCEPT_FUNC(siglongjmp);
>  #endif
> -#if ASAN_INTERCEPT_PRCTL
> -  ASAN_INTERCEPT_FUNC(prctl);
> -#endif
>
>    // Intercept exception handling functions.
>  #if ASAN_INTERCEPT___CXA_THROW
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.h?rev=172719&r1=172718&r2=172719&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.h Thu Jan 17 07:38:16 2013
> @@ -17,6 +17,7 @@
>  //   COMMON_INTERCEPTOR_WRITE_RANGE
>  //   COMMON_INTERCEPTOR_FD_ACQUIRE
>  //   COMMON_INTERCEPTOR_FD_RELEASE
> +//   COMMON_INTERCEPTOR_SET_THREAD_NAME
>  //===----------------------------------------------------------------------===//
>  #ifndef SANITIZER_COMMON_INTERCEPTORS_H
>  #define SANITIZER_COMMON_INTERCEPTORS_H
> @@ -34,6 +35,9 @@
>      COMMON_INTERCEPTOR_FD_ACQUIRE(fd);
>    return res;
>  }
> +# define INIT_READ INTERCEPT_FUNCTION(read)
> +#else
> +# define INIT_READ
>  #endif
>
>  #if SANITIZER_INTERCEPT_PREAD
> @@ -46,6 +50,9 @@
>      COMMON_INTERCEPTOR_FD_ACQUIRE(fd);
>    return res;
>  }
> +# define INIT_PREAD INTERCEPT_FUNCTION(pread)
> +#else
> +# define INIT_PREAD
>  #endif
>
>  #if SANITIZER_INTERCEPT_PREAD64
> @@ -58,29 +65,35 @@
>      COMMON_INTERCEPTOR_FD_ACQUIRE(fd);
>    return res;
>  }
> -#endif
> -
> -#if SANITIZER_INTERCEPT_READ
> -# define INIT_READ INTERCEPT_FUNCTION(read)
> -#else
> -# define INIT_READ
> -#endif
> -
> -#if SANITIZER_INTERCEPT_PREAD
> -# define INIT_PREAD INTERCEPT_FUNCTION(pread)
> -#else
> -# define INIT_PREAD
> -#endif
> -
> -#if SANITIZER_INTERCEPT_PREAD64
>  # define INIT_PREAD64 INTERCEPT_FUNCTION(pread64)
>  #else
>  # define INIT_PREAD64
>  #endif
>
> +#if SANITIZER_INTERCEPT_PRCTL
> +INTERCEPTOR(int, prctl, int option,
> +            unsigned long arg2, unsigned long arg3,  // NOLINT
> +            unsigned long arg4, unsigned long arg5) {  // NOLINT
> +  COMMON_INTERCEPTOR_ENTER(prctl, option, arg2, arg3, arg4, arg5);
> +  static const int PR_SET_NAME = 15;
> +  int res = REAL(prctl(option, arg2, arg3, arg4, arg5));
> +  if (option == PR_SET_NAME) {
> +    char buff[16];
> +    internal_strncpy(buff, (char*)arg2, 15);
> +    buff[15] = 0;
> +    COMMON_INTERCEPTOR_SET_THREAD_NAME(buff);
> +  }
> +  return res;
> +}
> +# define INIT_PRCTL INTERCEPT_FUNCTION(prctl)
> +#else
> +# define INIT_PRCTL
> +#endif  // SANITIZER_INTERCEPT_PRCTL
> +
>  #define SANITIZER_COMMON_INTERCEPTORS_INIT \
>    INIT_READ;                               \
>    INIT_PREAD;                              \
>    INIT_PREAD64;                            \
> +  INIT_PRCTL;                              \
>
>  #endif  // SANITIZER_COMMON_INTERCEPTORS_H
>
> 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=172719&r1=172718&r2=172719&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Jan 17 07:38:16 2013
> @@ -24,7 +24,9 @@
>
>  #if defined(__linux__) && !defined(ANDROID)
>  # define SANITIZER_INTERCEPT_PREAD64 1
> +# define SANITIZER_INTERCEPT_PRCTL 1
>  #else
> +# define SANITIZER_INTERCEPT_PRCTL 0
>  # define SANITIZER_INTERCEPT_PREAD64 0
>  #endif
>
>
> Modified: compiler-rt/trunk/lib/tsan/lit_tests/thread_name.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_name.cc?rev=172719&r1=172718&r2=172719&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/lit_tests/thread_name.cc (original)
> +++ compiler-rt/trunk/lib/tsan/lit_tests/thread_name.cc Thu Jan 17 07:38:16 2013
> @@ -15,8 +15,7 @@
>  }
>
>  void *Thread2(void *x) {
> -  AnnotateThreadName(__FILE__, __LINE__, "Thread2");
> -  // TODO: pthread_setname_np(pthread_self(), "Thread2");
> +  pthread_setname_np(pthread_self(), "Thread2");

This is failing to compile on my system, possible because of an
outdated version of glibc, though I'm not sure:

/usr/local/google/home/blaikie/Development/llvm/src/projects/compiler-rt/lib/tsan/lit_tests/thread_name.cc:18:3:
error: use of undeclared identifier 'pthread_setname_np'; did you mean
'pthread_getattr_np'?
  pthread_setname_np(pthread_self(), "Thread2");
  ^~~~~~~~~~~~~~~~~~
  pthread_getattr_np
/usr/include/pthread.h:406:12: note: 'pthread_getattr_np' declared here
extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
           ^
/usr/local/google/home/blaikie/Development/llvm/src/projects/compiler-rt/lib/tsan/lit_tests/thread_name.cc:18:38:
error: cannot initialize a parameter of type 'pthread_attr_t *' with
an lvalue of type 'const char [8]'
  pthread_setname_np(pthread_self(), "Thread2");
                                     ^~~~~~~~~
/usr/include/pthread.h:406:64: note: passing argument to parameter '__attr' here
extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
                                                               ^
2 errors generated.


>    Global--;
>    return NULL;
>  }
>
> 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=172719&r1=172718&r2=172719&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Jan 17 07:38:16 2013
> @@ -1623,9 +1623,10 @@
>  #define COMMON_INTERCEPTOR_READ_RANGE(ptr, size)  \
>      MemoryAccessRange(thr, pc, (uptr)ptr, size, false)
>  #define COMMON_INTERCEPTOR_ENTER(func, ...) \
> - SCOPED_TSAN_INTERCEPTOR(func, __VA_ARGS__)
> +  SCOPED_TSAN_INTERCEPTOR(func, __VA_ARGS__)
>  #define COMMON_INTERCEPTOR_FD_ACQUIRE(fd) FdAcquire(thr, pc, fd)
>  #define COMMON_INTERCEPTOR_FD_RELEASE(fd) FdRelease(thr, pc, fd)
> +#define COMMON_INTERCEPTOR_SET_THREAD_NAME(name) ThreadSetName(thr, name)
>  #include "sanitizer_common/sanitizer_common_interceptors.h"
>
>  namespace __tsan {
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=172719&r1=172718&r2=172719&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Thu Jan 17 07:38:16 2013
> @@ -204,6 +204,7 @@
>    name[StatInt_pipe]                     = "  pipe                            ";
>    name[StatInt_pipe2]                    = "  pipe2                           ";
>    name[StatInt_read]                     = "  read                            ";
> +  name[StatInt_prctl]                    = "  prctl                           ";
>    name[StatInt_pread]                    = "  pread                           ";
>    name[StatInt_pread64]                  = "  pread64                         ";
>    name[StatInt_readv]                    = "  readv                           ";
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=172719&r1=172718&r2=172719&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Thu Jan 17 07:38:16 2013
> @@ -199,6 +199,7 @@
>    StatInt_pipe,
>    StatInt_pipe2,
>    StatInt_read,
> +  StatInt_prctl,
>    StatInt_pread,
>    StatInt_pread64,
>    StatInt_readv,
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list