<div dir="ltr"><div><div><div>Hi,<br></div><div><br></div><div>My colleagues and I have actually been doing quite a bit of investigation in the past couple of weeks into what to do about debug data that refers to sections that are discarded due to --gc-sections etc. Currently, LLD treats the references as address zero, but at least on our platform, address zero is a valid address, so we were looking at alternatives. One of the ideas that I personally looked at was based on section E.3 of the DWARF4/5 specifications, i.e. having a separate .debug_info section for each subprogram, each of which imports from a "main" .debug_info section containing shared information. I was able to prototype a change to LLVM that did this, without too much effort, given that I hadn't previously looked in that area of code before. I then had to modify LLD to recognise these new info sections as being dependent on the corresponding text section, which was a relatively simple change to make, thanks to the mechanism for dependent sections already being there. It didn't require inspecting the contents of the section, only the section name in my case (the sections in my experiment were named things like .debug_info._Z3foov). I also prototyped changes to llvm-dwarfdump to print the .debug_info for these multiple sections. Again, this was relatively simple, although I certainly didn't experiment beyond a very simply case. Similar investigations are being conducted for having multiple of other .debug_* sections.</div><div><br></div>We haven't yet decided whether this is an approach we'd like to push for, as there are some downsides (e.g. larger debug information) but my point is that I wouldn't be so certain that we won't need to handle multiple .debug_info sections correctly in the relatively near term, so I'd much rather option 2).<br><br></div>Regards,<br><br></div>James<br><div><div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On 8 December 2017 at 08:49, George Rimar via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><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="color:rgb(33,33,33);font-size:12pt">Thanks for commens, David ! Let me answer from the end.</span></p><span class="gmail-">
<p><span style="color:rgb(33,33,33);font-size:12pt"><br>
</span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">>It seems strange to me that the linker would special
 case the debug_* sections </span></span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">>(& that that special casing would limit how they can
 be used) given the discussion we were </span></span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">>having about the linker wanting to treat debug info as
 just normal sections.</span><br>
</span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><br>
</span></span></p>
</span><p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">There are two different things about handing such sections in
 linker.</span></span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">We are talking about multiple .debug_info*, where there
 is some main .debug_info and</span></span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">multiple COMDAT .debug_info* section with types.</span></span></p>
<p><span style="color:rgb(33,33,33)">Linker </span><span style="color:rgb(33,33,33)">do deduplication of COMDATs
</span><span style="color:rgb(33,33,33)">and </span><span style="color:rgb(33,33,33)">does</span><span style="color:rgb(33,33,33)"> </span><span style="color:rgb(33,33,33)">not care about section names, flags etc,</span><br>
</p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">so it handles debug_* sections just as normal sections
 and that is already works as expected.</span></span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><br>
</span></span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">Issue my patch trying to address is a different case and comes
 from llvm::DWARFObject class. We use it when</span></span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">LLD do error reporting </span></span><span style="color:rgb(33,33,33)">(to
 get information about source lines) and for --gdb-index. In both cases it relies on current</span></p>
