[compiler-rt] r219675 - tsan: refactor atexit handling

Dmitry Vyukov dvyukov at google.com
Sun Nov 16 06:34:20 PST 2014


On Tue, Nov 4, 2014 at 5:31 AM, Kostya Serebryany <kcc at google.com> wrote:
>
>
> On Tue, Oct 14, 2014 at 2:32 AM, Dmitry Vyukov <dvyukov at google.com> wrote:
>>
>> Author: dvyukov
>> Date: Tue Oct 14 04:32:45 2014
>> New Revision: 219675
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=219675&view=rev
>> Log:
>> tsan: refactor atexit handling
>> The current handling (manual execution of atexit callbacks)
>> is overly complex and leads to constant problems due to mutual ordering of
>> callbacks.
>> Instead simply wrap callbacks into our wrapper to establish
>> the necessary synchronization.
>> Fixes issue https://code.google.com/p/thread-sanitizer/issues/detail?id=80
>>
>>
>> Added:
>>     compiler-rt/trunk/test/tsan/dlclose.cc
>> Modified:
>>     compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
>>
>> 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=219675&r1=219674&r2=219675&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Tue Oct 14
>> 04:32:45 2014
>> @@ -105,11 +105,6 @@ typedef void (*sighandler_t)(int sig);
>>
>>  #define errno (*__errno_location())
>>
>> -// 16K loaded modules should be enough for everyone.
>> -static const uptr kMaxModules = 1 << 14;
>> -static LoadedModule *modules;
>> -static uptr nmodules;
>> -
>>  struct sigaction_t {
>>    union {
>>      sighandler_t sa_handler;
>> @@ -289,6 +284,7 @@ TSAN_INTERCEPTOR(int, nanosleep, void *r
>>    return res;
>>  }
>>
>> +/*
>>  class AtExitContext {
>>   public:
>>    AtExitContext()
>> @@ -346,6 +342,26 @@ class AtExitContext {
>>  };
>>
>>  static AtExitContext *atexit_ctx;
>> +*/
>> +
>> +// The sole reason tsan wraps atexit callbacks is to establish
>> synchronization
>> +// between callback setup and callback execution.
>> +struct AtExitCtx {
>> +  void (*f)();
>> +  void *arg;
>> +};
>> +
>> +static void at_exit_wrapper(void *arg) {
>> +  ThreadState *thr = cur_thread();
>> +  uptr pc = 0;
>
>
> Why you do not call SCOPED_INTERCEPTOR_RAW here?
> This way if there is a race inside the atexit handler we lose the stack
> trace and don't know where the atexit handler was called from.

Well, it's called from nowhere. Just called. What a user can expect to
see below atexit handler?
Or you mean backtrace through libc? Tsan don't do it.



More information about the llvm-commits mailing list