[Bug debug/51902] New: lexical_blocks inside inlined_subroutines generate duplicate debug_ranges

mark at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jan 19 15:01:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51902

             Bug #: 51902
           Summary: lexical_blocks inside inlined_subroutines generate
                    duplicate debug_ranges
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mark@gcc.gnu.org
                CC: jakub@gcc.gnu.org, jason@gcc.gnu.org


Created attachment 26380
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26380
debug_ranges.c - Get some statistics on .debug_ranges section.

I noticed that when you generate dwarf for an inlined function it often
comes with duplicate range lists for both the DW_TAG_inlined_subroutine
and the child DW_TAG_lexical_block DIE. For example:

static int k;

static int foo (int i)
{
  int j = i + 42;
  return k + (j > 14 ? j : i);
}

int main (int argc, char **argv)
{
  int c = argc;
  k = 2 * c;
  c = foo (c);
  return c;
}

Generates with -O2 -gdwarf-4:

DWARF section [27] '.debug_info' at offset 0x895:
 [Offset]
 Compilation unit at offset 0:
 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
[...]
 [    a8]      inlined_subroutine
               abstract_origin      (ref4) [    31]
               entry_pc             (addr) 0x0000000000400360 <main>
               ranges               (data4) range list [     0]
               call_file            (data1) 1
               call_line            (data1) 13
 [    bb]        formal_parameter
                 abstract_origin      (ref4) [    42]
                 location             (block1) 
                  [   0] reg5
 [    c2]        lexical_block
                 ranges               (data4) range list [    40]
 [    c7]          variable
                   abstract_origin      (ref4) [    4b]
                   location             (data4) location list [    23]
[...]
DWARF section [32] '.debug_ranges' at offset 0xb4e:
 [     0]  0x0000000000400360 <main>..0x0000000000400363 <main+0x3>
           0x0000000000400366 <main+0x6>..0x0000000000400369 <main+0x9>
           0x000000000040036f <main+0xf>..0x0000000000400374 <main+0x14>
 [    40]  0x0000000000400360 <main>..0x0000000000400363 <main+0x3>
           0x0000000000400366 <main+0x6>..0x0000000000400369 <main+0x9>
           0x000000000040036f <main+0xf>..0x0000000000400374 <main+0x14>
 [    80]  0x0000000000400360 <main>..0x0000000000400375

So range list 0 for the inlined_subroutine DIE a8 is the same as range
list 40 for the lexical_block DIE c2.

I wrote a quick and dirty elfutils libdw/libdwfl based program to look for this
pattern and it seems to occur reasonably often:

$ ./debug_ranges /usr/lib/debug/bin/bash.debug 
cus: 160
  subprograms: 6397
    inlined_subroutines: 838
      lexical_blocks: 359
dup_ranges: 220
dup_addrs: 1454

$ ./debug_ranges ~/build/gcc-obj/gcc/cc1
cus: 390
  subprograms: 84288
    inlined_subroutines: 7860
      lexical_blocks: 6256
dup_ranges: 5274
dup_addrs: 29190

$ ./debug_ranges /usr/lib/debug/lib/modules/3.1.9-1.fc16.x86_64/vmlinux 
cus: 1616
  subprograms: 108066
    inlined_subroutines: 42784
      lexical_blocks: 15276
dup_ranges: 7763
dup_addrs: 38586

Given that there will be relocations for .debug_ranges addresses pointing into
.text it could even save twice that number of addresses for ET_REL files.

See also this thread for a first try of a fix (needs some help):
http://gcc.gnu.org/ml/gcc/2012-01/msg00158.html



More information about the Gcc-bugs mailing list