<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:SimSun;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="ZH-CN" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi Teresa,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The third way you suggested has solved my problem perfectly! `-plugin-opt emit-llvm` assigns PostInternalizeModuleHook a lambda which always returns false so that `if (Conf.PostInternalizeModuleHook && !Conf.PostInternalizeModuleHook(0,
 *RegularLTO.CombinedModule))` is met now and runRegularLTO() returns without executing backend(), though it creates an output file(defaults to be a.out), it doesn’t really matter. For the first suggestion, I need some time to figure out what a “valid target
 machine” requires here and what I missed. Your help is really appreciated!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Mindong<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Teresa Johnson [mailto:tejohnson@google.com]
<br>
<b>Sent:</b> Saturday, November 30, 2019 5:51 AM<br>
<b>To:</b> chenmindong <chenmindong1@huawei.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org; Yuchao (Michael) <michael.yuchao@huawei.com><br>
<b>Subject:</b> Re: [llvm-dev] ThinLTO Problem<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal"><span lang="EN-US">On Wed, Nov 27, 2019 at 10:36 PM chenmindong <<a href="mailto:chenmindong1@huawei.com" target="_blank">chenmindong1@huawei.com</a>> wrote:<o:p></o:p></span></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">Hi Teresa,<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">Thanks for the detailed reply!<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">> How are you creating your bitcode files?<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">I create the bitcode with `-flto=thin -c` and sure it has a GLOBALVAL_SUMMARY_BLOCK. And there</span>’<span lang="EN-US">s no RegularLTO partition only ThinLTO
 bicode.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">> Where is it aborting in the backend?<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">It aborts at ` report_fatal_error("Failed to setup codegen")` in of codegen() of LTOBackend.cpp. And before that in createTargetMachine() it also warns
</span>‘<span lang="EN-US">xxx is not a recognized processor</span>’<span lang="EN-US">. But the program should return before run into backend() IIUC since all I want is using lld with `-thinlto-index-only` option to generate *.thinlto.bc and feed it and bitocde
 to clang to invoke target-specific optimizations(we use gnu as and ld).Do you have any suggestion about this?<o:p></o:p></span></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">Ah, ok, that's helpful. So the report_fatal_error is almost certainly just a consequence of the earlier failure in createTargetMachine. And the issue is that it will try to code through the codegen path for regular LTO
 even if CombinedModule is empty, which it presumably is in your case. Even when LTO linking with -thinlto-index-only need to go through this path in case there are some regularLTO modules. And you must not be setting up any valid target machine, so it is complaining.
 Here's a few possible fixes/workarounds:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">1) Can you pass a valid target machine that LLVM understands, even if you are using another tool downstream to compile for a specialized target?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">2) If you are using LTO via the gold plugin (e.g. either gold or gnu), then you can pass the disable-output plugin option (i.e. -Wl,-plugin-opt,disable-output) to get it the regular LTO path to exit before codegen, without
 emitting anything for the (presumably empty) regular LTO object. Unfortunately, it does not look like lld supports this feature, although it would be straightforward to add. What linker are you using for the LTO link?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">3) Supported by both the gold plugin (used by gold and gnu LTO), as well as lld, you can exit just slightly later using the following option, which will emit the regular LTO bitcode to the specified output file (which
 again would presumably be an "empty" module in your case) and exit, just before codegen: -Wl,-plugin-opt,emit-llvm<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US">Teresa<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">Regards,<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">Mindong<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US" style="font-size:10.5pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><span lang="EN-US"><o:p></o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Teresa
 Johnson [mailto:</span><span lang="EN-US"><a href="mailto:tejohnson@google.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">tejohnson@google.com</span></a></span><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">]
<br>
<b>Sent:</b> Wednesday, November 27, 2019 11:12 PM<br>
<b>To:</b> chenmindong <</span><span lang="EN-US"><a href="mailto:chenmindong1@huawei.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">chenmindong1@huawei.com</span></a></span><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">><br>
<b>Cc:</b> </span><span lang="EN-US"><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">llvm-dev@lists.llvm.org</span></a></span><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">;
 Yuchao (Michael) <</span><span lang="EN-US"><a href="mailto:michael.yuchao@huawei.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">michael.yuchao@huawei.com</span></a></span><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">><br>
<b>Subject:</b> Re: [llvm-dev] ThinLTO Problem</span><span lang="EN-US"><o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">Hi Mindong,<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">On Wed, Nov 27, 2019 at 3:29 AM chenmindong via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></span></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">Hi,<br>
<br>
I'm working on enabling thinLTO for our custom backend on LLVM-8 with lld to get code size benefits from dead symbol elimination. The code in LTO::run() of LTO.cpp confuses me that, even though thinLTO is specified, runRegularLTO() will be run first and its
 return value determines whether runThinLTO() will be executed. <br>
<br>
My question is if it's clearly known that thinLTO is used, is it still necessary to execute runRegularLTO()?If it is, what's the reason behind?<o:p></o:p></span></p>
</blockquote>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">This is to handle the case where the LTO link is given a mix of regular and thin LTO bitcode - it should do regular LTO on that subset and ThinLTO on the other.
 The other case this handles is when a bitcode object is split into regular and thin LTO halves - this is enabled for things like CFI but shouldn't be the default currently (you'd have to build with -fsplit-lto-unit to get it unless you are building with CFI).<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">Whether the bitcode is added to the regular or Thin LTO partition is determined in LTO::addModule, and is based on a flag set when the bitcode is read which is
 based in turn on whether the bitcode has a summary block, and whether that is a thinlto or regular (full) LTO summary block. How are you creating your bitcode files? If you run llvm-dis on it does it have summary entries? You can also see if you run llvm-bcanalyzer
 whether it has a GLOBALVAL_SUMMARY_BLOCK or a FULL_LTO_GLOBALVAL_SUMMARY_BLOCK or neither. If you are compiling with -flto=thin you should realistically have the former, which would make it a ThinLTO bitcode. But it sounds like you have some objects that either
 don't or have the full LTO summary.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">For now our custom backend, where distributed thinLTO is adopted, it works fine as I removed the line executing runRegularLTO(). But if I preserve it, the code
 fails the `if (Conf.PostInternalizeModuleHook &&!Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule))`, which I also don't understand, and fall through to backend() and abort there. I believe something is missed during adding the target support but
 cannot figure it out. Could anyone help?<o:p></o:p></span></p>
