<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Sep 19, 2013, at 10:34 AM, Chandler Carruth <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">On Wed, Sep 18, 2013 at 9:06 PM, Andrew Trick <span dir="ltr"><<a href="mailto:atrick@apple.com" target="_blank" class="cremed">atrick@apple.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="h5"><br><div><div>On Sep 18, 2013, at 8:58 AM, Chris Lattner <<a href="mailto:clattner@apple.com" target="_blank" class="cremed">clattner@apple.com</a>> wrote:</div>
<br><blockquote type="cite"><div style="word-wrap:break-word"><div>On Sep 17, 2013, at 10:10 AM, Andrew Trick <<a href="mailto:atrick@apple.com" target="_blank" class="cremed">atrick@apple.com</a>> wrote:</div><blockquote type="cite">
LLVM's internal command line library needs to evolve. We have an immediate need to build LLVM as a library free of static initializers, but before brute-force fixing this problem, I'd like outline the incremental steps that will lead to a desirable long term solution. We want infrastructure in place to provide an evolutionary path.</blockquote>
<div><br></div>Thank you for tackling this, we should have fixed this years ago.<br><br>Please do a pass over the cl::opts we have, and remove ones that are long dead or unused.   Do we still need -join-liveintervals? :-)<br>
<br><br><div><div>On Sep 17, 2013, at 12:03 PM, Daniel Dunbar <<a href="mailto:daniel@zuster.org" target="_blank" class="cremed">daniel@zuster.org</a>> wrote:</div><blockquote type="cite"><div dir="ltr">On Tue, Sep 17, 2013 at 11:29 AM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank" class="cremed">rnk@google.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Wait, I have a terrible idea.  Why don't we roll our own .init_array style appending section?  I think we can make this work for all toolchains we support.</div></blockquote><div><br></div><div>Andy and I talked about this, but I don't think its worth it. My opinion is:</div>

<div>1. For tool options (the top-level llc, opt, llvm-as etc. opts) it doesn't matter.</div><div>2. For experimental options (options that we would be happy if they were compiled out of a production compiler/JIT client/whatever), it doesn't matter.</div>

<div>3. For backend options that need to always be available, lots of them probably already need to get promoted to real API.</div><div>4. For the remaining options (ones that don't need to become API, but also aren't purely experimental), many of them can probably easily be initialized by some existing initialization hook (pass initialization, target initialization).</div>

<div>5. There aren't enough options left not in those categories to motivate some kind of clever solution.</div></div></div></div></blockquote><br></div><div>I think that this is a great summary of the problem.  Having cl::opt's compiled *out* of non-assert build by default makes a lot of sense to me, and having tool options use toolopt<> (or something) also makes perfect sense.</div>
<div><br></div><div>If you're going to go and tackle pass-specific options, I think that we should consider changing the syntax and overall design of the command line options.   We already have some manual name mangling/namespacification of options (e.g. -tail-dup-limit=). Perhaps we should formalize this somehow?</div>
</div></blockquote><br></div></div></div><div><div>Obviously, based on the 18 responses I've gotten, the tone of my first email was misleading.</div><div><br></div><div>I don’t want to stifle discussion, but to be clear, the only thing I propose to tackle immediately is the removal of static initializers from libraries. There are several isolated issues that Filip has found good workarounds for. cl::opt is the one pervasive problem that can't be weeded out one case at a time.</div>
<div><br></div><div>The purpose of posting an RFC and opening up discussion was to find out from people who have already thought about this, how the ideal cl::opt framework should work. I won't be making that happen, rather I'll make sure that the changes we make don't get in the way of future progress.</div>
<div><br></div><div>I would certainly love to see LLVM internal options be reorganized and help however I can, but I'll be very sad if that holds up removing static initializers.</div></div></div></blockquote><div><br>
</div><div>=/ I think we should actually implement the right long-term design rather than something short term.</div><div><br></div><div>Anyways, I feel like there are (at least) three possible problems you want to solve here, and I'd like to understand which (maybe all) you're actually trying to solve, and which ones seem most important:</div>
<div><br></div><div>1) threads still alive during program termination reading from flags that are being destroyed along with all globals</div><div><br></div><div>2) initialization ordering issues between flags in different translation units</div>
<div><br></div><div>3) the existence of (non-zero-initializing) static initializers at all</div><div><br></div><div><br></div><div>For me, #1 and #2 are things I care a lot about and would be happy to see solved. But #3 doesn't seem necessary or even desirable. We have a lot of registration patterns in LLVM that make working with it very simple and easy. It's not clear why we would want to preclude this, or re-invent the mechanisms that already exist to automatically trigger static initialization with the arbitrary fan-out of 'initializeFoo' global functions. So if #3 is really an important goal, I'm curious about the why. =] This is especially relevant as it impacts all of the work I'm starting to do on the pass management and registration system.</div></div></div></div></blockquote><div><br></div><div>Frameworks on Mac and iOS don't have static initializers, since their presence would hurt application start-up time.  Thus, static initializers in LLVM would prevent LLVM from being used as a framework on these platforms.</div><div><br></div><div>We'd like to use LLVM as a JIT in WebKit (<a href="https://bugs.webkit.org/show_bug.cgi?id=112840">https://bugs.webkit.org/show_bug.cgi?id=112840</a>).  If we linked LLVM into WebKit, every application would have to run LLVM's static initializers on start-up, which we don't want.</div><div><br></div><div>WebKit's LLVM integration already ensures that (1) LLVM is only invoked for functions that are sufficiently hot and (2) LLVM is always invoked on a thread.  So even if there was some explicit initialization process that had to run prior to the first LLVM compile, that would be fine - the effect on application responsiveness would be minimal since you wouldn't run it every time and you would run it on a separate thread.</div><div><br></div><div>Although I'm less familiar with dynamic library conventions on other platforms, I suspect that even non-Mac/iOS applications that wanted to do some JITing via LLVM would end up suffering the same problem: it's much harder to pursue using LLVM as a JIT if just linking to LLVM means that the application has to go through all of LLVM's static initializers each time it starts.</div><div><br></div><div>-Filip</div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div><br></div><div><br></div><div>As a somewhat separable point, I completely agree that every flag which any frontend actually needs to control for correct functionality should be moved from flags to an actual, proper interface as global flags just don't work for a library. Essentially, they should be "debugging" tools or "developer" tools, not actual interfaces. This isn't true today, and the most egregious cases are the emission of debug information. All of that is controlled through global flags, which causes lots of problems today for our library users of LLVM.</div>
<div><br></div><div>However, I don't think the flags should only be present in !NDEBUG builds. I think its reasonable for developers to debug problems with released binaries by causing these flags to be toggled using '-mllvm' or related tools in the frontends to manually parse flags, or by 'opt' automatically handing the flag parsing down to this layer.</div>
</div></div></div>
</blockquote></div><br></body></html>