<div dir="ltr"><div>Great, thanks! I'll look at a patch in due course (it may need to wait for me to finish other bits first).</div><div><br></div><div>James<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 21 Jul 2020 at 19:31, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Yep, sounds like a reasonable bug in llvm-dwarfdump to fix.<br><br>Probably the right way to fix this is to check whether the start/end addresses have a section number. If they're zero with no section number, then they're really zero & should terminate the list. Otherwise they shouldn't.<br><br>Here's a reproducer for debug_ranges at least, without needing any patches to LLVM:<br><br><font face="monospace">$ cat range.cpp<br>void f1() { }<br>void f2() { __builtin_unreachable(); } // alternatively: "int f2() { }" - both constructs are valid so long as f2 is never called, though it may still need to have a valid address (could use pointers to it in a map for some reason, etc)<br>int main() { }<br>$ clang++ range.cpp -ffunction-sections -g -O1 -c<br>$ llvm-dwarfdump-tot range.o -debug-info -debug-ranges<br>range.o:        file format elf64-x86-64<br><br>.debug_info contents:<br>0x00000000: Compile Unit: length = 0x00000079, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000007d)<br><br>0x0000000b: DW_TAG_compile_unit<br>...<br>              DW_AT_ranges      (0x00000000<br>                 [0x0000000000000000, 0x0000000000000001))<br>...<br>.debug_ranges contents:<br>00000000 0000000000000000 0000000000000001<br>00000000 <End of list><br>00000020 0000000000000000 0000000000000003<br>00000020 <End of list><br>$ llvm-dwarfdump-tot a.out -debug-info -debug-ranges<br>a.out:  file format elf64-x86-64<br><br>.debug_info contents:<br>0x00000000: Compile Unit: length = 0x00000079, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000007d)<br><br>0x0000000b: DW_TAG_compile_unit<br>...<br>              DW_AT_ranges      (0x00000000<br>                 [0x0000000000401110, 0x0000000000401111)<br>                 [0x0000000000401120, 0x0000000000401120)<br>                 [0x0000000000401120, 0x0000000000401123))<br>...<br><br>.debug_ranges contents:<br>00000000 0000000000401110 0000000000401111<br>00000000 0000000000401120 0000000000401120<br>00000000 0000000000401120 0000000000401123<br>00000000 <End of list></font></div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 21, 2020 at 8:29 AM Robinson, Paul <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div>
<p class="MsoNormal">I agree it’s a bug.  An absolute (0, 0) pair is what indicates end-of-list.  You can get pairs of 0 addends with `.quad foo; .quad foo` or `.quad foo; .quad bar` but the former is an empty range and the latter would be a real range.<u></u><u></u></p>
<p class="MsoNormal">I’d expect the identical issue to pop up in .debug_ranges, so a patch should address both.<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-color:currentcolor currentcolor currentcolor blue;border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0in 0in 0in 4pt">
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> <b>On Behalf Of
</b>James Henderson via llvm-dev<br>
<b>Sent:</b> Tuesday, July 21, 2020 4:26 AM<br>
<b>To:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>; David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>>; Alexey Lapshin <<a href="mailto:a.v.lapshin@mail.ru" target="_blank">a.v.lapshin@mail.ru</a>><br>
<b>Subject:</b> [llvm-dev] [DWARF] Handling empty ranges/location lists in ET_REL files<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Hi all,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I've put this email in a different thread, although it is quite similar to some of the threads on tombstoning etc, with similar underlying structural issues.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Whilst prototyping my fragmented DWARF idea for GC-ing DWARF sections properly, I ran into an object in the game code I was using as my input where a v4 .debug_loc section had a location description that looked something like this:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">.quad foo<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">.quad foo<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">... # location description<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">where foo was a section symbol, i.e. the start and end address were the same. Consequently, there would be two relocations with 0 addend patching the start and end offset. When I was using llvm-dwarfdump to dump the .debug_loc section,
 I ended up with a decoding, and eventually a parsing error, because it saw a 0, 0 pair, so treated the entry as an end of list entry, and assumed the location description was the start of the next list.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">The debug_loc parsing code treats 0, 0 pairs as end of list entries, whether or not they are relocated. I think this is a bug - if there are relocations we can be reasonably confident that the compiler did not intend it to be the end of
 the list, and at link time, this probably won't get resolved to 0, 0 (it's still technically possible it will, if 0 is a valid address, and the corresponding section was put at that address, but that's outside the scope of this email).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I've got a fairly simple change that could solve this, but it would require to check for the presence of a relocation at either address, in the event 0, 0 was read. Should I go ahead with tidying up the change/testing it etc? Or do we want
 a different solution to this problem (aside from using DWARFv5 of course!)?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Related aside: I haven't checked, but it's quite possible there's a similar problem in .debug_ranges parsing.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">James<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>

</blockquote></div>
</blockquote></div>