Bug 42454 - [4.5 Regression] debug_ranges table contains empty range for unused .text section with -ffunction-sections
Summary: [4.5 Regression] debug_ranges table contains empty range for unused .text sec...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.5.0
: P2 normal
Target Milestone: 4.5.0
Assignee: Cary Coutant
URL:
Keywords: wrong-debug
Depends on:
Blocks:
 
Reported: 2009-12-21 23:09 UTC by Cary Coutant
Modified: 2009-12-23 17:09 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux
Target: x86_64-unknown-linux
Build: x86_64-unknown-linux
Known to work:
Known to fail:
Last reconfirmed: 2009-12-21 23:56:48


Attachments
Proposed fix for PR 42454 (314 bytes, patch)
2009-12-21 23:13 UTC, Cary Coutant
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Cary Coutant 2009-12-21 23:09:43 UTC
When -ffunction-sections is turned on with -g2, gcc emits an entry into the .debug_ranges section for the DW_TAG_compile_unit for the range (.Ltext, .Letext) unconditionally. With -ffunction-sections, the .text section remains unused, and this entry in .debug_ranges refers to a zero-length range.

That's not normally a problem, but when --gc-sections is turned on in the linker, the empty .text section can be removed, and the relocations for that range apply zeroes to that entry, and it now looks like the end of the range list. Because that's actually the first range entry that gcc emits for the compile unit, DWARF consumers see an empty range list. This causes significant slowdowns for objdump and addr2line.

Example:

$ cat foo.c
int foo(int i)
{       
  return i + 1; 
}       
int bar(int i)  
{       
  return i + 2; 
}       
$ gcc -S -dA -g -ffunction-sections foo.c

The resulting assembly code has this:

        .text
.Ltext0:
        .section        .text.foo,"ax",@progbits
.globl foo
        .type   foo, @function
foo:
.LFB0:
...
        .text
.Letext0:
...
        .section        .debug_ranges,"",@progbits
.Ldebug_ranges0:
        .quad   .Ltext0 # Offset 0x0
        .quad   .Letext0
        .quad   .LFB0   # Offset 0x10
        .quad   .LFE0
        .quad   .LFB1   # Offset 0x20
        .quad   .LFE1
        .quad   0x0
        .quad   0x0
Comment 1 Cary Coutant 2009-12-21 23:13:31 UTC
Created attachment 19363 [details]
Proposed fix for PR 42454

	* dwarf2out.c (dwarf2out_finish): Don't output range for .text
	section unless .text section was used.  Likewise for cold.
Comment 2 Cary Coutant 2009-12-22 17:38:13 UTC
Subject: Bug 42454

Author: ccoutant
Date: Tue Dec 22 17:37:57 2009
New Revision: 155402

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155402
Log:
	PR debug/42454
	* dwarf2out.c (dwarf2out_finish): Don't output range for .text
	section unless .text section was used.  Likewise for cold.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c

Comment 3 Cary Coutant 2009-12-22 17:45:23 UTC
Fixed at r155402.
Comment 4 Cary Coutant 2009-12-23 00:15:20 UTC
Caused a regression: If !text_section_used, would omit the DW_AT_ranges attribute from the compile_unit DIE.
Comment 5 Jakub Jelinek 2009-12-23 16:54:50 UTC
Subject: Bug 42454

Author: jakub
Date: Wed Dec 23 16:54:35 2009
New Revision: 155429

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155429
Log:
	PR debug/42454
	* dwarf2out.c (add_ranges_by_labels_to_AT_range_list): New function.
	(dwarf2out_finish): Call add_ranges_by_labels_to_AT_range_list.

	* gcc.dg/debug/dwarf2/aranges-fnsec-1.c: Add check for .debug_ranges.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/debug/dwarf2/aranges-fnsec-1.c

Comment 6 Jakub Jelinek 2009-12-23 17:09:25 UTC
Fixed.
Comment 7 Tobias Grosser 2010-06-07 20:59:54 UTC
Subject: Bug 42454

Author: grosser
Date: Mon Jun  7 20:59:33 2010
New Revision: 160403

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160403
Log:
Merge some commits missed during a merge from mainline in Dez 2009.

	* README: Mention changes to Makefile.in and functions.texi.
	* gather-docs: Mention 'make stamp-functions' in the header.

svn+ssh://gcc.gnu.org/svn/gcc/trunk@154545

	* functions.texi: Rebuild.

svn+ssh://gcc.gnu.org/svn/gcc/trunk@154546

Fix PR target/40887

2009-12-24  Julian Brown  <julian@codesourcery.com>
            Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>

        PR target/40887

        * config/arm/arm.c (output_call_mem): Remove armv5 support.
        * config/arm/arm.md (*call_mem): Disable for armv5. Add note.
        (*call_value_mem): Likewise.

        PR target/40887

        * gcc.target/gcc.arm/pr40887.c: New test.

svn+ssh://gcc.gnu.org/svn/gcc/trunk@155453

Fix PR target/42093

2009-12-23  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>

        PR target/42093
        * config/arm/arm.h (CASE_VECTOR_PC_RELATIVE): Fix macro usage
        to TARGET_THUMB1.
        (CASE_VECTOR_SHORTEN_MODE): Allow signed offsets
        only for TARGET_THUMB1.

2009-12-23  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>

        PR target/42093
        * gcc.target/arm/pr42093.c: New test.

svn+ssh://gcc.gnu.org/svn/gcc/trunk@155428

	PR debug/42454
	* dwarf2out.c (add_ranges_by_labels_to_AT_range_list): New function.
	(dwarf2out_finish): Call add_ranges_by_labels_to_AT_range_list.

	* gcc.dg/debug/dwarf2/aranges-fnsec-1.c: Add check for .debug_ranges.

svn+ssh://gcc.gnu.org/svn/gcc/trunk@155429

Added:
    branches/graphite/gcc/testsuite/gcc.target/arm/pr40887.c
    branches/graphite/gcc/testsuite/gcc.target/arm/pr42093.c
Modified:
    branches/graphite/gcc/config/arm/arm.c
    branches/graphite/gcc/config/arm/arm.h
    branches/graphite/gcc/config/arm/arm.md
    branches/graphite/gcc/dwarf2out.c
    branches/graphite/gcc/testsuite/gcc.dg/debug/dwarf2/aranges-fnsec-1.c
    branches/graphite/libiberty/README
    branches/graphite/libiberty/functions.texi
    branches/graphite/libiberty/gather-docs