<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 15, 2013 at 5:08 PM, Dmitry Vyukov <span dir="ltr"><<a href="mailto:dvyukov@google.com" target="_blank">dvyukov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Oct 15, 2013 at 4:32 PM, Alexey Samsonov <<a href="mailto:samsonov@google.com">samsonov@google.com</a>> wrote:<br>

><br>
> On Tue, Oct 15, 2013 at 4:12 PM, Dmitry Vyukov <<a href="mailto:dvyukov@google.com">dvyukov@google.com</a>> wrote:<br>
>><br>
>> On Tue, Oct 15, 2013 at 4:09 PM, Alexey Samsonov <<a href="mailto:samsonov@google.com">samsonov@google.com</a>><br>
>> wrote:<br>
>> ><br>
>> > On Tue, Oct 15, 2013 at 3:34 PM, Dmitry Vyukov <<a href="mailto:dvyukov@google.com">dvyukov@google.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> Author: dvyukov<br>
>> >> Date: Tue Oct 15 06:34:59 2013<br>
>> >> New Revision: 192688<br>
>> >><br>
>> >> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=192688&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=192688&view=rev</a><br>
>> >> Log:<br>
>> >> tsan: resolve symlinks for called_from_lib suppressions<br>
>> >><br>
>> >><br>
>> >> Modified:<br>
>> >>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc<br>
>> >>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h<br>
>> >>     compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc<br>
>> >><br>
>> >> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc<br>
>> >> URL:<br>
>> >><br>
>> >> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc?rev=192688&r1=192687&r2=192688&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc?rev=192688&r1=192687&r2=192688&view=diff</a><br>

