<div dir="ltr">[The discussion is a little bit lengthy to understand from a first read, so don't blame me too much if I haven't understood the question]<div><br></div><div>Unfortunately, I don't know how to reliably do linker-initialized CriticalSections on Windows.  [+Dmitry, David or Reid might help]</div><div><br></div><div>Currently there is a hack in BlockingMutex::Lock @ sanitizer_win.cc that makes global mutexes work on Windows, but I think even this implementation fails to start sometimes.</div><div><br></div><div>Also please note we DON'T yet have a public buildbot that runs ASan tests on Windows.  I've been working on one this week and it's green, but it only compiles:</div><div><a href="http://lab.llvm.org:8011/builders/sanitizer-windows">http://lab.llvm.org:8011/builders/sanitizer-windows</a><br></div><div>Hopefully it will start running tests next week.<br><br><div class="gmail_quote">On Fri Feb 20 2015 at 8:28:36 AM Yuri Gribov <<a href="mailto:tetra2005@gmail.com">tetra2005@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Feb 20, 2015 at 5:19 AM, Alexey Samsonov <<a href="mailto:vonosmas@gmail.com" target="_blank" class="cremed">vonosmas@gmail.com</a>> wrote:<br>
><br>
> On Wed, Feb 18, 2015 at 5:29 AM, Yury Gribov <<a href="mailto:y.gribov@samsung.com" target="_blank" class="cremed">y.gribov@samsung.com</a>> wrote:<br>
>><br>
>> On 02/06/2015 09:10 AM, Yury Gribov wrote:<br>
>>><br>
>>> On 02/04/2015 07:23 PM, David Blaikie wrote:<br>
>>>><br>
>>>> On Wed, Feb 4, 2015 at 3:56 AM, Yury Gribov <<a href="mailto:tetra2005@gmail.com" target="_blank" class="cremed">tetra2005@gmail.com</a>> wrote:<br>
>>>><br>
>>>>>> Yes, I think enabling -Wglobal-constructors for ASan (and for all the<br>
>>>>><br>
>>>>> rest sanitizers) will be great.<br>
>>>>><br>
>>>>><br>
>>>>> FYI it was relatively easy to get this working on Linux (with ~500<br>
>>>>> lines<br>
>>>>> of changes). Unfortunately Windows compiler lacks too many necessary<br>
>>>>> features: explicit initialization of array members, constexpr,<br>
>>>>> unrestricted<br>
>>>>> unions (all still missing in VS2013 and we still use VS2012). Having<br>
>>>>> #if<br>
>>>>> WINDOWS all over the place isn't an option as well so I'm afraid we<br>
>>>>> are out<br>
>>>>> of luck.<br>
>>>>><br>
>>>><br>
>>>> Perhaps there's a relatively small number of structures (probably<br>
>>>> templates) we could create to keep all of this logic (and Windows<br>
>>>> workarounds/suppressions) in one place so it could scale to all the use<br>
>>>> cases we have?<br>
>>><br>
>>><br>
>>> Thanks for the idea, I'll check this next week.<br>
>><br>
>><br>
>> Folks,<br>
>><br>
>> Here is a draft version (not full-blown patch but rather a PoC). The main<br>
>> part is in sanitizer_internal_defs.h (classes LinkerInitializedArray and<br>
>> LinkerInitializedStructArray). I also slightly changed atomic types in<br>
>> sanitizer_atomic.h (volatile members can't be linker-initialized). Does this<br>
>> look sane in general?<br>
><br>
> +Timur for Windows parts.<br>
> Overall, yes, although missing constexpr is such a pain (sigh). Why is it<br>
> necessary to initialize all fields to 0 in LinkerInitialized constructor?<br>
<br>
You mean some classes may want non-zero values there? That's true, I<br>
planned to address this (the patch is a draft anyway).<br>
<br>
>> I've did full rebuild and regtests on Linux (compiler-rt built by trunk<br>
>> Clang, GCC 4.8 and Clang 3.1). I haven't done full testing on Windows and<br>
>> Mac but at least relevant parts of sanitizer_internal_defs.h compiled fine.<br>
>><br>
>> If all this makes sense, how should I proceed with a refactoring of this<br>
>> scale? Is it mandatory to verify _all_ platforms or I could to some extent<br>
>> rely on respected maintainers to fix errors? The former would be quite a<br>
>> burden.<br>
><br>
> Well, at least for LLVM, we have buildbots (for Linux/Mac/Windows), so it's<br>
> fine to test your change on available platforms, and then watch the<br>
> buildbots closely.<br>
<br>
Ok.<br>
<br>
> It would be awesome to rollout this out gradually, first by introducing<br>
> LinkerInitializedArray, then converting global objects to use constexpr<br>
> constructor one by one, and enabling -Wglobal-constructor as a final change.<br>
<br>
Right.<br>
<br>
-Y<br>
</blockquote></div></div></div>