<div dir="ltr">Hi Tanoy,<div><br></div><div>Sorry for the slow response. I haven't thought through what would need to be done here very closely, but here are a couple of thoughts.</div><div>Somehow, the module identifier for each constituent object would need to be both unique (we currently generate this from the name of the archive plus the offset in the archive plus the name of the source file IIRC), but also correctly identify the extracted bitcode object used in the post-thinlink backend invocation. This is so it can write out the distributed index file with a filename that gets consumed by the associated backend invocation (passed to -fthinlto-index=), and so that the module paths emitted in those index files correctly identify where we can import functions from. Since the bitcode objects need to be extracted for the corresponding backend clang invocations, a couple possibilities come to mind:</div><div>1) Do it outside the compiler/linker: wrap the whole thing in a script that does the extraction, invokes the link with extracted constituents surrounded by --start-lib/-end-lib pairs, invokes each backend through some parallel or distributed mechanism, and then invokes the final link; or</div><div>2) Add support to pass some kind of mapping file into LTO that maps from each archive constituent to the extracted filename including path that the corresponding ThinLTO backend clang invocation will use, and have LTO set the module identifiers accordingly so that everything "just works" (in theory). We already support some munging of these names (see the thinlto_object_suffix_replace plugin option in either gold-plugin.cpp or in lld), but what you need here is a bit more complicated than a simple suffix change. But since there is already support for adjusting the name, it might not be too bad to add this support.</div><div><br></div><div>Hope that helps,</div><div>Teresa</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 18, 2019 at 2:27 PM Tanoy Sinha <<a href="mailto:tsinha@gmail.com">tsinha@gmail.com</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 dir="ltr">Thanks very much!<br><br>One more question:<div><br></div><div>If I wanted to implement archive support for distributed ThinLTO, what all would I need to do?</div><div><br></div><div>I know I need to pull out the bitcode module during the optimizer step, which I've looked at.<br><br>What else would I need to change?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 18, 2019 at 4:58 PM Teresa Johnson <<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</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 dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 18, 2019 at 1:40 PM Tanoy Sinha <<a href="mailto:tsinha@gmail.com" target="_blank">tsinha@gmail.com</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 dir="ltr"><div>Thanks!<br><br>Question about the final link step:</div><div><br></div><div>Do I provide all the object files to the link step, i.e. something like: <br>clang++ -o thinlto main-native.o lib/lib-native.o src/lib-native.o </div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br>Do I need to provide --start-lib markers on that final link step as well?</div></div></blockquote><div><br></div><div>No and No. After the thin link the linker has already done its symbol resolution, and using --start-lib/--end-lib in the final link can muck with that. However, the list of files the linker selected in the right order is emitted in the argument given to thinlto-index-only (thinlto.objects in your case below). You can pass that to the native link via the "@" option:</div><div>  clang++ -o thinlto @thinlto.objects</div><div>however you need to deal with the fact that this file contains the original bitcode names (not the names you gave it in your backend step like main-native.o, etc)</div><div>There are 2 options for correcting the names:</div><div>1) Manually rename in thinlto.objects</div><div>2) Use the thinlto_prefix_replace=oldprefix;newprefix plugin option, to replace the old path prefix of the input bitcode files with a new path prefix. In your case the old prefix is "", so you could do something like "-Wl,-plugin-opt,thinlto_prefix_replace=:native/". This should do 2 things: 1) the generated .thinlto.bc index files and the .imports files will be put under a "native/" subdirectory; 2) the paths in thinlto.objects should also have the "native/" prefix. If you use that prefix in your LTO backend clang invocations (e.g. -o native/main.o instead of main-native.o), then thinlto.objects can just be passed directly to the final link via "@" without any modification.</div><div><br></div><div>Note that if your thin link included any already native files/libraries, those still need to be passed as the thinlto.objects only includes those that were originally bitcode.</div><div><br></div><div>Teresa</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 dir="ltr"><div dir="ltr"><br></div><div>Tanoy</div><div dir="ltr"><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 18, 2019 at 10:37 AM Teresa Johnson <<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</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 dir="ltr"><div dir="ltr">Hi Tanoy,<div><br></div><div>You can't use distributed ThinLTO with archives (thin or not), at least not today. The reason is that we need to be able to identify specific bitcode object files to import from in the backends, and that logic does not know how to deal with objects within archives. We do distributed ThinLTO in our builds but don't use .a files, rather, we use --start-lib/--end-lib around the files that would be in the same archive when performing the thin link. I.e. if you change your thin link to be:</div><div><br></div><div>clang++ -flto=thin -o index -O3  -Wl,-plugin-opt,thinlto-index-only=thinlto.objects -Wl,-plugin-opt,thinlto-emit-imports-files main.o --start-lib lib/lib.o src/lib.o --end-lib<br></div><div><br></div><div>things should work. </div><div><br></div><div>Note you also need to do the ThinLTO backend compile for each of the archive constituents anyway, e.g. something like:</div><div>  clang++ -c -x ir lib/lib.o -O3 -flto=thin -o lib/lib-native.o -fthinlto-index=lib/lib.o.thinlto.bc<br></div><div>etc</div><div><br></div><div>HTH,</div><div>Teresa</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 17, 2019 at 2:46 PM Tanoy Sinha via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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 dir="ltr">I'm trying to run distributed ThinLTO without thin archives. <br>When I do, I get an error in the optimizer when clang tries to open a nonexistent file:<br><br>clang++ -flto=thin -Xclang -fno-lto-unit -O3 -c main.cpp -o main.o<br>clang++ -flto=thin -Xclang -fno-lto-unit -O3 -c lib/lib.cpp -o lib/lib.o<br>clang++ -flto=thin -Xclang -fno-lto-unit -O3 -c src/lib.cpp -o src/lib.o<br>llvm-ar -format gnu qcs lib.a lib/lib.o src/lib.o<br>clang++ -flto=thin -o index -O3  -Wl,-plugin-opt,thinlto-index-only=thinlto.objects -Wl,-plugin-opt,thinlto-emit-imports-files main.o lib.a<br>clang++ -c -x ir main.o -O3 -flto=thin -o main-native.o -fthinlto-index=main.o.thinlto.bc<br>Error loading imported file 'lib.a.llvm.2596.lib.cpp': No such file or directory<br><br>In this case, gold has registered the modules within my archive with ThinLTO. <br>The string "lib.a.llvm.2596.lib.cpp" is generated with the archive in question, plus an offset indicating where in the archive the particular object file is. <br>Unfortunately, when the optimizer tries to include the proper modules, <br>it's naively looking for a bitcode file with the name of the string provided, but there's obviously no "lib.a.llvm.2596.lib.cpp" for it to open.<br><br>Has anyone else tried to get clang to understand distributed ThinLTO when using non thin archives? <br>Is there some way to get clang to understand these out of the box?<br><br>I'm actually a little confused about the ".cpp" in "lib.a.llvm.2596.lib.cpp". <br>Seems like it should be a ".o"?<br><br>It didn't seem like there was anything out of the box that supported this. <br>I was looking at having clang actually read in the archive file and register the correct bitcode module. <br>I wanted to run it by the list to get some second opinions before I started that.<br></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><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-6234131711221587424gmail-m_3144820070741782407gmail-m_-8285749593618731522gmail-m_-6123948428681749062gmail_signature"><div dir="ltr"><div><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)">Teresa Johnson |</td><td nowrap style="border-top:2px solid rgb(51,105,232)"> Software Engineer |</td><td nowrap style="border-top:2px solid rgb(0,153,57)"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top:2px solid rgb(238,178,17)"><br></td></tr></tbody></table></span></div></div></div></div>
</blockquote></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-6234131711221587424gmail-m_3144820070741782407gmail_signature"><div dir="ltr"><div><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)">Teresa Johnson |</td><td nowrap style="border-top:2px solid rgb(51,105,232)"> Software Engineer |</td><td nowrap style="border-top:2px solid rgb(0,153,57)"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top:2px solid rgb(238,178,17)"><br></td></tr></tbody></table></span></div></div></div></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)">Teresa Johnson |</td><td nowrap style="border-top:2px solid rgb(51,105,232)"> Software Engineer |</td><td nowrap style="border-top:2px solid rgb(0,153,57)"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top:2px solid rgb(238,178,17)"><br></td></tr></tbody></table></span></div></div></div>