This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR42454 caused regression


> Unfortunately, when backporting the patch to 4.4-RH I've discovered it is
> actually broken. ?Note the add_AT_range_list call, which has been
> unconditional before, but now is done only if text_section_used.

Oh, sorry! Thanks for catching that. I was a bit too reliant on the
test suite, but nothing's going to notice the absence of the range
list on the compile_unit DIE except for the same slow performance of
objdump and addr2line that I was trying to fix. (I guess that means
I'd have discovered this myself later today, as I was just about to
check objdump's performance.)

> If !text_section_used, add_AT_range_list is never called on
> comp_unit_die, and while .Ldebug_ranges0 ranges are emitted, nothing
> references them. ?Checking at each add_ranges_by_label call whether it
> is the first one (whose result should be passed to add_AT_range_list)
> would be very ugly, so I'm just remembering the value that the first
> add_ranges_by_label call will return and adding DW_AT_ranges if any has been
> added (and not adding the terminator in the unlikely case that no ranges
> have been added at all).

Looks OK, but the duplication of code from add_ranges_num isn't ideal.
Maybe a new helper function would make things cleaner, something like
this:

Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 155407)
+++ dwarf2out.c	(working copy)
@@ -11045,6 +11045,19 @@ add_ranges_by_labels (const char *begin,
 }

 static void
+add_ranges_by_labels_to_AT_range_list (dw_die_ref die, const char *begin,
+				       const char *end, bool *added)
+{
+  unsigned int offset = add_ranges_by_labels (begin, end);
+
+  if (! *added)
+    {
+      add_AT_range_list (die, DW_AT_ranges, offset);
+      *added = true;
+    }
+}
+
+static void
 output_ranges (void)
 {
   unsigned i;
@@ -21209,6 +21222,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 +21233,15 @@ 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_to_AT_range_list (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_to_AT_range_list (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 +21250,25 @@ 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_to_AT_range_list (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_to_AT_range_list (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_to_AT_range_list (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.  */

-cary


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]