public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] DWARF: Add header for .debug_str_offsets table for dwarf_version 5.
@ 2018-04-30 12:35 Mark Wielaard
  2018-05-14 13:42 ` Mark Wielaard
  2018-05-16 17:37 ` Jason Merrill
  0 siblings, 2 replies; 3+ messages in thread
From: Mark Wielaard @ 2018-04-30 12:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Mark Wielaard

DWARF5 defines a small header for .debug_str_offsets.  Since we only use
it for split dwarf .dwo files we don't need to keep track of the actual
index offset in an attribute.

gcc/ChangeLog:

	* dwarf2out.c (count_index_strings): New function.
	(output_indirect_strings): Call count_index_strings and generate
	header for dwarf_version >= 5.

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index d2d4ec0..340de5b 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -28732,6 +28732,19 @@ output_index_string (indirect_string_node **h, unsigned int *cur_idx)
   return 1;
 }
 
+/* A helper function for output_indirect_strings.  Counts the number
+   of index strings offsets.  Must match the logic of the functions
+   output_index_string[_offsets] above.  */
+int
+count_index_strings (indirect_string_node **h, unsigned int *last_idx)
+{
+  struct indirect_string_node *node = *h;
+
+  if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
+    *last_idx += 1;
+  return 1;
+}
+
 /* A helper function for dwarf2out_finish called through
    htab_traverse.  Emit one queued .debug_str string.  */
 
@@ -28769,6 +28782,33 @@ output_indirect_strings (void)
 					  output_indirect_string> (DW_FORM_strp);
 
       switch_to_section (debug_str_offsets_section);
+      /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
+	 header.  Note that we don't need to generate a label to the
+	 actual index table following the header here, because this is
+	 for the split dwarf case only.  In an .dwo file there is only
+	 one string offsets table (and one debug info section).  But
+	 if we would start using string offset tables for the main (or
+	 skeleton) unit, then we have to add a DW_AT_str_offsets_base
+	 pointing to the actual index after the header.  Split dwarf
+	 units will never have a string offsets base attribute.  When
+	 a split unit is moved into a .dwp file the string offsets can
+	 be found through the .debug_cu_index section table.  */
+      if (dwarf_version >= 5)
+	{
+	  unsigned int last_idx = 0;
+	  unsigned long str_offsets_length;
+
+	  debug_str_hash->traverse_noresize
+	    <unsigned int *, count_index_strings> (&last_idx);
+	  str_offsets_length = last_idx * DWARF_OFFSET_SIZE + 4;
+	  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+	    dw2_asm_output_data (4, 0xffffffff,
+				 "Escape value for 64-bit DWARF extension");
+	  dw2_asm_output_data (DWARF_OFFSET_SIZE, str_offsets_length,
+			       "Length of string offsets unit");
+	  dw2_asm_output_data (2, 5, "DWARF string offsets version");
+	  dw2_asm_output_data (2, 0, "Header zero padding");
+	}
       debug_str_hash->traverse_noresize
 	<unsigned int *, output_index_string_offset> (&offset);
       switch_to_section (debug_str_dwo_section);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] DWARF: Add header for .debug_str_offsets table for dwarf_version 5.
  2018-04-30 12:35 [PATCH] DWARF: Add header for .debug_str_offsets table for dwarf_version 5 Mark Wielaard
@ 2018-05-14 13:42 ` Mark Wielaard
  2018-05-16 17:37 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2018-05-14 13:42 UTC (permalink / raw)
  To: gcc-patches

On Mon, 2018-04-30 at 14:34 +0200, Mark Wielaard wrote:
> DWARF5 defines a small header for .debug_str_offsets.  Since we only use
> it for split dwarf .dwo files we don't need to keep track of the actual
> index offset in an attribute.

Ping.

gcc/ChangeLog:

        * dwarf2out.c (count_index_strings): New function.
        (output_indirect_strings): Call count_index_strings and generate
        header for dwarf_version >= 5.

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index d2d4ec0..340de5b 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -28732,6 +28732,19 @@ output_index_string (indirect_string_node **h, unsigned int *cur_idx)
   return 1;
 }
 
+/* A helper function for output_indirect_strings.  Counts the number
+   of index strings offsets.  Must match the logic of the functions
+   output_index_string[_offsets] above.  */
+int
+count_index_strings (indirect_string_node **h, unsigned int *last_idx)
+{
+  struct indirect_string_node *node = *h;
+
+  if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
+    *last_idx += 1;
+  return 1;
+}
+
 /* A helper function for dwarf2out_finish called through
    htab_traverse.  Emit one queued .debug_str string.  */
 
@@ -28769,6 +28782,33 @@ output_indirect_strings (void)
                                          output_indirect_string> (DW_FORM_strp);
 
       switch_to_section (debug_str_offsets_section);
+      /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
+        header.  Note that we don't need to generate a label to the
+        actual index table following the header here, because this is
+        for the split dwarf case only.  In an .dwo file there is only
+        one string offsets table (and one debug info section).  But
+        if we would start using string offset tables for the main (or
+        skeleton) unit, then we have to add a DW_AT_str_offsets_base
+        pointing to the actual index after the header.  Split dwarf
+        units will never have a string offsets base attribute.  When
+        a split unit is moved into a .dwp file the string offsets can
+        be found through the .debug_cu_index section table.  */
+      if (dwarf_version >= 5)
+       {
+         unsigned int last_idx = 0;
+         unsigned long str_offsets_length;
+
+         debug_str_hash->traverse_noresize
+           <unsigned int *, count_index_strings> (&last_idx);
+         str_offsets_length = last_idx * DWARF_OFFSET_SIZE + 4;
+         if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+           dw2_asm_output_data (4, 0xffffffff,
+                                "Escape value for 64-bit DWARF extension");
+         dw2_asm_output_data (DWARF_OFFSET_SIZE, str_offsets_length,
+                              "Length of string offsets unit");
+         dw2_asm_output_data (2, 5, "DWARF string offsets version");
+         dw2_asm_output_data (2, 0, "Header zero padding");
+       }
       debug_str_hash->traverse_noresize
        <unsigned int *, output_index_string_offset> (&offset);
       switch_to_section (debug_str_dwo_section);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] DWARF: Add header for .debug_str_offsets table for dwarf_version 5.
  2018-04-30 12:35 [PATCH] DWARF: Add header for .debug_str_offsets table for dwarf_version 5 Mark Wielaard
  2018-05-14 13:42 ` Mark Wielaard
@ 2018-05-16 17:37 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2018-05-16 17:37 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: gcc-patches List

On Mon, Apr 30, 2018 at 8:34 AM, Mark Wielaard <mark@klomp.org> wrote:
> DWARF5 defines a small header for .debug_str_offsets.  Since we only use
> it for split dwarf .dwo files we don't need to keep track of the actual
> index offset in an attribute.
>
> gcc/ChangeLog:
>
>         * dwarf2out.c (count_index_strings): New function.
>         (output_indirect_strings): Call count_index_strings and generate
>         header for dwarf_version >= 5.

OK.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-16 17:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-30 12:35 [PATCH] DWARF: Add header for .debug_str_offsets table for dwarf_version 5 Mark Wielaard
2018-05-14 13:42 ` Mark Wielaard
2018-05-16 17:37 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).