<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 16, 2016 at 12:31 PM, Pete Cooper via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class="gmail-"><blockquote type="cite"><div>On Dec 16, 2016, at 11:46 AM, Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:</div><br class="gmail-m_-5869550416470507579Apple-interchange-newline"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Dec 16, 2016 at 11:18 AM, Pete Cooper <span dir="ltr"><<a href="mailto:peter_cooper@apple.com" target="_blank">peter_cooper@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">Hi Rui<div><br></div><div>I agree separating the components out in to libraries only makes sense when there is a clear reason to do so. However, just this year there was a very involved discussion about what it means to be a library. Specifically, I don't think your current 'main-as-library' argument is valid while you call exit or (if you) rely on mutable global state. Having a single entry point via a main function is fine, but that function cannot then kill the process which its linked in to.</div></div></blockquote><div><br></div><div>Our main function returns as long as input object files are not corrupted. If you are doing in-memory linking, I think it is unlikely that the object files in memory are corrupted (especially when you just created them using LLVM), so I think this satisfies most users needs in practice. Do you have a concern about that?</div></div></div></div></div></blockquote></span>Ultimately my concern is that there is *any* code path calling exit. I would say that this prevents the lld library from being used in-process. But others opinions may differ, and I honestly don't have a use case in mind, just that I don't think library code should ever call exit.</div></div></blockquote><div><br></div><div>I agreed with the sentiment at first, but after thinking about it for a while, I actually have convinced myself that it doesn't hold water under closer inspection.</div><div><br></div><div>The fundamental thing is that the LLVM libraries actually do have tons of fatal errors; they're just in the form of assert's (or we'll dereference a null pointer, or run off the end of a data structure, or go into an infinite loop, etc.).</div><div><br></div><div>If you pass a corrupted Module to LLVM through the library API, you can certainly trip tons of "fatal errors" (in the form of failed assertions or UB). The way that LLVM gets around this is by having a policy of "if you pass it corrupted Module that doesn't pass the verifier, it's your fault, you're using our API wrong". Why can't an LLD library API have that same requirement?</div><div><br></div><div>If it is safe for clang to uses the LLVM library API without running the verifier as its default configuration for non-development builds, why would it be unsafe for (say) clang to pass an object file directly to LLD as a library without verification? Like Rui said, it's absolutely possible to create a verifier pass for LLD; it just hasn't been written because most object files we've seen so far seem to come from a small number of well-tested codepaths that always (as in the `assert` meaning of "always") create valid ELF files. In fact, we've added graceful recovery as appropriate (e.g. r259831), which is a step above error handling!</div><div><br></div><div>Also, I'd like to point out that Clang, even when it does run the LLVM verifier (which is not the default except in development builds), runs it with fatal error handling. Is anybody aware of a program that uses LLVM as a library, produces IR in memory, runs the verifier, and does not simply abort if the verifier fails in non-development builds?</div><div><br></div><div>-- Sean Silva</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><span class="gmail-"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>For the situation that you need to handle foreign object files in the same process (I'd recommend you to sandbox a process in that case though), we can write a verifier to check for file correctness rigorously so that we can guarantee that object files are as trustworthy as freshly-created object files. I think this feature is a reasonable addition to the linker.</div></div></div></div></div></blockquote></span>That sounds great. Having written some parts of the MachO lld linker and seen Kevin's work on llvm-objdump, I can appreciate that is not easy. For example, I wrote the logic to process EH FDE's which may need to error out if invalid. You don't necessarily want to validate them all up front as it may be too slow, so I can understand that this isn't necessarily trivial to handle in a performant way.<span class="gmail-"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>As to the mutable shared state, my current (unproved) idea is to make them thread local variables. Since no one yet has come up to say "hey, we are actually trying to run multiple instances of the linker in the same process simultaneously but LLD doesn't allow that", that's not implemented yet, but technically I think it's doable, and that's needless to say a reasonable feature request.</div></div></div></div></div></blockquote></span>LLVM uses the LLVMContext for this (and begs users to look the other way with regards to cl::opt's). I don't know if there's been a discussion in LLVM about whether TLV's would be better there too, but seems like a reasonable discussion to have. Certainly I don't think anyone should say you can't use them without good reason.<span class="gmail-"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>As I repeatedly said in the thread that speed is not the only goal for us. Honestly, it's going to be the best selling point of LLD, because most people do not use that many linker features but just use it to create executables (and sometimes wait for a long period of time). I reported about the performance in this thread because I thought people would be happy to hear the speed improvement we've made this year. Also, because I was happy about that, I probably emphasized that too much. But that's not our single goal.</div></div></div></div></div></blockquote></span>I meant to commend you for both sending out a summary email, and the results. Having this fast a linker on ELF/COFF is going to be a huge win for developers. And I personally really like status updates for major projects/features as it can be hard to follow along with all the email traffic. So thank you for doing that.</div><div><br></div><div>My only concern with performance is that I felt like you would be against changes to the code which make it slower but add functionality. Error handling is such a use case. LLVM and clang continue to get bigger each year and sometimes that means a little slower too. The linker may be faster next year than it is now, or it may be slower but have a feature which makes that a worthwhile tradeoff. I don't want to slow down any of the code for any reason, but its natural that sometimes it'll happen with good reason.</div><div><br></div><div>Thanks,</div><div>Pete<div><div class="gmail-h5"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>If you want context then the relevant piece of the thread is <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/093760.html" target="_blank">http://lists.llvm.org/piper<wbr>mail/llvm-dev/2016-January/<wbr>093760.html</a>.</div><div><br></div><div>Arseny summarized things very well there, so i'll just quote him at the end here. I understand that you and others want to first write a fast linker tool and i don't think anyone has any problem with that, but there is also a clear desire from folks to have it be usable as a library and I would hope any patches to do so are accepted, even if they make the code more complex, or slower.</div><div><br></div><div><pre style="white-space:pre-wrap;background-color:rgb(255,255,255)">>>><i> On Thu, Jan 7, 2016 at 7:03 AM, Arseny Kapoulkine via llvm-dev <
</i>>>><i> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">llvm-dev at lists.llvm.org</a>> wrote:
</i>>>><i>
</i>>>>><i> In the process of migrating from old lld ELF linker to new (previously
</i>>>>><i> ELF2) I noticed the interface lost several important features (ordered by
</i>>>>><i> importance for my use case):
</i>>>>><i>
</i>>>>><i> 1. Detecting errors in the first place. New linker seems to call
</i>>>>><i> exit(1) for any error.
</i>>>>><i>
</i>>>>><i> 2. Reporting messages to non-stderr outputs. Previously all link
</i>>>>><i> functions had a raw_ostream argument so it was possible to delay the error
</i>>>>><i> output, aggregate it for multiple linked files, output via a different
</i>>>>><i> format, etc.
</i>>>>><i>
</i>>>>><i> 3. Linking multiple outputs in parallel (useful for test drivers) in a
</i>>>>><i> single process. Not really an interface issue but there are at least two
</i>>>>><i> global pointers (Config & Driver) that refer to stack variables and are
</i>>>>><i> used in various places in the code.
</i>>>>><i>
</i>>>>><i> All of this seems to indicate a departure from the linker being useable
</i>>>>><i> as a library. To maintain the previous behavior you'd have to use a linker
</i>>>>><i> binary & popen.</i></pre><span class="gmail-m_-5869550416470507579HOEnZb"><font color="#888888"><div>Pete</div></font></span></div><div><div class="gmail-m_-5869550416470507579h5"><div><div><blockquote type="cite"><div>On Dec 16, 2016, at 10:15 AM, Rui Ueyama via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="gmail-m_-5869550416470507579m_4520725906270749047Apple-interchange-newline"><div><div dir="ltr"><div>I talked several people and found that this is more like a communication issue rather than a technical/philosophical issue. I believe communication problems won't solve themselves. As a person who is on the owners file of LLD, I think I need to say something about that issue. Also, I guess people who were just watching this thread wondered why my happy pre-holiday status report suddenly turned into a heated discussion, and they are probably still wondering what's wrong with LLD. I want to address that, too.</div><div><br></div><div>So, as a project, there is no anti-library policy in LLD. I think this is the misunderstanding one side had. We already provide main-as-a-library feature so that you can embed the linker to your program. We as a project welcome other ideas to export linker features at a well-defined boundary. For example, I think abstracting the file system access so that you can hook file operations could be a well-defined, useful API for those who want to do in-memory linking (I expressed that opinion already in this thread). Just like LLVM, we won't guarantee API compatibility between releases, and we are unlikely to be able to expose deep internals of the linker, but as long as you think you found a reasonable coarse API boundary, there should be nothing preventing you from bringing that to the table.</div><div><br></div><div>On the other hand, as far as I talked, no one who is on the "library" side requested LLD expose deep internals. This is the misunderstanding the other side had. If we as a project said that LLD should not support any library interface at all, they would be upset and speak out loudly, but again, that's not a project policy.</div><div><br></div><div>So, correct me if I'm wrong, but I don't see no serious conflicts here. The conflict I saw in the thread is I believe superficial, and I strongly believe that it could have been addressed calmly and nicely if we have used more words to explain thoughts instead of small number of strong words.</div><div><br></div><div>Hope this helps.</div><div><br></div><div>Rui</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 16, 2016 at 1:40 AM, George Rimar via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>>I am on PTO, so slow to respond.<br>
><br>
>Some items that are left:<br>
><br>
>* Debug fission<br>
>* Single file debug fission<br>
>* Range extension thunks<br>
>* All of freebsd links and works<br>
>* Very good performance when all that is in<br>
<br>
</span>Looks we have initial version of debug fusion implemented.<br>
r289790, r289810 commits from yesterday did the rest of main job I believe.<br>
I do not know what is "Single file debug fission" ? (quick googling gives nothing and I never heard about that before I think)<br>
<br>
George.<br>
<div class="gmail-m_-5869550416470507579m_4520725906270749047HOEnZb"><div class="gmail-m_-5869550416470507579m_4520725906270749047h5">______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>
______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div>
</div></blockquote></div></div></div><br></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>