<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Dec 13, 2016 at 1:22 PM, Matthias Braun <span dir="ltr"><<a href="mailto:mbraun@apple.com" target="_blank">mbraun@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Dec 13, 2016, at 12:56 PM, Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<br>
><br>
> Given that LLVM has so many auto-registration systems (cl::opt, target registry, pass registry, statistics, I'm sure there's more), maybe we should spend the time to build an auto-registration system that doesn't involve static constructors?<br>
</span>I would volunteer to do the work, however this obviously needs some consensus first on how that would look.<br>
<span class=""><br>
><br>
> It needs custom code for every supported object file format, and is hard to get right when DSOs are involved, but in the long run it's probably worth fixing this problem once and for all.<br>
</span>I assume you are thinking about creating custom linker sections with list of init functions; Similar to the existing constructors sections but running at a time controlled by llvm code. While the compiler/linker nerd in me would love doing that, I could see this being very tricky to pull off consistenly on all platforms.<br></blockquote><div><br></div><div>The goal of using sections would be to build the array of statistics without running any code. This is only possible when you have one DSO. Once you have a second DSO, it will need to run some initialization code to link the two arrays together.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
We should not forget that there is a portable and proven solution: Just write the code!</blockquote><div><br></div><div>Yep, that always works, and you can control when it happens so you don't have to run initializers scattered across your binary at startup.</div></div></div></div>