public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com
Subject: [committed] Clear struct dw_die's u.p2 field before use in 'phase 2'
Date: Tue, 01 Jan 2019 00:00:00 -0000	[thread overview]
Message-ID: <20191108171102.GA20300@delia> (raw)

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

                 reply	other threads:[~2019-11-08 17:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191108171102.GA20300@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).