From 374b9cb810f4c44bd7e66078694dcbeb3d4b40cd Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 23 Dec 2009 17:54:35 +0100 Subject: [PATCH] re PR debug/42454 (debug_ranges table contains empty range for unused .text section with -ffunction-sections) 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. Co-Authored-By: Cary Coutant From-SVN: r155429 --- gcc/ChangeLog | 7 +++ gcc/dwarf2out.c | 45 ++++++++++++------- gcc/testsuite/ChangeLog | 6 +++ .../gcc.dg/debug/dwarf2/aranges-fnsec-1.c | 8 ++-- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index be260888761..42c4e1c085c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2009-12-23 Jakub Jelinek + Cary Coutant + + 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. + 2009-12-23 Ramana Radhakrishnan PR target/42093 diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 2296dc34945..02c0afd1171 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -6062,7 +6062,8 @@ static void add_arange (tree, dw_die_ref); static void output_aranges (void); static unsigned int add_ranges_num (int); static unsigned int add_ranges (const_tree); -static unsigned int add_ranges_by_labels (const char *, const char *); +static void add_ranges_by_labels (dw_die_ref, const char *, const char *, + bool *); static void output_ranges (void); static void output_line_info (void); static void output_file_names (void); @@ -11021,10 +11022,12 @@ add_ranges (const_tree block) /* Add a new entry to .debug_ranges corresponding to a pair of labels. */ -static unsigned int -add_ranges_by_labels (const char *begin, const char *end) +static void +add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end, + bool *added) { unsigned int in_use = ranges_by_label_in_use; + unsigned int offset; if (in_use == ranges_by_label_allocated) { @@ -11041,7 +11044,12 @@ add_ranges_by_labels (const char *begin, const char *end) ranges_by_label[in_use].end = end; ranges_by_label_in_use = in_use + 1; - return add_ranges_num (-(int)in_use - 1); + offset = add_ranges_num (-(int)in_use - 1); + if (!*added) + { + add_AT_range_list (die, DW_AT_ranges, offset); + *added = true; + } } static void @@ -21209,6 +21217,7 @@ dwarf2out_finish (const char *filename) else { unsigned fde_idx = 0; + bool range_list_added = false; /* We need to give .debug_loc and .debug_ranges an appropriate "base address". Use zero so that these addresses become @@ -21219,12 +21228,11 @@ dwarf2out_finish (const char *filename) add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); if (text_section_used) - add_AT_range_list (comp_unit_die, DW_AT_ranges, - add_ranges_by_labels (text_section_label, - text_end_label)); + add_ranges_by_labels (comp_unit_die, text_section_label, + text_end_label, &range_list_added); if (flag_reorder_blocks_and_partition && cold_text_section_used) - add_ranges_by_labels (cold_text_section_label, - cold_end_label); + add_ranges_by_labels (comp_unit_die, cold_text_section_label, + cold_end_label, &range_list_added); for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++) { @@ -21233,18 +21241,23 @@ dwarf2out_finish (const char *filename) if (fde->dw_fde_switched_sections) { if (!fde->in_std_section) - add_ranges_by_labels (fde->dw_fde_hot_section_label, - fde->dw_fde_hot_section_end_label); + add_ranges_by_labels (comp_unit_die, + fde->dw_fde_hot_section_label, + fde->dw_fde_hot_section_end_label, + &range_list_added); if (!fde->cold_in_std_section) - add_ranges_by_labels (fde->dw_fde_unlikely_section_label, - fde->dw_fde_unlikely_section_end_label); + add_ranges_by_labels (comp_unit_die, + fde->dw_fde_unlikely_section_label, + fde->dw_fde_unlikely_section_end_label, + &range_list_added); } else if (!fde->in_std_section) - add_ranges_by_labels (fde->dw_fde_begin, - fde->dw_fde_end); + add_ranges_by_labels (comp_unit_die, fde->dw_fde_begin, + fde->dw_fde_end, &range_list_added); } - add_ranges (NULL); + if (range_list_added) + add_ranges (NULL); } /* Output location list section if necessary. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index da6d3b1e5b3..83144a258f2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2009-12-23 Jakub Jelinek + Cary Coutant + + PR debug/42454 + * gcc.dg/debug/dwarf2/aranges-fnsec-1.c: Add check for .debug_ranges. + 2009-12-23 Ramana Radhakrishnan PR target/42093 diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/aranges-fnsec-1.c b/gcc/testsuite/gcc.dg/debug/dwarf2/aranges-fnsec-1.c index 8bd34b2fe29..124e28eb7ce 100644 --- a/gcc/testsuite/gcc.dg/debug/dwarf2/aranges-fnsec-1.c +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/aranges-fnsec-1.c @@ -1,9 +1,11 @@ -/* Test that .debug_aranges does not have an entry for the text - section if nothing went in there. */ +/* Test that .debug_aranges and .debug_ranges do not have an entry for the + text section if nothing went in there. */ /* Origin: Joseph Myers */ /* { dg-do compile } */ -/* { dg-options "-gdwarf-2 -ffunction-sections -w" } */ +/* { dg-options "-gdwarf-2 -ffunction-sections -w -dA" } */ /* { dg-final { scan-assembler-not "\\.Letext0-\\.Ltext0" } } */ +/* { dg-final { scan-assembler-not "\\.Ltext0\[^\n\r\]*Offset 0x0" } } */ +/* { dg-final { scan-assembler "DW_AT_ranges" } } */ int f (void)