<div dir="ltr"><div>That can be controlled, see <a href="https://github.com/llvm/llvm-project/blob/a845dc1e562c20db54018a121eb01970e76602db/lld/ELF/Driver.cpp#L127">https://github.com/llvm/llvm-project/blob/a845dc1e562c20db54018a121eb01970e76602db/lld/ELF/Driver.cpp#L127</a></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 11, 2021 at 6:18 AM Jean-Daniel via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<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="overflow-wrap: break-word;"><div><br></div>One other point to consider for library usage is memory management.<div><br><div>I don’t know the state of LLD  today, but I think it was purposefully leaking memory as a tradeoff for performance at some point in the past (why deallocating everything before exiting main as the system will take care of this).</div><div><br></div><div><br></div><div>This presentation even says: </div><div><br></div><div><a href="https://archive.fosdem.org/2019/schedule/event/llvm_lld/attachments/slides/3423/export/events/attachments/llvm_lld/slides/3423/WhatMakesLLDSoFastPresenterNotes." target="_blank">What makes LLD so fast? - Previous FOSDEM Editionshttps://archive.fosdem.org › llvm_lld › slides › W…</a></div><div><br></div><div><span style="color:rgb(0,0,0)">“</span><span style="color:rgb(0,0,0);white-space:pre-wrap"> </span><span style="color:rgb(0,0,0)">• Large amounts of memory allocated up front and never released.</span><font color="#000000"><span> »</span></font></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><br><div><br><blockquote type="cite"><div>Le 11 juin 2021 à 12:56, Peter Smith via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> a écrit :</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span>One of the earliest discussions about the LLD as a library design, at least after it had matured enough to be practical was this rather long thread<span> </span><a href="https://lists.llvm.org/pipermail/llvm-dev/2016-December/107981.html" style="color:blue;text-decoration:underline" target="_blank">https://lists.llvm.org/pipermail/llvm-dev/2016-December/107981.html</a><u></u><u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span><u></u> <u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span>I don’t have any objections about making LLD more useable as a library.<u></u><u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span><u></u> <u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span>What I would say is that we should come up with a good idea of what the functionality needed from the library is. For example I can see one use case with a relatively coarse interface that is similar to running LLD from the command line, with object files passed in memory buffers. I can see that working as an extension of the existing design. A more ambitious use case would permit more fine grain control of the pipeline, or construct LLD data structures directly rather than using object files could require quite a bit more work. I think people are thinking along the lines of the former, but it is worth making sure.<u></u><u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span><u></u> <u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span>I think one of the reasons the library use case faltered was that there was no-one with a use case that was able to spend enough time to make it happen. The existing maintainers had enough work to do to catch up with Gold and BFD. Do we have someone willing to do the work?<u></u><u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span><u></u> <u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span>Peter<u></u><u></u></span></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span><u></u> <u></u></span></div><div style="border-style:none none none solid;border-left-width:1.5pt;border-left-color:blue;padding:0cm 0cm 0cm 4pt"><div><div style="border-style:solid none none;border-top-width:1pt;border-top-color:rgb(225,225,225);padding:3pt 0cm 0cm"><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><b><span lang="EN-US">From:</span></b><span lang="EN-US"><span> </span>llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" style="color:blue;text-decoration:underline" target="_blank">llvm-dev-bounces@lists.llvm.org</a>><span> </span><b>On Behalf Of<span> </span></b>James Henderson via llvm-dev<br><b>Sent:</b><span> </span>11 June 2021 08:42<br><b>To:</b><span> </span>Reid Kleckner <<a href="mailto:rnk@google.com" style="color:blue;text-decoration:underline" target="_blank">rnk@google.com</a>><br><b>Cc:</b><span> </span>llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" style="color:blue;text-decoration:underline" target="_blank">llvm-dev@lists.llvm.org</a>>;<span> </span><a href="mailto:jezng@fb.com" style="color:blue;text-decoration:underline" target="_blank">jezng@fb.com</a><br><b>Subject:</b><span> </span>Re: [llvm-dev] RFC: Revisiting LLD-as-a-library design<u></u><u></u></span></div></div></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div><div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">No objections here (although I don't have a specific use-case currently).<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">Regarding the error handling, I support some sort of callback approach to report the errors (<a href="https://www.youtube.com/watch?v=YSEY4pg1YB0" style="color:blue;text-decoration:underline" target="_blank">https://www.youtube.com/watch?v=YSEY4pg1YB0</a>). This doesn't solve the problem of what to do after a fatal error has been reported. In the debug line parsing code which inspired that talk, we had a concept of unrecoverable and recoverable errors, whereby the parser would either stop parsing if it found something it couldn't recover from, by bailing out of the function, or it would set some assumed values and continue parsing. This may work for some cases in LLD, but the fatal cases need to stop the linking completely, so we'll need some way to bail out of the LLD call stack in those cases still somehow - personally, I think we should use llvm::Error for that up to the point of public interface with the library, to avoid the failure being unchecked. The error callbacks could then return Error to allow a client to force LLD to stop, even if the error would otherwise be non-fatal.<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">James<u></u><u></u></div></div></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div><div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">On Thu, 10 Jun 2021 at 19:15, Reid Kleckner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" style="color:blue;text-decoration:underline" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></div></div><blockquote style="border-style:none none none solid;border-left-width:1pt;border-left-color:rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">Hey all,<u></u><u></u></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">Long ago, the LLD project contributors decided that they weren't going to design LLD as a library, which stands in opposition to the way that the rest of LLVM strives to be a reusable library. Part of the reasoning was that, at the time, LLD wasn't done yet, and the top priority was to finish making LLD a fast, useful, usable product. If sacrificing reusability helped LLD achieve its project goals, the contributors at the time felt that was the right tradeoff, and that carried the day.<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">However, it is now ${YEAR} 2021, and I think we ought to reconsider this design decision. LLD was a great success: it works, it is fast, it is simple, many users have adopted it, it has many ports (COFF/ELF/mingw/wasm/new MachO). Today, we have actual users who want to run the linker as a library, and they aren't satisfied with the option of launching a child process. Some users are interested in process reuse as a performance optimization, some are including the linker in the frontend. Who knows. I try not to pre-judge any of these efforts, I think we should do what we can to enable experimentation.<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">So, concretely, what could change? The main points of reusability are:<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">- Fatal errors and warnings exit the process without returning control to the caller<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">- Conflicts over global variables between threads<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">Error recovery is the big imposition here. To avoid a giant rewrite of all error handling code in LLD, I think we should *avoid* returning failure via the llvm::Error class or std::error_code. We should instead use an approach more like clang, where diagnostics are delivered to a diagnostic consumer on the side. The success of the link is determined by whether any errors were reported. Functions may return a simple success boolean in cases where higher level functions need to exit early. This has worked reasonably well for clang. The main failure mode here is that we miss an error check, and crash or report useless follow-on errors after an error that would normally have been fatal.<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">Another motivation for all of this is increasing the use of parallelism in LLD. Emitting errors in parallel from threads and then exiting the process is risky business. A new diagnostic context or consumer could make this more reliable. MLIR has this issue as well, and I believe they use this pattern. They use some kind of thread shard index to order the diagnostics, LLD could do the same.<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">Finally, we'd work to eliminate globals. I think this is mainly a small matter of programming (SMOP) and doesn't need much discussion, although the `make` template presents interesting challenges.<u></u><u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div></div><div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">Thoughts? Tomatoes? Flowers? I apologize for the lack of context links to the original discussions. It takes more time than I have to dig those up.<br><br>Reid<u></u><u></u></div></div></div><div style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" style="color:blue;text-decoration:underline" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="color:blue;text-decoration:underline" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></div></blockquote></div></div></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">LLVM Developers mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="mailto:llvm-dev@lists.llvm.org" style="color:blue;text-decoration:underline;font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">llvm-dev@lists.llvm.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="color:blue;text-decoration:underline;font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div></blockquote></div><br></div></div></div>_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>