<div dir="ltr"><div dir="ltr">On Mon, Mar 16, 2020 at 9:31 AM Robinson, Paul <<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="gmail-m_2345183820610977334WordSection1">
<p class="MsoNormal">With AVR being affected, upstreaming a patch to put segment selectors into .debug_aranges becomes completely reasonable. There would likely want to be a target hook somewhere to return a value saying what size to use, with the default
implementation returning zero.</p></div></div></blockquote><div><br></div><div>*nod* something along those lines</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="gmail-m_2345183820610977334WordSection1"><p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal"><u></u> > If the producer has put ranges on the CU it's not a lot of work - it's parsing one DIE & looking for a couple of attributes.</p><p class="MsoNormal"><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">It’s walking through all the CUs, picking up the associated abbrevs, trolling down the list of attributes… “not a lot” indeed, but not as trivial as running through a single section linearly, which is what .debug_aranges gets you. I’ve
been lectured by @clayborg on what consumers really want for performance gains.</p></div></div></blockquote><div><br>Sure enough - though I don't believe aranges is used by default on any target/platform LLVM supports, so this time/space tradeoff doesn't seem to have been important to any of them? <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 lang="EN-US"><div class="gmail-m_2345183820610977334WordSection1"><p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal"><u></u> > It's enough at least at Google for us to not use them & use CU ranges for the same purpose.</p><p class="MsoNormal">
<br>
<u></u><u></u></p>
<p class="MsoNormal">Google is much more seriously concerned about debug-info size than about debugger performance, IIRC. This is not universally the preferred tradeoff. Just sayin’.</p></div></div></blockquote><div><br>Sure enough.<br><br>I've just had a couple of people ask about aranges recently (~year or so) & when pressing a little further, using the CU's address ranges turned out to be sufficient for their needs without having to change Clang's defaults or have their users specify extra flags to explicitly request them, etc.<br><br>Out of curiosity/for data/usage/etc - does Sony use aranges? (changing the default when targeting SCE or the like)<br><br>- Dave<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 lang="EN-US"><div class="gmail-m_2345183820610977334WordSection1"><p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal">--paulr<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0in 0in 0in 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> Dylan McKay <<a href="mailto:me@dylanmckay.io" target="_blank">me@dylanmckay.io</a>> <br>
<b>Sent:</b> Monday, March 16, 2020 1:32 AM<br>
<b>To:</b> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>><br>
<b>Cc:</b> Robinson, Paul <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>>; <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] DWARF .debug_aranges data objects and address spaces<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">I'm not across most of this debug info stuff but I'll stomp in here to confirm that AVR is a Harvard architecture, with separate addressing for the data and program buses via specialized instructions which will load from either one, or
the other, but never both.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">It makes sense that this particular problem would also affect AVR - the backend does have some issues with debug info generation.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Fri, Mar 13, 2020 at 12:22 PM David Blaikie 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>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Thu, Mar 12, 2020 at 1:51 PM Robinson, Paul <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">I’ve encountered this kind of architecture before, a long time ago (academically). In a flat-address-space machine such as X64, there is still an instruction/data distinction,
but usually only down at the level of I-cache versus D-cache (instruction fetch versus data fetch). A Harvard architecture machine exposes that to the programmer, which effectively doubles the available address space. Code and data live in different address
spaces, although the address space identifier per se is not explicit. A Move instruction would implicitly use the data address space, while an indirect Branch would implicitly target the code address space. An OS running on a Harvard architecture would require
the loader to be privileged, so it can map data from an object file into the code address space and implement any necessary fixups. Self-modifying code is at least wicked hard if not impossible to achieve.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">In DWARF this would indeed be described by a segment selector. It’s up to the target ABI to specify what the segment selector numbers actually are. For a Harvard architecture
machine this is pretty trivial, you say something like 0 for code and 1 for data. Boom done.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">LLVM basically doesn’t have targets like this, or at least it has never come up before that I’m aware of. So, when we emit DWARF, we assume a flat address space (unconditionally
setting the segment selector size to zero), and llvm-dwarfdump will choke (hopefully cleanly, but still) on an object file that uses DWARF segment selectors.<u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><br>
FWIW Luke mentioned in the original email the AVR in-tree backend seems to have this problem with an ambiguous debug_aranges entries.<br>
<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"> The point of .debug_aranges is to accelerate the search for the appropriate CU. Yes you can spend time trolling through .debug_info and .debug_abbrev, decoding the CU DIEs looking
for low_pc/high_pc pairs (or perhaps pointers to .debug_ranges) and effectively rebuild a .debug_aranges section yourself, if the compiler/linker isn’t kind enough to pre-build the table for you. I don’t understand why .debug_aranges should be discouraged;
I shouldn’t think they would be huge, and consumers can avoid loading lots of data just to figure out what’s not worth looking at. Forcing all consumers to do things the slow way seems unnecessarily inefficient.<u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><br>
If the producer has put ranges on the CU it's not a lot of work - it's parsing one DIE & looking for a couple of attributes. With Split DWARF the cost of becomes a bit more prominent - Sema.o from clang, with split dwarf (v4 or v5 about the same) is about 3.5%
larger with debug aranges (not sure about the overall data). It's enough at least at Google for us to not use them & use CU ranges for the same purpose.<br>
<br>
I thought I might be able to find some email history about why we turned it off by default, but seems we never turned it /on/ by default to begin with & it wasn't implemented until relatively late in the game (well, what I think as relatively late - after I
started on the project at least).<br>
<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"> Thinking about Harvard architecture specifically, you *<b>need</b>* the segment selector only when an address could be ambiguous about whether it’s a code or data address. This
basically comes up *<b>only</b>* in .debug_aranges, he said thinking about it for about 30 seconds. Within .debug_info you don’t need it because when you pick up the address of an entity, you know whether it’s for a code or data entity. Location lists and
range lists always point to code. For .debug_aranges you would need the segment selector, but I think that’s the only place.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">For an architecture with multiple code or data segments, then you’d need the segment selector more widely, but I should think this case wouldn’t be all that difficult to make work.
Even factoring in the llvm-dwarfdump part, it has to understand the selector only for the .debug_aranges section; everything else can remain as it is, pretending there’s a flat address space.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Now, if your target is downstream, that would make upstreaming the LLVM support a bit dicier, because we’d not want to have that feature in the upstream repo if there are no targets
using it. You’d be left maintaining that patch on your own. But as I described above, I don’t think it would be a huge deal.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">HTH,<u></u><u></u></p>
<p class="MsoNormal">--paulr<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div style="border-top:none currentcolor;border-right:none currentcolor;border-bottom:none currentcolor;border-left:1.5pt solid blue;padding:0in 0in 0in 4pt">
<div>
<div style="border-right:none currentcolor;border-bottom:none currentcolor;border-left:none currentcolor;border-top:1pt solid currentcolor;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>>
<br>
<b>Sent:</b> Thursday, March 12, 2020 2:20 PM<br>
<b>To:</b> Luke Drummond <<a href="mailto:luke.drummond@codeplay.com" target="_blank">luke.drummond@codeplay.com</a>>; Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>>; Jonas Devlieghere <<a href="mailto:jdevlieghere@apple.com" target="_blank">jdevlieghere@apple.com</a>>;
Robinson, Paul <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>><br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] DWARF .debug_aranges data objects and address spaces<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On Thu, Mar 12, 2020 at 11:00 AM Luke Drummond <<a href="mailto:luke.drummond@codeplay.com" target="_blank">luke.drummond@codeplay.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none currentcolor;border-right:none currentcolor;border-bottom:none currentcolor;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<p class="MsoNormal">On Thu Mar 12, 2020 at 5:37 PM, David Blaikie wrote:<br>
> On Wed, Mar 11, 2020 at 8:09 AM Luke Drummond<br>
> <<a href="mailto:luke.drummond@codeplay.com" target="_blank">luke.drummond@codeplay.com</a>><br>
> wrote:<br>
><br>
> > On Tue Mar 10, 2020 at 7:45 PM, David Blaikie wrote:<br>
> > > If you only want code addresses, why not use the CU's<br>
> > > low_pc/high_pc/ranges<br>
> > > - those are guaranteed to be only code addresses, I think?<br>
> > ><br>
> > In the common case, for most targets LLVM supports I think you're right,<br>
> > but for my case, regrettably, not. Because my target is a Harvard<br>
> > Architecture, any code address can have the same ordinal value as any<br>
> > data address: the code and data reside on different buses so the whole<br>
> > 4GiB space is available to both code, and data. `DW_AT_low_pc` and<br>
> > `DW_AT_high_pc` can be used to find the range of the code segment, but<br>
> > given an arbitrary address, cannot be used to conclusively determine<br>
> > whether that address belongs to code or data when both segments contain<br>
> > addresses in that numeric range.<br>
><br>
><br>
> Sorry I'm not following, partly probably due to my not having worked<br>
> with<br>
> such machines before.<br>
><br>
> But how are the code addresses and data addresses differentiated then<br>
> (eg:<br>
> if you had segment selectors in debug_aranges, how would they be used?<br>
> The<br>
> addresses taken from the system at runtime have some kind of segment<br>
> selector associated with them, that you can then use to match with the<br>
> addr+segment selector in aranges?).<br>
Yes. This. The system mostly provides us the ability to disambiguate<br>
addresses because the device's simulator / debugger make this<br>
unambiguous, but the current .debug_aranges does not allow us to do this<br>
because it's missing such info.<br>
><br>
> Actually, coming at it from a different angle: It sounds like in the<br>
> original email you're suggesting if debug_aranges did not contain data<br>
> addresses, this would be good/sufficient for you? So somehow you'd be<br>
> ensuring you only query debug_aranges using things you know are code<br>
> addresses, not data addresses? So why would the same solution/approach<br>
> not<br>
> hold to querying low/high/ranges on a CU that's already guaranteed not<br>
> to<br>
> contain data addresses?<br>
That's the root of the issue: the .debug_aranges section emitted by llvm<br>
*does* contain data addresses by default and therefore can be ambiguous.<br>
I've worked around this locally by hacking llvm to only emit aranges for<br>
text objects, <u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><br>
Sorry, but I'm still not understanding why "aranges for only text objects" is more usable for your use case than "high/low/ranges on the CU"? Could you help me understand how those are different in your situation?<br>
<u></u><u></u></p>
</div>
<blockquote style="border-top:none currentcolor;border-right:none currentcolor;border-bottom:none currentcolor;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<p class="MsoNormal">but I was wandering if it's something that's valuable to<br>
fix upstream. My guess is that it's probably too niche to worry about<br>
for the moment, but if there's interest I can propose a design (probably<br>
a target hook to ask if segment selectors are required and how to get<br>
their number from an object).<u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><br>
Added a few debug info folks in case they've got opinions. I don't really mind if we removed data objects from debug_aranges, though as you say, it's arguably correct/maybe useful as-is. Supporting it properly - probably using address segment selectors would
be fine too, I guess AVR uses address spaces for its pointers to differentiate data and code addresses? In which case we could encode the LLVM address space as the segment selector (& probably would need to query the target to decide if it has non-zero address
spaces and use that to decide whether to use segment selectors in debug_aranges)<br>
<br>
But in general, I'm mostly just discouraging people from using aranges - the data is duplicated in the CU's ranges anyway (there's some small caveats there - a producer doesn't /have/ to produce ranges on the CU, but I'd just say lower performance on such DWARF
would be acceptable) & makes object files/executables larger for minimal value/mostly duplicate data.<br>
<br>
- Dave<br>
<u></u><u></u></p>
</div>
<blockquote style="border-top:none currentcolor;border-right:none currentcolor;border-bottom:none currentcolor;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<p class="MsoNormal"><br>
Thanks for your help<br>
<br>
Luke<br>
<br>
-- <br>
Codeplay Software Ltd.<br>
Company registered in England and Wales, number: 04567874<br>
Registered office: Regent House, 316 Beulah Hill, London, SE19 3HF<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
<p class="MsoNormal">_______________________________________________<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><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote></div></div>