<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>I've put a patch up for this here:
<a class="moz-txt-link-freetext" href="https://reviews.llvm.org/D50994">https://reviews.llvm.org/D50994</a></p>
<p>Thanks!<br>
</p>
<br>
<div class="moz-cite-prefix">On 7/16/18 2:55 PM, JF Bastien via
cfe-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:2EA323C2-E8A5-4818-9596-DE8F9A27D123@apple.com">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="">Hi folks,</div>
<div class=""><br class="">
</div>
<div class="">I’d like to add a flag in clang, <font class=""
face="Courier New">-fno-cxx-static-destructors</font>, which
allows developers to demand that no static destructors be
emitted. Bruno has <a href="https://reviews.llvm.org/D22474"
class="" moz-do-not-send="true">a sample implementation</a>.
We’ve <a
href="http://lists.llvm.org/pipermail/cfe-dev/2016-July/050040.html"
class="" moz-do-not-send="true">discussed this previously</a> but
I’d like to re-open the discussion and make a different case for
it because we’ve received more requests for such a feature.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><b class="">Why is this desirable?</b></div>
<div class=""><br class="">
</div>
<div class="">In low-memory circumstances it’s often the case that
we know that static global destructors are never called. It
would be useful to avoid emitting them entirely to save memory.
We can’t necessarily make the types themselves trivially
destructible (e.g. a <font class="" face="Courier New">std::map</font>,
or a type that’s used both as a global and as an automatic
variable for which the destructor is only meaningful when
automatic, or coming from 3rd party library such as boost), and
using a <font class="" face="Courier New">NeverDestroyed<T></font>
class or global pointer only (<font class="" face="Courier New">std::string&
foo = *new std::string(“derp");</font>) prevents <font
class="" face="Courier New">constexpr</font> and is annoying
boilerplate (and again, 3rd party code breaks that party).</div>
<div class=""><br class="">
</div>
<div class="">This is also useful for some thread-related use
cases: we have empirical evidence that threads using globals
cause crashes if these globals are being destroyed.</div>
<div class=""><br class="">
</div>
<div class="">Thread-local storage is similarly painful for
different reasons. I’m not proposing that anything be done yet,
but let’s keep it in mind.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><b class="">Developers want this?</b></div>
<div class=""><br class="">
</div>
<div class="">Yes, we’ve received numerous requests for this.
Developers are worried about code footprint, and have numerous
crash reports they’d like to get rid of. Developers tell us
they’d really rather not pay for this feature, because they
don’t want to use it yet are stuck with it (and C++ is a “don’t
pay for what you don’t use” language).</div>
<div class="">Interesting note: developers are used to having no
cleanup on termination on platforms where applications can get
terminated when e.g. they’re sent to the background by user
action.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><b class="">Concrete example</b></div>
<div class=""><br class="">
</div>
<div class="">Greg Parker provided this example of thread-related
issues in the previous discussion:</div>
<div class=""><br class="">
</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">
<div class="">
<div class="">The Objective-C runtime has a global table that
stores retain counts. Pretty much all Objective-C code in
the process uses this table. With global destructors in
place this table is destroyed during exit(). If any other
thread is still running Objective-C code then it will crash.</div>
</div>
<div class="">
<div class=""><br class="">
</div>
</div>
<div class="">
<div class="">Currently the Objective-C runtime avoids the
destructor by initializing this table using placement new
into an aligned static char buffer.</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">I’m assuming that the embedded usecase is obvious
enough to everyone to not need an example. Let me know if that’s
not the case.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><b class="">What about standardization?</b></div>
<div class=""><br class="">
</div>
<div class="">If this works out I'll discuss standardization
options through SG14 (and then WG21). The type of developer
who’s asked for this are typical SG14 targets (embedding,
gaming, etc). This might fit in with “freestanding” or other
similar SG14 efforts, but we need experience to guide the
proposal. Maybe EWG will be interested as well? 🤷♂️</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class=""><br class="">
</div>
<div class="">JF</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>