<div dir="ltr"><div dir="ltr">On Thu, Dec 12, 2024 at 9:41 AM David Anderson via Dwarf-discuss <<a href="mailto:dwarf-discuss@lists.dwarfstd.org">dwarf-discuss@lists.dwarfstd.org</a>> wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 12/11/24 16:59, Alex via Dwarf-discuss wrote:<br>
> ## Proposed Changes<br>
> <br>
> In Section 2.17 (Location Descriptions), replace the text on p. 53, line 15:<br>
> <br>
> From:<br>
> ```<br>
> Bounded range entries in a range list may not overlap. There is no <br>
> requirement that the entries be ordered in any particular way.<br>
> ```<br>
<br>
Neither the proposal nor  the html give a clear self-contained example <br>
of the overlap case and I think that would be important to add.<br></blockquote><div><br>Aggressive linker identical code folding is the main source of potentially overlapping CU ranges (within a single CU, or across two CUs) (& then combined with fragmented functions (what clang calls "-fbasic-block-sections", for instance) - causing one subprogram's ranges to overlap with itself or another subprogram's ranges (& then that causes overlapping at the CU level too))<br><br>eg:<br>void f1() { }<br>void f2() { }<br>int main() { f1(); f2(); }<br><br>$ clang++-tot test.cpp -g -ffunction-sections -fuse-ld=gold -Wl,--icf=all && llvm-dwarfdump-tot a.out | grep DW_AT_ranges -A3<br>              DW_AT_ranges      (indexed (0x0) rangelist = 0x00000010<br>                 [0x0000000000000670, 0x0000000000000676)<br>                 [0x0000000000000670, 0x0000000000000676)<br>                 [0x0000000000000680, 0x0000000000000692))<br><br>Admittedly, lld's icf doesn't have this result - it resolves one copy to an address, and the other copy is resolved to 0:<br><br>$ clang++-tot test.cpp -g -ffunction-sections -fuse-ld=lld -Wl,--icf=all && llvm-dwarfdump-tot a.out | grep DW_AT_ranges -A3<br>              DW_AT_ranges      (indexed (0x0) rangelist = 0x00000010<br>                 [0x0000000000001700, 0x0000000000001706)<br>                 [0x0000000000000000, 0x0000000000000006)<br>                 [0x0000000000001710, 0x0000000000001722))<br><br>(& I'm not sure if/what support bfd ld has for ICF)<br><br>Combine this with basic block sections (nodebug to simplify the DWARF output, but not necessary to reproduce the issue):<br><br>__attribute__((nodebug)) void f1() { }<br>void f2(bool b) {<br>  if (b)<br>    f1();<br>}<br>void f3(bool b) {<br>  if (!b)<br>    f1();<br>}<br>__attribute__((nodebug)) int main() {<br>}<br><br>CU ranges:<br>              DW_AT_ranges      (indexed (0x2) rangelist = 0x0000002c<br>                 [0x0000000000000680, 0x000000000000069f)<br>                 [0x000000000000069f, 0x00000000000006a9)<br>                 [0x00000000000006a9, 0x00000000000006af)<br>                 [0x00000000000006b0, 0x00000000000006cf)<br>                 [0x000000000000069f, 0x00000000000006a9)<br>                 [0x00000000000006a9, 0x00000000000006af))<br>Subprogram ranges:<br>f2:<br>                DW_AT_ranges    (indexed (0x0) rangelist = 0x00000018<br>                   [0x0000000000000680, 0x000000000000069f)<br>                   [0x000000000000069f, 0x00000000000006a9)<br>                   [0x00000000000006a9, 0x00000000000006af))<br>f3:<br>                DW_AT_ranges    (indexed (0x1) rangelist = 0x00000022<br>                   [0x00000000000006b0, 0x00000000000006cf)<br>                   [0x000000000000069f, 0x00000000000006a9)<br>                   [0x00000000000006a9, 0x00000000000006af))<br><br><br></div></div></div>