<div dir="ltr"><div>Broad question: Do you have any specific motivation/users/etc in implementing this (if you can speak about it)? - it might help motivate the work, understand what tradeoffs might be suitable for you/your users, etc.<br><br>In general, in the current state, I don't have strong feelings either way about this going in as-is with the intent to improve it to make it more viable - or some of that work being done out-of-tree until it's a more viable performance tradeoff. Mostly happy to leave that up to folks more involved with lld.<br><br>A couple of minor points...</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 8, 2020 at 6:18 AM Alexey Lapshin 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 dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Folks, we work on optimization of binary size and improvement of debug info quality.<br>
To reduce the size of the binary we use -ffunction-sections so that unused code would be garbage collected.
<br>
When the linker does garbage collection, a lot of abandoned debug info is left behind.
<br>
Besides inflated debug info size, we ended up with overlapping address ranges and no way to say valid vs garbage ranges(D59553).
<br>
To resolve these two problems, we use implementation extracted from dsymutil <a href="https://reviews.llvm.org/D74169" target="_blank">https://reviews.llvm.org/D74169</a>.<br>
It adds --gc-debuginfo command line option to the linker to remove obsolete debug info.<br>
Currently, it has the following limitations: does not support DWARF5, modules, -fdebug-types-section, type units, .debug_types,</p></div></blockquote><div><br>These last 3 ^ are all the same thing, FWIW. (well, in DWARFv5 they go in debug_info, but it's the same feature)<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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif"><p> multiple .debug_info sections, split DWARF, thin lto.<br>
<br>
Following are size/performance results for the D74169:<br>
<br>
<span style="font-family:"Courier New",monospace">A: --function-sections --gc-sections</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">B: --function-sections --gc-sections --gc-debuginfo</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">C: --function-sections --gc-sections --fdebug-types-section</span></p></div></blockquote><div> ^ not sure of the point of testing/showing comparisons with a situation that's currently unsupported</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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif"><p>
<span style="font-family:"Courier New",monospace">D: --function-sections --gc-sections --gsplit-dwarf</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">E: --function-sections --gc-sections --gc-debuginfo --compress-debug-sections=zlib</span><br style="font-family:"Courier New",monospace">
<br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">LLVM code base:</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">| Options |    build time   |    bin size   |    lib size    |
</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    A    |    54min(100%)  |   19.0G(100%) |  15.0G(100.0%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    B    |    65min(120%)  |    9.7G( 51%) |  12.0G( 80.0%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    C    |    53min( 98%)  |   12.0G( 63%) |  15.0G(100.0%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    D    |    52min( 96%)  |   12.0G( 63%) |   8.2G( 55.0%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    E    |    64min(118%)  |    5.3G( 28%) |  12.0G( 80.0%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<br style="font-family:"Courier New",monospace">
<br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">Clang binary:</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">-------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">| Options |      size      |     link time  |  used memory  |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">-------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    A    |    1.50G(100%) |    9sec(100%)  |  9307MB(100%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">-------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    B    |    0.76G( 50%) |   68sec(755%)  | 15055MB(161%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">-------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    C    |    0.82G( 54%) |    8sec( 89%)  |  8402MB( 90%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">-------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    D    |    0.96G( 64%) |    6sec( 67%)  |  4273MB( 46%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">-------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    E    |    0.43G( 29%) |   77sec(855%)  | 15000MB(161%) |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">-------------------------------------------------------------</span><br style="font-family:"Courier New",monospace">
<br style="font-family:"Courier New",monospace">
<br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">lldb loading time:</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">| Options |      time     |   used memory  |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    A    |  6.4sec(100%) |  1495MB(100%)  |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    B    |  4.0sec( 63%) |   826MB( 55%)  |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    C    |  3.7sec( 58%) |   877MB( 59%)  |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    D    |  4.3sec( 67%) |  1023MB( 69%)  |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">|    E    |  2.1sec( 33%) |   478MB( 32%)  |</span><br style="font-family:"Courier New",monospace">
<span style="font-family:"Courier New",monospace">--------------------------------------------</span><br>
<br>
I want to discuss the results and to decide whether it is worth to integrate of D74169:<br>
<br>
improvements:<br>
<br>
1. Reduces the size of debug info(50%).<br>
2. Resolves overlapping of address ranges(D59553).<br>
3. Reduced size of debug info allows tools to work faster and to require less memory.<br>
<br>
drawbacks and not implemented features:<br>
<br>
1. linking time is increased(755%).<br>
<br>
  The --gc-debuginfo option is off by default. So it would affect only those who need it and explicitly specified it.<br>
<br>
  I think the current DWARFLinker code could be optimized more to improve performance results.<br>
<br>
2. Support of type units.<br>
<br>
  That could be implemented further.<br></p></div></blockquote><div>Enabling type units increases object size to make it easier to deduplicate at link time by a DWARF-unaware linker. With a DWARF aware linker it'd be generally desirable not to have to add that object size overhead to get the linking improvements. </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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif"><p>
<br>
3. DWARF5. <br>
<br>
   Current DWARFEmitter/DWARFStreamer has an implementation for DWARF generation, which does not support
<br>
DWARF5(only debug_names table). At the same time, there already exists code in CodeGen/AsmPrinter/DwarfDebug.h,
<br>
which implements most of DWARF5. It seems that DWARFEmitter/DWARFStreamer should be rewritten using
<br>
DwarfDebug/DwarfFile. Though I am not sure whether it would be easy to re-use DwarfDebug/DwarfFile.
<br>
It would probably be necessary to separate some intermediate level of DwarfDebug/DwarfFile.<br>
<br>
4. split DWARF support.<br>
<br>
   This solution does not work with split DWARF currently. But it could be useful for the split dwarf in two ways:<br>
<br>
   a) The generation of skeleton file could be changed in such a way that address ranges pointing to garbage
<br>
collected code would be replaced with lowpc=0, highpc=0. That would solve the problem of overlapping address
<br>
ranges(D59553). <br></p></div></blockquote><div>This wouldn't/couldn't completely address the issue - because some address ranges would be in the .dwo files the linker can't see - and they'd still end up with the interesting address ranges.<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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif"><p>
<br>
   b) The approach similar to dsymutil implementation could be used to generate monolithic debuginfo created
<br>
from .dwo files. That suggestion is from - <a href="https://reviews.llvm.org/D74169#1888386" target="_blank">https://reviews.llvm.org/D74169#1888386</a>.<br>
      i.e., DWARFLinker could be taught to generate the same output as D74169 but for split DWARF as the source.<br>
<br>
5. -fmodules-debuginfo<br>
<br>
   That problem was described in this review - <a href="https://reviews.llvm.org/D54747#1505462" target="_blank">https://reviews.llvm.org/D54747#1505462</a> . Currently, DWARFLinker/dsymutil has the same problem. It could be solved using the fact that DWARFLinker analyzes debuginfo. It could recognize debug info generated for
 the module and keep it(compile units containing debug info for modules do not have low_pc, high_pc).<br>
<br>
6. -flto=thin<br>
<br>
   That problem was described in this review <a href="https://reviews.llvm.org/D54747#1503720" target="_blank">https://reviews.llvm.org/D54747#1503720</a>. It also exists in current DWARFLinker/dsymutil implementation. I think that problem should be discussed more: it could probably be fixed by avoiding generation of such incomplete
 declaration during thinlto, </p></div></blockquote><div>That would be costly to produce extra/redundant debug info in ThinLTO - actually ThinLTO could be doing more to reduce that redundancy early on (actually removing definitions from some llvm Modules if the type definition is known to exist in another Module, etc)<br><br>I don't know if it's a problem since that patch was reverted.</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" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif"><p>or, alternatively, DWARFLinker could recognize such situation and copy missed type declaration.<br>
<br>
=======================================================================================<br>
<br>
Debuginfo, Linker folks, What do you think about current results and future directions?</p>
<p><br>
It introduces quite a significant linking time increase(6x-8x). But it would affect only those who use that feature.</p>
<p>Thus the users will be able to decide whether that linking time increase is acceptable or not.<br>
Resolving all 1-6 points is quite a significant work. But, in the result, debug info is more correct and compact.<br>
<br>
Do you think that it would be good to integrate it and to start to work on improving?<br>
<br>
</p>
<p class="MsoNormal"><font size="1"><span style="font-size:11pt;font-family:"Trebuchet MS",sans-serif;color:black">Thank you, Alexey.<br>
</span></font></p>
<div id="gmail-m_9019961954974587019Signature">
<div name="divtagdefaultwrapper">
<table cellpadding="0" border="0">
<tbody>
<tr>
<td style="padding:0.75pt" valign="top"><br>
</td>
<td style="padding:0.75pt"><br>
</td>
</tr>
</tbody>
</table>
<br>
<font size="2"><span style="font-size:11pt;font-family:"Trebuchet MS",sans-serif;color:black"></span></font></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>