<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, May 4, 2017 at 11:23 AM Robinson, Paul <<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_-2846666061568291363WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Sorry, trying to catch up a bit late…<u></u><u></u></span></p></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">It sounds like having more than one CU per .dwo is outside of the intention of the DWARF specification (though not explicitly forbidden), since
 there is an implied 1-1 relationship between skeleton CU and .dwo.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
</div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1"><p class="MsoNormal"><a name="m_-2846666061568291363__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">There is an explicit 1-1 relationship between skeleton CU and split-full CU (not .dwo).  This suggests to me that if you want a .dwo
 to have multiple CUs, then the .o should have multiple corresponding skeleton CUs.</span></a></p></div></div></blockquote><div><br>Right - that's closest to/as things are today, for sure.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1"><p class="MsoNormal"><a name="m_-2846666061568291363__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">  Each skeleton/split-full pair would have the same dwo_name but different dwo_IDs.  You're making it sound like LTO is actually producing only one skeleton CU?  That would be
 a bug.</span></a></p></div></div></blockquote><div><br>It isn't at the moment - at the moment it produces a skeleton per CU, a single DWO file with multiple CUs, and all this (with a relatively small patch to GDB) works in GDB today so long as there aren't any cross-cu references and so long as it's DWO files and not a DWP file.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1"><p class="MsoNormal"><a name="m_-2846666061568291363__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></a></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> </span><span style="color:rgb(31,73,125);font-family:Calibri,sans-serif;font-size:11pt">I am not finding anywhere that explicitly says a .dwo file can have only one unit?  Although it does seem that the definition of the cu_index assumes each unit
 should be treated as being in an independent .debug_info section, which is a problem for making cross-CU references in a given .dwo file.  Thanks for bringing that up on dwarf-discuss already.</span></p></div></div></blockquote><div><br>Right - I'm not sure if binutils DWP was implemented with this in mind, or if it fell out naturally from the debug_types support (walk the info/types section for each unit, keep it if it's not already present in the output - so it would naturally want to trim the info/types contribution to that specific unit since other units may not be included in the output). My llvm-dwp failed this - and brings in the first CU, but I think it takes the whole unit CU contribution, maybe... - so that's a bit broken in any case here.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">So this leads us to a few options - the 'simplest', that changes the semantics but not the syntax of the table - would be to widen the INFO range
 to cover the whole portion that came from the original DWO file.<br>
<br>
Consumers would have to be adjusted to cope with the fact that the INFO contribution for a given DWO ID would be a range that contains the CU somewhere, along with other CUs - and they'd have to search (in full LTO, this would mean searching through /all/ the
 CUs).</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
