<div dir="ltr">I don't think this is a good way to go.  Does LLVM support reinitializing and calling llvm_shutdown() multiple times?  If so, this won't work.<div><br></div><div>How about adding a variant of ManagedStatic that registers the destructor with atexit(), just like C++ dynamic initializers do, instead of the LLVM shutdown machinery?</div>
<div><br></div><div>Then we could convert llvm::outs() to use it, thereby potential initialization races on Windows.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Sep 12, 2013 at 12:07 PM, Filip Pizlo <span dir="ltr"><<a href="mailto:fpizlo@apple.com" target="_blank">fpizlo@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This patch converts PrettyStackTrace to use ManagedStatic.  PrettyStackTrace is both important to convert to ManagedStatic, and surprisingly tricky.<br>

<br>
It's important because LLVM uses it in a lot of places.  This means that if you have a program that calls into LLVM on one thread while calling exit() on another without first doing a clean shutdown, you'll see assertions or crashes inside of PrettyStackTrace and/or inside ThreadLocal.<br>

<br>
This patch was surprisingly tricky because we often use PrettyStackTraceProgram in a way that causes its destruction to occur after shutdown.  I added a function called llvm_shutdown_has_been_called() to allow ~PrettyStackTrace to skip removing itself from the stack if we're past shutdown.  This is as safe as it gets: if we're done with shutdown then ManagedStatics are all destroyed and poisoned and so the only alternative to skipping removal from the stack is to trip over the assert that comes just after.  I went with this rather conservative approach because after seeing that llc did shutdown before ~PrettyStackTraceProgram, I sort of made the assumption that probably a bunch of llvm clients do it, and I didn't want them to start asserting or crashing on exit.<br>

<br>
I'm curious if there are better ways to do this, that don't involve revealing llvm_shutdown_has_been_called().  For example I considered making PrettyStackTraceProgram skip removal of the stack trace entry from the stack, but that felt even more yucky than my currently solution.  I also considered putting llvm_shutdown_obj before PrettyStackTraceProgram in all tools, but this felt too risky - I'm conservatively assuming outside clients might already be relying on this idiom being fine.<br>

<span class="HOEnZb"><font color="#888888"><br>
-Filip<br>
<br>
</font></span><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></blockquote></div><br></div>