<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> 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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> It's enough at least at Google for us to not use them & use CU ranges for the same purpose.<br>
<br>
<o:p></o:p></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’.<o:p></o:p></p>
<p class="MsoNormal">--paulr<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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 #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Dylan McKay <me@dylanmckay.io> <br>
<b>Sent:</b> Monday, March 16, 2020 1:32 AM<br>
<b>To:</b> David Blaikie <dblaikie@gmail.com><br>
<b>Cc:</b> Robinson, Paul <paul.robinson@sony.com>; llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] DWARF .debug_aranges data objects and address spaces<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></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">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></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"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></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:<o:p></o:p></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" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.<o:p></o:p></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>
 <o:p></o:p></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" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> 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.<o:p></o:p></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>
 <o:p></o:p></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" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> 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.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">HTH,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">--paulr<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div style="border:none;border-left:solid windowtext 1.5pt;padding:0in 0in 0in 4.0pt;border-color:currentcolor currentcolor currentcolor blue">
<div>
<div style="border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;border-color:currentcolor currentcolor">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><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<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid windowtext 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt;border-color:currentcolor currentcolor currentcolor rgb(204,204,204)">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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, <o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><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>
 <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid windowtext 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt;border-color:currentcolor currentcolor currentcolor rgb(204,204,204)">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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).<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><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>
 <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid windowtext 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt;border-color:currentcolor currentcolor currentcolor rgb(204,204,204)">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><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<o:p></o:p></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><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</body>
</html>