<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 31, 2018 at 9:58 AM A. Ilchinger 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-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">It is quite common for larger project to split the source tree into<br>
multiple libraries, which are built statically and linked together at<br>
the end. This practise also has advantages building tests, because only<br>
the library for the classes under test has to be linked.<br>
<br>
When it comes to LTO, I understand that it works when multiple .o files<br>
are linked together, doing its magic hopefully optimizing the resulting<br>
binary, be it a library or an executable. This is great for optimizing<br>
the different parts of a larger project individually. I don't know if<br>
there is an official term for that, but I'd call it intra-module LTO,<br></blockquote><div><br></div><div>A "Module" is a single .o in LLVM (usually). So LTO is always about cross-module optimizations.</div><div><br></div><div>The closer to use to describe the scope of optimization is probably a DSO (Dynamic Shared Object): i.e. a shared library (.so) or the final binary.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
where module basically means a binary target, be it the only one or<br>
just an intermediate.<br>
<br>
I'd like to know if LTO also works in the second step, when multiple .a<br>
libraries and potentially other .o files are linked together to the<br>
final binary. So can LTO also work successfully between modules (being<br>
inter-module).<br></blockquote><div><br></div><div>.a are really just an archive containing multiple .o, after the linker decide to pull some .o files out of a .a archive (there are some rule around this), there is no difference with .o directly passed on the command line as far as I know.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
And if it is possible, do I have to pay attention to some compiler<br>
flags, linker options, etc., or does it work out-of-the-bos with -flto?<br>
<br></blockquote><div><br></div><div>So LTO work just as fine with .a, with one caveat: the tool used to create the .a has to be compatible with LLVM bitcode (i.e. use llvm-ar instead of ar to create the archive) otherwise the .a creation may fail or the link step may fail.</div><div><br></div><div>Best,</div><div><br></div><div>-- </div><div>Mehdi </div></div></div></div></div></div>