[compiler-rt] r192688 - tsan: resolve symlinks for called_from_lib suppressions

Dmitry Vyukov dvyukov at google.com
Tue Oct 15 06:08:01 PDT 2013


On Tue, Oct 15, 2013 at 4:32 PM, Alexey Samsonov <samsonov at google.com> wrote:
>
> On Tue, Oct 15, 2013 at 4:12 PM, Dmitry Vyukov <dvyukov at google.com> wrote:
>>
>> On Tue, Oct 15, 2013 at 4:09 PM, Alexey Samsonov <samsonov at google.com>
>> wrote:
>> >
>> > On Tue, Oct 15, 2013 at 3:34 PM, Dmitry Vyukov <dvyukov at google.com>
>> > wrote:
>> >>
>> >> Author: dvyukov
>> >> Date: Tue Oct 15 06:34:59 2013
>> >> New Revision: 192688
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=192688&view=rev
>> >> Log:
>> >> tsan: resolve symlinks for called_from_lib suppressions
>> >>
>> >>
>> >> Modified:
>> >>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc
>> >>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h
>> >>     compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
>> >>
>> >> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc
>> >> URL:
>> >>
>> >> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc?rev=192688&r1=192687&r2=192688&view=diff
>> >>
>> >>
>> >> ==============================================================================
>> >> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc
>> >> (original)
>> >> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc Tue
>> >> Oct
>> >> 15 06:34:59 2013
>> >> @@ -38,7 +38,12 @@ void LibIgnore::Init(const SuppressionCo
>> >>    }
>> >>  }
>> >>
>> >> -void LibIgnore::OnLibraryLoaded() {
>> >> +void LibIgnore::OnLibraryLoaded(const char *name) {
>> >> +  const char *real_name = 0;
>> >> +  InternalScopedBuffer<char> buf(4096);
>> >> +  if (name != 0 && internal_readlink(name, buf.data(), buf.size() - 1)
>> >> >
>> >> 0)
>> >> +    real_name = buf.data();
>> >> +
>> >>    BlockingMutexLock lock(&mutex_);
>> >>    MemoryMappingLayout proc_maps(/*cache_enabled*/false);
>> >>    InternalScopedBuffer<char> fn(4096);
>> >> @@ -48,8 +53,14 @@ void LibIgnore::OnLibraryLoaded() {
>> >>      proc_maps.Reset();
>> >>      uptr b, e, off, prot;
>> >>      while (proc_maps.Next(&b, &e, &off, fn.data(), fn.size(), &prot))
>> >> {
>> >> -      if ((prot & MemoryMappingLayout::kProtectionExecute) != 0 &&
>> >> -          TemplateMatch(lib->templ, fn.data())) {
>> >> +      bool symlink = false;
>> >> +      if (((prot & MemoryMappingLayout::kProtectionExecute) != 0) &&
>> >> +          (TemplateMatch(lib->templ, fn.data()) ||
>> >> +          // Resolve symlinks.
>> >> +          (real_name != 0 && real_name[0] != 0 &&
>> >> +          TemplateMatch(lib->templ, name) &&
>> >> +          internal_strcmp(real_name, fn.data()) == 0 &&
>> >> +          (symlink = true)))) {
>> >
>> >
>> > I think this expression is hard to understand. Also, shouldn't we have
>> > TemplateMatch(lib->templ, real_name) here?
>>
>> Why we should have it here?
>
>
> Ok, this is fine (but it took me four iterations to understand what's going
> on in this expression,
> and I find "symlink = true" in condition and "fn" for memory mapping name
> pretty annoying :( )


Done r192698.

>> >>          if (loaded) {
>> >>            Report("%s: called_from_lib suppression '%s' is matched
>> >> against"
>> >>                   " 2 libraries: '%s' and '%s'\n",
>> >> @@ -60,6 +71,8 @@ void LibIgnore::OnLibraryLoaded() {
>> >>          if (!lib->loaded) {
>> >>            lib->loaded = true;
>> >>            lib->name = internal_strdup(fn.data());
>> >> +          if (symlink)
>> >> +            lib->real_name = internal_strdup(real_name);
>> >>            const uptr idx = atomic_load(&loaded_count_,
>> >> memory_order_relaxed);
>> >>            code_ranges_[idx].begin = b;
>> >>            code_ranges_[idx].end = e;
>> >> @@ -77,7 +90,7 @@ void LibIgnore::OnLibraryLoaded() {
>> >>  }
>> >>
>> >>  void LibIgnore::OnLibraryUnloaded() {
>> >> -  OnLibraryLoaded();
>> >> +  OnLibraryLoaded(0);
>> >>  }
>> >>
>> >>  }  // namespace __sanitizer
>> >>
>> >> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h
>> >> URL:
>> >>
>> >> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h?rev=192688&r1=192687&r2=192688&view=diff
>> >>
>> >>
>> >> ==============================================================================
>> >> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h
>> >> (original)
>> >> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h Tue
>> >> Oct
>> >> 15 06:34:59 2013
>> >> @@ -33,7 +33,7 @@ class LibIgnore {
>> >>    void Init(const SuppressionContext &supp);
>> >>
>> >>    // Must be called after a new dynamic library is loaded.
>> >> -  void OnLibraryLoaded();
>> >> +  void OnLibraryLoaded(const char *name);
>> >>
>> >>    // Must be called after a dynamic library is unloaded.
>> >>    void OnLibraryUnloaded();
>> >> @@ -45,6 +45,7 @@ class LibIgnore {
>> >>    struct Lib {
>> >>      char *templ;
>> >>      char *name;
>> >> +    char *real_name;  // target of symlink
>> >>      bool loaded;
>> >>    };
>> >>
>> >>
>> >> 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=192688&r1=192687&r2=192688&view=diff
>> >>
>> >>
>> >> ==============================================================================
>> >> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
>> >> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Tue Oct 15
>> >> 06:34:59 2013
>> >> @@ -136,7 +136,7 @@ static LibIgnore *libignore() {
>> >>
>> >>  void InitializeLibIgnore() {
>> >>    libignore()->Init(*GetSuppressionContext());
>> >> -  libignore()->OnLibraryLoaded();
>> >> +  libignore()->OnLibraryLoaded(0);
>> >>  }
>> >>
>> >>  }  // namespace __tsan
>> >> @@ -263,7 +263,7 @@ TSAN_INTERCEPTOR(void*, dlopen, const ch
>> >>    thr->in_rtl = 0;
>> >>    void *res = REAL(dlopen)(filename, flag);
>> >>    thr->in_rtl = 1;
>> >> -  libignore()->OnLibraryLoaded();
>> >> +  libignore()->OnLibraryLoaded(filename);
>> >>    return res;
>> >>  }
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> llvm-commits mailing list
>> >> llvm-commits at cs.uiuc.edu
>> >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>> >
>> >
>> >
>> >
>> > --
>> > Alexey Samsonov, MSK
>
>
>
>
> --
> Alexey Samsonov, MSK



More information about the llvm-commits mailing list