[compiler-rt] r211166 - [sanitizer] Intercept pthread_*attr_get*.

Arnold Schwaighofer aschwaighofer at apple.com
Wed Jun 18 12:06:33 PDT 2014


A public buildbot that exhibits this is here:

http://lab.llvm.org:8013/builders/clang-x86_64-darwin11-nobootstrap-RAincremental/builds/1024/steps/make/logs/stdio


> On Jun 18, 2014, at 10:41 AM, Arnold Schwaighofer <aschwaighofer at apple.com> wrote:
> 
> Hi Evgeniy,
> 
> this appears to have broken mac os x builds of compiler-rt:
> 
> CHECK_TYPE_SIZE(clockid_t);
>                 ^~~~~~~~~
>                 clock_t
> ../projects/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h:1263:55: note: expanded from macro 'CHECK_TYPE_SIZE'
>   COMPILER_CHECK(sizeof(__sanitizer_##TYPE) == sizeof(TYPE))
>                                                       ^
> ../projects/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:264:51: note: expanded from macro 'COMPILER_CHECK'
> #define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
>                                                   ^
> ../projects/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:270:65: note: expanded from macro 'IMPL_COMPILER_ASSERT'
>     typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
>                                                                 ^
> /usr/include/sys/_types/_clock_t.h:30:33: note: 'clock_t' declared here
> typedef __darwin_clock_t        clock_t;
>                                 ^
> ../projects/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:1061:1: error: 'assertion_failed__1061' declared as an array with a negative size
> CHECK_TYPE_SIZE(clockid_t);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~
> ../projects/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h:1263:3: note: expanded from macro 'CHECK_TYPE_SIZE'
>   COMPILER_CHECK(sizeof(__sanitizer_##TYPE) == sizeof(TYPE))
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../projects/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:264:30: note: expanded from macro 'COMPILER_CHECK'
> #define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
>                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../projects/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:270:57: note: expanded from macro 'IMPL_COMPILER_ASSERT'
>     typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
> 
> 
> 
>> On Jun 18, 2014, at 7:16 AM, Evgeniy Stepanov <eugeni.stepanov at gmail.com> wrote:
>> 
>> Author: eugenis
>> Date: Wed Jun 18 09:16:41 2014
>> New Revision: 211166
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=211166&view=rev
>> Log:
>> [sanitizer] Intercept pthread_*attr_get*.
>> 
>> Added:
>>    compiler-rt/trunk/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc   (with props)
>> Modified:
>>    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
>>    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
>>    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
>>    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
>>    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
>> 
>> 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=211166&r1=211165&r2=211166&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Jun 18 09:16:41 2014
>> @@ -3294,19 +3294,26 @@ INTERCEPTOR(int, random_r, void *buf, u3
>> // FIXME: under ASan the REAL() call below may write to freed memory and corrupt
>> // its metadata. See
>> // https://code.google.com/p/address-sanitizer/issues/detail?id=321.
>> -#if SANITIZER_INTERCEPT_PTHREAD_ATTR_GET || \
>> -    SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSSCHED
>> -#define INTERCEPTOR_PTHREAD_ATTR_GET(what, sz)                      \
>> -  INTERCEPTOR(int, pthread_attr_get##what, void *attr, void *r) {   \
>> -    void *ctx;                                                      \
>> -    COMMON_INTERCEPTOR_ENTER(ctx, pthread_attr_get##what, attr, r); \
>> -    int res = REAL(pthread_attr_get##what)(attr, r);                \
>> -    if (!res && r) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, r, sz);      \
>> -    return res;                                                     \
>> +#if SANITIZER_INTERCEPT_PTHREAD_ATTR_GET ||              \
>> +    SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSSCHED || \
>> +    SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GET ||         \
>> +    SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GET ||        \
>> +    SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GET ||          \
>> +    SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GET
>> +#define INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(fn, sz)            \
>> +  INTERCEPTOR(int, fn, void *attr, void *r) {                  \
>> +    void *ctx;                                                 \
>> +    COMMON_INTERCEPTOR_ENTER(ctx, fn, attr, r);                \
>> +    int res = REAL(fn)(attr, r);                               \
>> +    if (!res && r) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, r, sz); \
>> +    return res;                                                \
>>   }
>> #endif
>> 
>> +
>> #if SANITIZER_INTERCEPT_PTHREAD_ATTR_GET
>> +#define INTERCEPTOR_PTHREAD_ATTR_GET(what, sz) \
>> +  INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_attr_get##what, sz)
>> INTERCEPTOR_PTHREAD_ATTR_GET(detachstate, sizeof(int))
>> INTERCEPTOR_PTHREAD_ATTR_GET(guardsize, sizeof(SIZE_T))
>> INTERCEPTOR_PTHREAD_ATTR_GET(schedparam, struct_sched_param_sz)
>> @@ -3380,6 +3387,60 @@ INTERCEPTOR(int, pthread_attr_getaffinit
>> #define INIT_PTHREAD_ATTR_GETAFFINITY_NP
>> #endif
>> 
>> +#if SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GET
>> +#define INTERCEPTOR_PTHREAD_MUTEXATTR_GET(what, sz) \
>> +  INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_mutexattr_get##what, sz)
>> +INTERCEPTOR_PTHREAD_MUTEXATTR_GET(pshared, sizeof(int))
>> +INTERCEPTOR_PTHREAD_MUTEXATTR_GET(type, sizeof(int))
>> +INTERCEPTOR_PTHREAD_MUTEXATTR_GET(protocol, sizeof(int))
>> +INTERCEPTOR_PTHREAD_MUTEXATTR_GET(prioceiling, sizeof(int))
>> +INTERCEPTOR_PTHREAD_MUTEXATTR_GET(robust, sizeof(int))
>> +INTERCEPTOR_PTHREAD_MUTEXATTR_GET(robust_np, sizeof(int))
>> +#define INIT_PTHREAD_MUTEXATTR_GET                             \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getpshared);     \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_gettype);        \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getprotocol);    \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getprioceiling); \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getrobust);      \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_mutexattr_getrobust_np);
>> +#else
>> +#define INIT_PTHREAD_MUTEXATTR_GET
>> +#endif
>> +
>> +#if SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GET
>> +#define INTERCEPTOR_PTHREAD_RWLOCKATTR_GET(what, sz) \
>> +  INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_rwlockattr_get##what, sz)
>> +INTERCEPTOR_PTHREAD_RWLOCKATTR_GET(pshared, sizeof(int))
>> +INTERCEPTOR_PTHREAD_RWLOCKATTR_GET(kind_np, sizeof(int))
>> +#define INIT_PTHREAD_RWLOCKATTR_GET                         \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_rwlockattr_getpshared); \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_rwlockattr_getkind_np);
>> +#else
>> +#define INIT_PTHREAD_RWLOCKATTR_GET
>> +#endif
>> +
>> +#if SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GET
>> +#define INTERCEPTOR_PTHREAD_CONDATTR_GET(what, sz) \
>> +  INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_condattr_get##what, sz)
>> +INTERCEPTOR_PTHREAD_CONDATTR_GET(pshared, sizeof(int))
>> +INTERCEPTOR_PTHREAD_CONDATTR_GET(clock, sizeof(__sanitizer_clockid_t))
>> +#define INIT_PTHREAD_CONDATTR_GET                         \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_condattr_getpshared); \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_condattr_getclock);
>> +#else
>> +#define INIT_PTHREAD_CONDATTR_GET
>> +#endif
>> +
>> +#if SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GET
>> +#define INTERCEPTOR_PTHREAD_BARRIERATTR_GET(what, sz) \
>> +  INTERCEPTOR_PTHREAD_OBJECT_ATTR_GET(pthread_barrierattr_get##what, sz)
>> +INTERCEPTOR_PTHREAD_BARRIERATTR_GET(pshared, sizeof(int))
>> +#define INIT_PTHREAD_BARRIERATTR_GET \
>> +  COMMON_INTERCEPT_FUNCTION(pthread_barrierattr_getpshared);
>> +#else
>> +#define INIT_PTHREAD_BARRIERATTR_GET
>> +#endif
>> +
>> #if SANITIZER_INTERCEPT_TMPNAM
>> INTERCEPTOR(char *, tmpnam, char *s) {
>>   void *ctx;
>> @@ -4606,6 +4667,10 @@ static void InitializeCommonInterceptors
>>   INIT_PTHREAD_ATTR_GET;
>>   INIT_PTHREAD_ATTR_GETINHERITSCHED;
>>   INIT_PTHREAD_ATTR_GETAFFINITY_NP;
>> +  INIT_PTHREAD_MUTEXATTR_GET;
>> +  INIT_PTHREAD_RWLOCKATTR_GET;
>> +  INIT_PTHREAD_CONDATTR_GET;
>> +  INIT_PTHREAD_BARRIERATTR_GET;
>>   INIT_TMPNAM;
>>   INIT_TMPNAM_R;
>>   INIT_TEMPNAM;
>> 
>> 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=211166&r1=211165&r2=211166&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Jun 18 09:16:41 2014
>> @@ -163,6 +163,10 @@
>> #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
>>   SI_MAC || SI_LINUX_NOT_ANDROID
>> #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_LINUX_NOT_ANDROID
>> +#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GET SI_NOT_WINDOWS
>> +#define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GET SI_NOT_WINDOWS
>> +#define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GET SI_NOT_WINDOWS
>> +#define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GET SI_NOT_WINDOWS
>> #define SANITIZER_INTERCEPT_TMPNAM SI_NOT_WINDOWS
>> #define SANITIZER_INTERCEPT_TMPNAM_R SI_LINUX_NOT_ANDROID
>> #define SANITIZER_INTERCEPT_TEMPNAM SI_NOT_WINDOWS
>> 
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=211166&r1=211165&r2=211166&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Wed Jun 18 09:16:41 2014
>> @@ -1058,6 +1058,7 @@ CHECK_SIZE_AND_OFFSET(shmid_ds, shm_natt
>> #endif
>> 
>> CHECK_TYPE_SIZE(clock_t);
>> +CHECK_TYPE_SIZE(clockid_t);
>> 
>> #if !SANITIZER_ANDROID
>> CHECK_TYPE_SIZE(ifaddrs);
>> 
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=211166&r1=211165&r2=211166&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Wed Jun 18 09:16:41 2014
>> @@ -440,6 +440,8 @@ namespace __sanitizer {
>>   typedef long __sanitizer_clock_t;
>> #endif
>> 
>> +  typedef int __sanitizer_clockid_t;
>> +
>> #if SANITIZER_LINUX || SANITIZER_FREEBSD
>> #if defined(_LP64) || defined(__x86_64__) || defined(__powerpc__)
>>   typedef unsigned __sanitizer___kernel_uid_t;
>> 
>> 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=211166&r1=211165&r2=211166&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Wed Jun 18 09:16:41 2014
>> @@ -47,7 +47,7 @@ DECLARE_REAL(int, pthread_attr_getdetach
>> extern "C" int pthread_attr_setstacksize(void *attr, uptr stacksize);
>> extern "C" int pthread_key_create(unsigned *key, void (*destructor)(void* v));
>> extern "C" int pthread_setspecific(unsigned key, const void *v);
>> -extern "C" int pthread_mutexattr_gettype(void *a, int *type);
>> +DECLARE_REAL(int, pthread_mutexattr_gettype, void *, void *)
>> extern "C" int pthread_yield();
>> extern "C" int pthread_sigmask(int how, const __sanitizer_sigset_t *set,
>>                                __sanitizer_sigset_t *oldset);
>> @@ -1029,7 +1029,7 @@ TSAN_INTERCEPTOR(int, pthread_mutex_init
>>     bool recursive = false;
>>     if (a) {
>>       int type = 0;
>> -      if (pthread_mutexattr_gettype(a, &type) == 0)
>> +      if (REAL(pthread_mutexattr_gettype)(a, &type) == 0)
>>         recursive = (type == PTHREAD_MUTEX_RECURSIVE
>>             || type == PTHREAD_MUTEX_RECURSIVE_NP);
>>     }
>> 
>> Added: compiler-rt/trunk/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc?rev=211166&view=auto
>> ==============================================================================
>> --- compiler-rt/trunk/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc (added)
>> +++ compiler-rt/trunk/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc Wed Jun 18 09:16:41 2014
>> @@ -0,0 +1,20 @@
>> +// RUN: %clangxx -O0 %s -o %t && %run %t
>> +// XFAIL: arm-linux-gnueabi
>> +
>> +#include <assert.h>
>> +#include <pthread.h>
>> +
>> +int main(void) {
>> +  pthread_mutexattr_t ma;
>> +  int res = pthread_mutexattr_init(&ma);
>> +  assert(res == 0);
>> +  res = pthread_mutexattr_setpshared(&ma, 1);
>> +  assert(res == 0);
>> +  int pshared;
>> +  res = pthread_mutexattr_getpshared(&ma, &pshared);
>> +  assert(res == 0);
>> +  assert(pshared == 1);
>> +  res = pthread_mutexattr_destroy(&ma);
>> +  assert(res == 0);
>> +  return 0;
>> +}
>> 
>> Propchange: compiler-rt/trunk/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc
>> ------------------------------------------------------------------------------
>>    svn:eol-style = LF
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140618/1d28f835/attachment.html>


More information about the llvm-commits mailing list