[llvm] r205137 - Don't mark the declarations of the TSan annotation functions as weak.

Kostya Serebryany kcc at google.com
Mon Mar 31 00:06:39 PDT 2014


+dvyukov

These annotations were needed when Nick was testing llvm-as-a-library in
multi-threaded environment under the old valgrind-based tsan.
Now we have our new and shiny LLVM-based tsan, which understands atomics
and c++11.
The next time we touch this code I suggest to rewrite the whole thing in
c++11 (e.g. using std::call_once?) and get rid of the annotations.
BTW, do we have any multi-threaded tests for this code?

--kcc


On Mon, Mar 31, 2014 at 12:22 AM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Chandler Carruth wrote:
>
>> Author: chandlerc
>> Date: Sun Mar 30 06:20:25 2014
>> New Revision: 205137
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=205137&view=rev
>> Log:
>> Don't mark the declarations of the TSan annotation functions as weak.
>> That causes references to them to be weak references which can collapse
>> to null if no definition is provided.
>>
>
> Whoops! I didn't realize that attribute weak on a declaration meant
> something different from attribute weak on a definition. Thanks for the fix!
>
> Nick
>
>  We call these functions
>
>> unconditionally, so a definition *must* be provided. Make the
>> definitions provided in the .cpp file weak by re-declaring them as weak
>> just prior to defining them. This should keep compilers which cannot
>> attach the weak attribute to the definition happy while actually
>> resolving the symbols correctly during the link.
>>
>> You might ask yourself upon reading this commit log: how did *any* of
>> this work before? Well, fun story. It turns out we have some code in
>> Support (BumpPtrAllocator) which both uses virtual dispatch and has
>> out-of-line vtables used by that virtual dispatch. If you move the
>> virtual dispatch into its header in *just* the right way, the optimizer
>> gets to devirtualize, and remove all references to the vtable. Then the
>> sad part: the references to this one vtable were the only strong symbol
>> uses in the support library for llvm-tblgen AFAICT. At least, after
>> doing something just like this, these symbols stopped getting their weak
>> definition and random calls to them would segfault instead.
>>
>> Yay software.
>>
>> Modified:
>>      llvm/trunk/include/llvm/Support/Valgrind.h
>>      llvm/trunk/lib/Support/Valgrind.cpp
>>
>> Modified: llvm/trunk/include/llvm/Support/Valgrind.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/
>> llvm/Support/Valgrind.h?rev=205137&r1=205136&r2=205137&view=diff
>> ============================================================
>> ==================
>> --- llvm/trunk/include/llvm/Support/Valgrind.h (original)
>> +++ llvm/trunk/include/llvm/Support/Valgrind.h Sun Mar 30 06:20:25 2014
>> @@ -24,12 +24,10 @@
>>   // tsan (Thread Sanitizer) is a valgrind-based tool that detects these
>> exact
>>   // functions by name.
>>   extern "C" {
>> -LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
>> -                                              const volatile void *cv);
>> -LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int
>> line,
>> -                                               const volatile void *cv);
>> -LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file,
>> int line);
>> -LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int
>> line);
>> +void AnnotateHappensAfter(const char *file, int line, const volatile
>> void *cv);
>> +void AnnotateHappensBefore(const char *file, int line, const volatile
>> void *cv);
>> +void AnnotateIgnoreWritesBegin(const char *file, int line);
>> +void AnnotateIgnoreWritesEnd(const char *file, int line);
>>   }
>>   #endif
>>
>>
>> Modified: llvm/trunk/lib/Support/Valgrind.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
>> Support/Valgrind.cpp?rev=205137&r1=205136&r2=205137&view=diff
>> ============================================================
>> ==================
>> --- llvm/trunk/lib/Support/Valgrind.cpp (original)
>> +++ llvm/trunk/lib/Support/Valgrind.cpp Sun Mar 30 06:20:25 2014
>> @@ -55,13 +55,21 @@ void llvm::sys::ValgrindDiscardTranslati
>>
>>   #if LLVM_ENABLE_THREADS != 0&&  !defined(NDEBUG)
>>
>>   // These functions require no implementation, tsan just looks at the
>> arguments
>> -// they're called with.
>> +// they're called with. However, they are required to be weak as some
>> other
>> +// application or library may already be providing these definitions for
>> the
>> +// same reason we are.
>>   extern "C" {
>> +LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
>> +                                              const volatile void *cv);
>> +void AnnotateHappensAfter(const char *file, int line, const volatile
>> void *cv) {
>> +}
>> +LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int
>> line,
>> +                                               const volatile void *cv);
>>   void AnnotateHappensBefore(const char *file, int line,
>>                              const volatile void *cv) {}
>> -void AnnotateHappensAfter(const char *file, int line,
>> -                          const volatile void *cv) {}
>> +LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file,
>> int line);
>>   void AnnotateIgnoreWritesBegin(const char *file, int line) {}
>> +LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int
>> line);
>>   void AnnotateIgnoreWritesEnd(const char *file, int line) {}
>>   }
>>   #endif
>>
>>
>> _______________________________________________
>> 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/20140331/f73178c2/attachment.html>


More information about the llvm-commits mailing list