</div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">But each skeleton/split-full pair needs a distinct DWO ID (per the v5 spec).</span></p></div></div></blockquote><div><br>Each skeleton/split-full pair would still have a distinct DWO ID (each CU still has a separate hash) from what I was describing above/in the section you quoted. But the debug_info contribution in the cu_index would be 'vague' - it would be widened to describe the whole info contribution from that DWO file.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">  I guess we could address this by replicating the index entry for each DWO ID in
 the .dwo file, so lookup-by-ID would still work, but the INFO ranges would always describe the full .debug_info section from the .dwo file. </span></p></div></div></blockquote><div><br>Right, that ^ so, yeah "replicated" in the sense that for each DWO ID in the same DWO file, they'd have a separate entry in the cu_index with each unique DWO ID - but the contributions would be the same for every one of those DWO IDs from the same DWO file.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> You'd still need to search the .dwo file's part of the INFO range to find the actual CU, unless we change the syntax
 of the table to provide those offsets.  But then ref_addr would work across CUs from the same .dwo file.</span></p></div></div></blockquote><div><br>Precisely.<br><br>In the worst case, with full LTO - that'd be potentially a lot of searching across because it'd be a single DWO file with all the CUs.<br><br>hopefully we can talk about this more on the dwarf-discuss list (I haven't seen any replies there, maybe I should just subscribe to the dwarf committee list & discuss it there? I dunno - open to suggestions)<br><br>- Dave<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">--paulr<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>David Blaikie via llvm-dev<br>
<b>Sent:</b> Wednesday, May 03, 2017 7:52 PM<br>
<b>To:</b> Adrian Prantl<br>
<b>Cc:</b> llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] DWARF Fission + ThinLTO<u></u><u></u></span></p>
</div>
</div></div></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-2846666061568291363WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, May 3, 2017 at 7:48 PM Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On May 3, 2017, at 7:43 PM, Adrian Prantl via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
On May 3, 2017, at 2:59 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">On Wed, May 3, 2017 at 2:09 PM Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>> wrote:<u></u><u></u></span></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
> On May 3, 2017, at 2:00 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
><br>
> So Dehao and I have been dealing with some of the nitty gritty details of debug info with ThinLTO, specifically with Fission(Split DWARF).<br>
><br>
> This applies to LTO as well, so I won't single out ThinLTO here.<br>
><br>
> 1) Multiple CUs in a .dwo file<br>
> Clang/LLVM produces a CU for each original source file - these CUs are kept through IR linking (thin or full) and produced as distinct CUs in the resulting DWARF.<br>
> This preserves semantics as much as possible - eg: file-local functions and types (those in anonymous namespaces or declared file-static) con co-exist even if their names collide.<br>
> GDB does good things with this, except with Fission.<br>
<br>
Can you lay out the terminology you are using here? Is Fission as used here different/more than creating .dwo files?<u></u><u></u></span></p>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
Fission as used in that sentence means .dwo files and anything beyond (.dwp files - <a href="https://gcc.gnu.org/wiki/DebugFissionDWP" target="_blank">https://gcc.gnu.org/wiki/DebugFissionDWP</a> ). GDB warns/errors/complains if two CUs are in a single .dwo,
 and ignores all but the first.<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">It sounds like having more than one CU per .dwo is outside of the intention of the DWARF specification (though not explicitly forbidden), since there is an implied 1-1 relationship
 between skeleton CU and .dwo.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">What do you think is the *right* solution here: <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">- Allowing more than one CU in gdb?<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">- Emitting many little .dwo files for the cross-inlined functions' CUs?<u></u><u></u></span></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Hmm.. I guess that would make the cross-CU references impossible. (Unless we can refer to everything via signatures).<u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><br>
Precisely!<br>
<br>
It'd be pretty tricky to do by signature - /maybe/ possible. But these are internal symbols - so they're not very uniqueable - in terms of mangled name, etc to hash.<br>
<br>
and I hadn't mentioned one other wrinkle:<br>
<br>
The CU fragments that result from selectively importing functions in ThinLTO are going to be a problem - if two ThinLTO shards both import the same chunks from a third module - they'll potentially produce two CUs with the same DWO ID hash. So I was thinking
 there might be some need to cross-polinate the hashes of the various CUs in ThinLTO, to create 'more unique' identifiers... but I don't know exactly how it'd all look there.<br>
 <u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><br>
<br>
<u></u><u></u></p>
</div>
</div>
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
<u></u><u></u></span></p>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
> Binutils DWP produces usable DWPs from DWO files with multiple CUs<br>
><br>
> 2) Cross-CU references<br>
> This is where it gets trickier.<br>
> LLVM produces cross-CU references (DW_FORM_ref_addr) to refer to types or functions defined in one CU used from another. This only happens with (thin or plain) LTO. LLVM's had this for a while.<br>
> This helps fully express interesting cases outlined in (1) - it's possible that a file-local function is inlined into another CU - by using ref_addr the semantics described in (1) can be preserved, while also explaining the inlining that has occurred. (similar
 cases can arise with intra-CU type references too)<br>