<p><span style="color:rgb(33,33,33)">DWARFObject API </span><span style="color:rgb(33,33,33)">that among other things assumes that th</span><span style="color:rgb(33,33,33)">ere are single .debug_info, .debug_abbrev and .debug_line.</span></p>
<p><span style="color:rgb(33,33,33)">(<a href="https://github.com/llvm-mirror/llvm/blob/master/include/llvm/DebugInfo/DWARF/DWARFObject.h#L36" target="_blank">https://github.com/llvm-<wbr>mirror/llvm/blob/master/<wbr>include/llvm/DebugInfo/DWARF/<wbr>DWARFObject.h#L36</a>)</span></p>
<p><span style="color:rgb(33,33,33)"><br>
</span></p>
<p>What I really wanted to do in this patch is to error out when this class is used in case multiple of above sections are present. Because<br>
</p>
<p>with current implementation result would be just a mess, we would use the last debug section with a given name only and result would be<br>
</p>
<p>undefined.<br>
</p>
<p>My approach was not entirelly correct, as you mentioned it would not work in case of multiple .debug_types. Honestly I forgot<br>
</p>
<p>about them when tried to sim<span style="font-size:12pt">plify code</span><span style="font-size:12pt">, we do not use this sections there and had no test to fail, I`ll add it.</span></p><span class="gmail-">
<p><br>
</p>
<p><span style="color:rgb(33,33,33);font-size:12pt">>What's the error handling case you mention? </span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><br>
</span></p>
</span><p><font color="#212121">One of use cases I mentioned above (for reference our code is <a href="https://github.com/llvm-mirror/lld/blob/master/ELF/InputFiles.cpp#L73" target="_blank">https://github.com/llvm-<wbr>mirror/lld/blob/master/ELF/<wbr>InputFiles.cpp#L73</a>​),</font></p>
<p><font color="#212121">in short we use .debug_line​ for reporting error locations and scan ​.debug_info for variables to report them for reporting duplicate </font></p>
<p><font color="#212121">declarations.</font></p><span class="gmail-">
<p><font color="#212121">​</font></p>
<p><span style="color:rgb(33,33,33);font-size:12pt">>Presumably it works for multiple debug_types sections, so perhaps that support could be generalized to multiple</span></p>
<p><span style="color:rgb(33,33,33);font-size:12pt">>debug_info sections as well? Then this failure could be restricted to only multiple debug_info sections when using gdb-index?</span><br>
</p>
</span><div style="color:rgb(33,33,33)">
<div><span class="gmail-">
<div dir="ltr">></div>
<div dir="ltr">>That way DWARF5 type units (that use debug_info sections) would just work? (except when using gdb-index)<br>
<br>
</div>
</span><div dir="ltr">I do not see way it could be restricted to only --gdb-index case. We discussed multiple .debug_info case only I think,<br>
</div>
<div dir="ltr">but looks important point that DWARF5 spec at p366<span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"> (</span><a href="http://dwarfstd.org/doc/DWARF5.pdf" class="gmail-m_-673758841713917131remarkup-link" rel="noreferrer" style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;text-decoration-line:none;color:rgb(19,108,178)" target="_blank">http://dwarfstd.org/doc/<wbr>DWARF5.pdf</a><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">)
 also mentions it can be multiple of <span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">.debug_abrev, </span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">.debug_info,
 .debug_line</span><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> sections. </span></span>We use
 them for error reporting as well. (not we, but llvm::DWARFObject<span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"> we re</span><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">l</span><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">y
 on </span><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">actually).</span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
</span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">Given all above
 I see 2 solutions.</span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"></span>1)
<span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">
As far I can tell there is no producers of multiple .debug_info/.debug_abbrev/.<wbr>debug_line yet. And at least basing on our</span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">discussions
 looks we do not plan to support it in closest future (and it is actually unclear we will).</span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">That
 is why I prepared patch using less intrusive approach to restrict multiple debug sections. What can I do for it</span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">is
 to fix/update it so it will just black list </span></span></span>sections we do not expect to be not unique.</div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><br>
</span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">2)
 We could teach <span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">llvm::DWARFObject</span> to handle multiple <span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"> .debug_info/.debug_<wbr>abbrev/.debug_line</span>.
 That would be helpful</span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">for
 tools like llvm-dwarfdump (in case they be used for some wild object with such sections) and would allow LLD to work with such objects. </span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">Given
 our discussion I am not sure it is useful/worth to do, </span></span></span>but I will be happy to try to implement it if such way be chosen.</div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><br>
</span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">What
 do you guys think, what should we do ?</span></span></span></div><span class="gmail-HOEnZb"><font color="#888888">
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><br>
</span></span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">George.</span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
</span></span></div>
<div dir="ltr"><span style="font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(33,33,33);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
</span></span></div>
</font></span></div>
</div>
</div>

<br>______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div></div></div></div></div></div></div>