>> >><br>
>> >><br>
>> >> ==============================================================================<br>
>> >> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc<br>
>> >> (original)<br>
>> >> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc Tue<br>
>> >> Oct<br>
>> >> 15 06:34:59 2013<br>
>> >> @@ -38,7 +38,12 @@ void LibIgnore::Init(const SuppressionCo<br>
>> >>    }<br>
>> >>  }<br>
>> >><br>
>> >> -void LibIgnore::OnLibraryLoaded() {<br>
>> >> +void LibIgnore::OnLibraryLoaded(const char *name) {<br>
>> >> +  const char *real_name = 0;<br>
>> >> +  InternalScopedBuffer<char> buf(4096);<br>
>> >> +  if (name != 0 && internal_readlink(name, buf.data(), buf.size() - 1)<br>
>> >> ><br>
>> >> 0)<br>
>> >> +    real_name = buf.data();<br>
>> >> +<br>
>> >>    BlockingMutexLock lock(&mutex_);<br>
>> >>    MemoryMappingLayout proc_maps(/*cache_enabled*/false);<br>
>> >>    InternalScopedBuffer<char> fn(4096);<br>
>> >> @@ -48,8 +53,14 @@ void LibIgnore::OnLibraryLoaded() {<br>
>> >>      proc_maps.Reset();<br>
>> >>      uptr b, e, off, prot;<br>
>> >>      while (proc_maps.Next(&b, &e, &off, fn.data(), fn.size(), &prot))<br>
>> >> {<br>
>> >> -      if ((prot & MemoryMappingLayout::kProtectionExecute) != 0 &&<br>
>> >> -          TemplateMatch(lib->templ, fn.data())) {<br>
>> >> +      bool symlink = false;<br>
>> >> +      if (((prot & MemoryMappingLayout::kProtectionExecute) != 0) &&<br>
>> >> +          (TemplateMatch(lib->templ, fn.data()) ||<br>
>> >> +          // Resolve symlinks.<br>
>> >> +          (real_name != 0 && real_name[0] != 0 &&<br>
>> >> +          TemplateMatch(lib->templ, name) &&<br>
>> >> +          internal_strcmp(real_name, fn.data()) == 0 &&<br>
>> >> +          (symlink = true)))) {<br>
>> ><br>
>> ><br>
>> > I think this expression is hard to understand. Also, shouldn't we have<br>
>> > TemplateMatch(lib->templ, real_name) here?<br>
>><br>
>> Why we should have it here?<br>
><br>
><br>
> Ok, this is fine (but it took me four iterations to understand what's going<br>
> on in this expression,<br>
> and I find "symlink = true" in condition and "fn" for memory mapping name<br>
> pretty annoying :( )<br>
<br>
<br>
</div></div>Done r192698.<br></blockquote><div><br></div><div>Thanks!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
>> >>          if (loaded) {<br>
>> >>            Report("%s: called_from_lib suppression '%s' is matched<br>
>> >> against"<br>
>> >>                   " 2 libraries: '%s' and '%s'\n",<br>
>> >> @@ -60,6 +71,8 @@ void LibIgnore::OnLibraryLoaded() {<br>
>> >>          if (!lib->loaded) {<br>
>> >>            lib->loaded = true;<br>
>> >>            lib->name = internal_strdup(fn.data());<br>
>> >> +          if (symlink)<br>
>> >> +            lib->real_name = internal_strdup(real_name);<br>
>> >>            const uptr idx = atomic_load(&loaded_count_,<br>
>> >> memory_order_relaxed);<br>
>> >>            code_ranges_[idx].begin = b;<br>
>> >>            code_ranges_[idx].end = e;<br>
>> >> @@ -77,7 +90,7 @@ void LibIgnore::OnLibraryLoaded() {<br>
>> >>  }<br>
>> >><br>
>> >>  void LibIgnore::OnLibraryUnloaded() {<br>
>> >> -  OnLibraryLoaded();<br>
>> >> +  OnLibraryLoaded(0);<br>
>> >>  }<br>
>> >><br>
>> >>  }  // namespace __sanitizer<br>
>> >><br>
>> >> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h<br>
>> >> URL:<br>
>> >><br>
>> >> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h?rev=192688&r1=192687&r2=192688&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h?rev=192688&r1=192687&r2=192688&view=diff</a><br>

>> >><br>
>> >><br>
>> >> ==============================================================================<br>
>> >> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h<br>
>> >> (original)<br>
>> >> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.h Tue<br>
>> >> Oct<br>
>> >> 15 06:34:59 2013<br>
>> >> @@ -33,7 +33,7 @@ class LibIgnore {<br>
>> >>    void Init(const SuppressionContext &supp);<br>
>> >><br>
>> >>    // Must be called after a new dynamic library is loaded.<br>
>> >> -  void OnLibraryLoaded();<br>
>> >> +  void OnLibraryLoaded(const char *name);<br>
>> >><br>
>> >>    // Must be called after a dynamic library is unloaded.<br>
>> >>    void OnLibraryUnloaded();<br>
>> >> @@ -45,6 +45,7 @@ class LibIgnore {<br>
>> >>    struct Lib {<br>
>> >>      char *templ;<br>
>> >>      char *name;<br>
>> >> +    char *real_name;  // target of symlink<br>
>> >>      bool loaded;<br>
>> >>    };<br>
>> >><br>
>> >><br>
>> >> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc<br>
>> >> URL:<br>
>> >><br>
>> >> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=192688&r1=192687&r2=192688&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=192688&r1=192687&r2=192688&view=diff</a><br>

>> >><br>
>> >><br>
>> >> ==============================================================================<br>
>> >> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)<br>
>> >> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Tue Oct 15<br>
>> >> 06:34:59 2013<br>
>> >> @@ -136,7 +136,7 @@ static LibIgnore *libignore() {<br>
>> >><br>
>> >>  void InitializeLibIgnore() {<br>
>> >>    libignore()->Init(*GetSuppressionContext());<br>
>> >> -  libignore()->OnLibraryLoaded();<br>
>> >> +  libignore()->OnLibraryLoaded(0);<br>
>> >>  }<br>
>> >><br>
>> >>  }  // namespace __tsan<br>
>> >> @@ -263,7 +263,7 @@ TSAN_INTERCEPTOR(void*, dlopen, const ch<br>
>> >>    thr->in_rtl = 0;<br>
>> >>    void *res = REAL(dlopen)(filename, flag);<br>
>> >>    thr->in_rtl = 1;<br>
>> >> -  libignore()->OnLibraryLoaded();<br>
>> >> +  libignore()->OnLibraryLoaded(filename);<br>
>> >>    return res;<br>
>> >>  }<br>
>> >><br>
>> >><br>
>> >><br>
>> >> _______________________________________________<br>
>> >> llvm-commits mailing list<br>
>> >> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>> >> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > --<br>
>> > Alexey Samsonov, MSK<br>
><br>
><br>
><br>
><br>
> --<br>
> Alexey Samsonov, MSK<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</div></div>