public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Clear struct dw_die's u.p2 field before use in 'phase 2'
@ 2019-01-01  0:00 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz, jakub

Hi,

In struct dw_die we have a union u with fields p1 and p2.  The p1 field is
used during 'phase 1', after which the space is reused for the p2 field during
'phase 2'.

While developing a patch for dwz, I ran into a case where a
'die->u.p2.die_new_offset != 0' assert in write_die did not trigger, because
die->u.p1 was used during 'phase 1' which left a non-zero value in
die->u.p2.die_new_offset.

Add initialization that clears the 'phase 2' field u.p2 before 'phase 2',
to increase the chance of triggering this type of assert.

Enable this only with -DDEVEL, since it increases runtime with ~1%.

Committed to trunk.

Thanks,
- Tom

Clear struct dw_die's u.p2 field before use in 'phase 2'

2019-11-08  Tom de Vries  <tdevries@suse.de>

	* dwz.c (clear_p2_field): New function.
	(write_multifile, dw, optimize_multifile): Call clear_p2_field.

---
 dwz.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/dwz.c b/dwz.c
index 6e1c997..ec9a79a 100644
--- a/dwz.c
+++ b/dwz.c
@@ -11474,6 +11474,29 @@ write_multifile_line (void)
   return ret;
 }
 
+#if DEVEL
+/* In struct dw_die we have a union u with fields p1 and p2.  The p1 field is
+   used during phase 1, after which the space is reused for the p2 field
+   during phase 2.  Clear the p2 field to get rid of values stored to p1
+   during phase 1.  */
+static int
+clear_p2_field (void)
+{
+  dw_cu_ref cu;
+  dw_die_ref die;
+
+  FOREACH_DIE (cu, die)
+    {
+      assert (die->die_collapsed_child == 0);
+      die->u.p2.die_new_abbrev = NULL;
+      die->u.p2.die_new_offset = 0;
+      die->u.p2.die_intracu_udata_size = 0;
+    }
+
+  return 0;
+}
+#endif
+
 /* Collect potentially shareable DIEs, strings and .debug_macro
    opcode sequences into temporary .debug_* files.  */
 static int
@@ -11500,6 +11523,10 @@ write_multifile (DSO *dso)
   multi_ptr_size = ptr_size;
   multi_endian = do_read_32 == buf_read_ule32 ? ELFDATA2LSB : ELFDATA2MSB;
 
+#if DEVEL
+  clear_p2_field ();
+#endif
+
   for (i = 0; i < SAVED_SECTIONS; i++)
     {
       saved_new_data[i] = debug_sections[i].new_data;
@@ -11812,6 +11839,9 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 		   && (remove_empty_pus ()
 		       || read_macro (dso)))
 	       || read_debug_info (dso, DEBUG_TYPES)
+#if DEVEL
+	       || clear_p2_field ()
+#endif
 	       || compute_abbrevs (dso)
 	       || (unlikely (fi_multifile) && (finalize_strp (false), 0)))
 	{
@@ -12127,6 +12157,10 @@ optimize_multifile (void)
 	  || partition_dups ())
 	goto fail;
 
+#if DEVEL
+      clear_p2_field ();
+#endif
+
       for (cup = &first_cu; *cup && (*cup)->cu_kind == CU_PU;
 	   cup = &(*cup)->cu_next)
 	;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-08 17:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  0:00 [committed] Clear struct dw_die's u.p2 field before use in 'phase 2' Tom de Vries

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).