> GDB handles this, except with Fission (I mean, it doesn't get this far - but even with patches to handle (1)+Fission, it's still not enough - needs more work)<br>
> Binutils DWP and the DWP format in general... maybe can't cope with this.<br>
><br>
> Talking about (2)+DWP:<br>
<br>
You mean (2)+DWO+DWP?<u></u><u></u></span></p>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
DWP is a package containing the contents of multiple DWOs - so, yes and no? Not sure how to answer.<br>
<br>
(2)+DWO could be made to work without changing much in the contents/format/etc, I think - consumers could be made to understand the 'obvious' form (no change to producers I think would be needed).<br>
<br>
But once you go to a DWP file, then there are repreesntational problems that make it currently impossible to use cross-CU references. The semantics (& possibly the syntax) of DWP files would have to change to enable this functionality.<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Why can a .dwo cope with cross-CU-references but not a .dwp?<br>
<br>
<u></u><u></u></span></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> <u></u><u></u></span></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
> It looks like this may require adjusting at least the semantics, if not the syntax of the indexes in the DWP file. I've started a thread on dwarf-discuss to start trying to hash that out.<br>
><br>
><br>
><br>
> So, to cut a long story short: Fission+LTO is currently unusable and may take a while to make the DWARF side of this usable.<br>
><br>
> In the interim, I'd like to propose adding a flag to LLVM to support something not very nice: When merging modules (or importing things into a module in ThinLTO), do not maintain separate CUs but redirect the cu pointer in any DISubprogram (& probably DIGlobalVariable
 too - I forget if ThinLTO can import them) metadata to refer to the original CU in the destination module. (in the full LTO case, it'd also be necessary to import any retained types)<br>
><br>
> This flag could be passed to the task doing the merging/importing, or could be passed to the frontend compile and stashed in per-CU metadata (where it would be respected when importing/merging from that CU).<br>
><br>
> The intent would be to support this flag until the DWARF functionality can be decided on and implemented - and kept for some time after that for backwards compatibility for those who want to use Fission but haven't got the latest toolchains with the fixes/improvements
 in them.<br>
><u></u><u></u></span></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">If the other tools cannot be fixed quickly, then this would be a pragmatic interim solution.<u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
<u></u><u></u></span></p>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">><br>
><br>
> How's this sound to everyone? Reasonable? Unreasonable? Need more details about the impact of these changes, etc? (I have examples with DWARF output, GDB behavior, etc)<br>
<br>
If you can post an example, that would help.<u></u><u></u></span></p>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
OK, so, here's an example of how GDB, without fission, benefits from the two distinct CUs (rather than bundling all the types & functions into a single CU):<br>
<br>
given:<br>
</span><span style="font-size:9.0pt;font-family:"Courier New"">  a.cpp:</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    namespace {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    struct foo {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      int i;</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    };</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    static void f1() {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    void f2() {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      f1();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }<br>
  b.cpp:</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    namespace {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    struct foo {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      float f;</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    };</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    static void f1() {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    void f2();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    int main() {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      f1();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      f2();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }<br>
  $ clang++ {a,b}.cpp -g -c -emit-llvm -S<br>
  $ llvm-link {a,b}.ll -S -o ab.ll</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  $ clang++-tot ab.ll<br>
  $ gdb a.out<br>
  (gdb) start</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  ..., main () at b.cpp:11</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  11        f1();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  (gdb) ptype foo</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  type = struct (anonymous namespace)::foo {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      float f;</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  }</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  (gdb) p &f1</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  $1 = (void (*)(void)) 0x400530 <f1()></span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  (gdb) n</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  12        f2();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  (gdb) s</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  f2 () at a.cpp:10</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  10        f1();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  (gdb) ptype foo</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  type = struct (anonymous namespace)::foo {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      int i;</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  }</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  (gdb) p &f1</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  $2 = (void (*)(void)) 0x400500 <f1()></span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
So in that case, the foo type and f1 function are properly identified depending on the context in which the expression is evaluated.<br>
<br>
If the types and subprograms are tied into the same CU (with a bit of manual IR editing), two distinct types and functions are emitted into the DWARF, but GDB only finds the first one, every time, in both contexts.<br>
<br>
<br>
To look into the larger motivation, cross-CU inlining and how it interacts with Fission:<br>
<br>
</span><span style="font-size:9.0pt;font-family:"Courier New"">  a.cpp:</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    __attribute__((optnone)) void f1() {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    __attribute__((always_inline)) void f2() {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      f1();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    };</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  b.cpp:</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    void f2();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    void f3() {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      f2();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }<br>
  c.cpp:</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    void f3();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    int main() {</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">      f3();</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">    }</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  $ clang++ {a,b}.cpp -g -c -emit-llvm -S<br>
  $ llvm-link {a,b}.ll -S -o ab.ll<br>
  $ clang++-tot c.cpp ab.ll -gsplit-dwarf<br>
  $ dwp {c,ab}.dwo -o cab.dwp<br>
<br>
This produces two dwo files - one per object file (c.dwo, ab.dwo). If we look at the contents, they make a fair bit of sense:<br>
<br>
  0x0b: DW_TAG_compile_unit [1] *</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  0x19:   DW_TAG_subprogram [2]  </span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  0x25:   DW_TAG_subprogram [3]  </span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  0x31:   DW_TAG_subprogram [4]  </span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  0x43: DW_TAG_compile_unit [1] *</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  0x51:   DW_TAG_subprogram [5] *</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Courier New"">  0x5d:     DW_TAG_inlined_subroutine [6]  </span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:9.0pt;font-family:"Courier New"">              DW_AT_abstract_origin [DW_FORM_ref_addr]      (0x31 "_Z2f2v")</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
The ref_addr can be resolved relative to this whole .dwo file & the abstract subprogram is found. Yay.<br>
<br>
So GDB can't currently handle this:<br>
<br>
</span><span style="font-size:9.0pt;font-family:"Courier New"">  Could not find DWO CU ab.dwo(0x32dd6d7121dd1d9a) referenced by CU at offset 0x66 [in module a.out]</span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
And that's after some local fixes I have so it doesn't error out on the two-CUs-in-a-dwo situation (that fix at least allows the first example (local foo/f1, etc) to work with GDB - but fixing ref_addr to resolve correctly would require deeper changes I haven't
 figured out/prototyped yet).<br>
<br>
So, up until this point I was pretty satisfied there would be a way forward... <br>
<br>
Then I hit DWP files.<br>
<br>
DWP files represent multiple DWO files stacked together - mostly to deduplicate strings and type units as a sort of archival (like dsym) format.<br>
<br>
The way DWPs work, roughly (full/more details here: <a href="https://gcc.gnu.org/wiki/DebugFissionDWP" target="_blank">https://gcc.gnu.org/wiki/DebugFissionDWP</a> ) is that all the sections are concatenated together, except the debug_str and debug_str_offsets
 sections which have special handling to do what you'd expect - deduplicate strings, and adjust the str_offsets to point to the right offsets in the deduplicated string section.<br>
<br>
The other thing that DWP has, is an index, or two. cu_index and tu_index. We'll just look at cu_index.<br>
<br>
A cu_index for the cab.dwp above, is:<u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#212121">Index Signature          INFO     ABBR     LINE     STR_OFF    </span><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif";color:#212121"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#212121">----- ------------------ -------- -------- -------- --------</span><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif";color:#212121"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#212121">    2 0x7bd765349b7e7631 [2d, 65) [38, ae) [11, 22) [14, 3c) </span><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif";color:#212121"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#212121">    8 0x66f4e160661d2687 [00, 2d) [00, 38) [00, 11) [00, 14) </span><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif";color:#212121"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#212121">   11 0x32dd6d7121dd1d9a [65, 98) [38, ae) [11, 22) [14, 3c)</span><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif";color:#212121"><u></u><u></u></span></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
What this is for is to tell the consumer, which portions of each section relate to which CUs - since the DIEs in the CU don't contain any relocations, for example the abbrev offset in the CU header is probably zero. It must be resolved relative to the ABBR
 section in the above table to find the chunk of the debug_abbrev that came from that CU.<br>
<br>
So, this is all good and well, except that the INFO range isn't the whole range of the debug info from the DWO file - it's /just/ the range of this CU. Which means there's no way to resolve the ref_addr relative to the whole range, you don't know where it starts.<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Ah thanks, that explains my question above!<br>
<br>
<u></u><u></u></span></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
So this leads us to a few options - the 'simplest', that changes the semantics but not the syntax of the table - would be to widen the INFO range to cover the whole portion that came from the original DWO file.<br>
<br>
Consumers would have to be adjusted to cope with the fact that the INFO contribution for a given DWO ID would be a range that contains the CU somewhere, along with other CUs - and they'd have to search (in full LTO, this would mean searching through /all/ the
 CUs).<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Would generating a .dwo per CU help with this?<u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
<br>
<u></u><u></u></span></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">This doesn't cover all the use cases I'd have in mind, but it would at least be possible to implement & support ref_addr. The full depth of design choices I'll likely leave
 to the dwarf-discuss thread, hopefully.<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Yes, given all the non-LLVM tools that will need to support this, that is the right forum to discuss this.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">-- adrian<u></u><u></u></span></p>
</div>
</div>
</blockquote>
</div>
</div>
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">_______________________________________________<br>
LLVM Developers mailing list<br>
</span><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">llvm-dev@lists.llvm.org</span></a><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
</span><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</span></a><u></u><u></u></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</blockquote>
</div>
</div>
</div></div></div></blockquote></div></div>