</blockquote>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">By default there should not be a PostInternalizeModuleHook set (it is set to support cases like -save-temps), so it isn't surprising that it would fail that test
 and fall through to the backend() call, which is what you would want if there was a regular LTO partition. Where is it aborting in the backend?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">Teresa<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"><br>
Regards,<br>
Mindong Chen<br>
_______________________________________________<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" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></span></p>
</blockquote>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"><br clear="all">
<o:p></o:p></span></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US">--
<o:p></o:p></span></p>
<div>
<div>
<div>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td nowrap="" style="border:none;border-top:solid #D50F25 1.5pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US" style="font-family:"Arial",sans-serif;color:#555555">Teresa Johnson |</span><span lang="EN-US"><o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #3369E8 1.5pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US" style="font-family:"Arial",sans-serif;color:#555555"> Software Engineer |</span><span lang="EN-US"><o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #009939 1.5pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US" style="font-family:"Arial",sans-serif;color:#555555"> </span><span lang="EN-US"><a href="mailto:tejohnson@google.com" target="_blank"><span style="font-family:"Arial",sans-serif">tejohnson@google.com</span></a></span><span lang="EN-US" style="font-family:"Arial",sans-serif;color:#555555"> |</span><span lang="EN-US"><o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #EEB211 1.5pt;padding:0cm 0cm 0cm 0cm">
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span lang="EN-US"> <o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><span lang="EN-US"><br clear="all">
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-US">-- <o:p></o:p></span></p>
<div>
<div>
<div>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td nowrap="" style="border:none;border-top:solid #D50F25 1.5pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Arial",sans-serif;color:#555555">Teresa Johnson |<o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #3369E8 1.5pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Arial",sans-serif;color:#555555"> Software Engineer |<o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #009939 1.5pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Arial",sans-serif;color:#555555"> </span><span lang="EN-US"><a href="mailto:tejohnson@google.com" target="_blank"><span style="font-family:"Arial",sans-serif">tejohnson@google.com</span></a></span><span lang="EN-US" style="font-family:"Arial",sans-serif;color:#555555"> |<o:p></o:p></span></p>
</td>
<td nowrap="" style="border:none;border-top:solid #EEB211 1.5pt;padding:0cm 0cm 0cm 0cm">
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>