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, mark@klomp.org
Subject: [committed] Handle reordered dup chains in create_import_tree
Date: Tue, 16 Mar 2021 16:54:57 +0100	[thread overview]
Message-ID: <20210316155456.GA32267@delia> (raw)

Hi,

With the test-case from PR27578, we run into:
...
$ dwz libvclplug_genlo.so.debug -o libvclplug_genlo.so.debug.z \
    -lnone --odr --devel-progress
create_import_tree phase 2
dwz: dwz.c:8833: remove_import_edges: Assertion `i == cucount' failed.
Aborted (core dumped)
...

Using --devel-verify-edges, we can trigger an assert earlier:
...
create_import_tree phase 1
dwz: dwz.c:8923: verify_edges_1: \
  Assertion `count == 0 || e1->icu->idx > last_idx' failed.
Aborted (core dumped)
...
where e1->icu->idx == 201 and last_idx == 201.

The problem is (as we can see using --devel-dump-edges) that there's a
duplicate edge from CU 201 to PU 48:
...
idx: 48
cu: 0xbc
incoming: 200
incoming: 201
incoming: 201
incoming: 203
incoming: 204
incoming: 208
...

This can be traced back to this duplicate chain:
...
duplicate chain:
 7fe2 O 2de8b1f3(fc1aa040) 2de8b1f3 Visual structure_type DECL
 19d67 O 2de8b1f3(fc1aa040) 2de8b1f3 Visual structure_type DECL
 2a7aa O 2de8b1f3(fc1aa040) 2de8b1f3 Visual structure_type DECL
 41434 O 2de8b1f3(fc1aa040) 2de8b1f3 Visual structure_type DECL
Compilation Unit @ offset 0x5bf84:
 5fd9d O 2de8b1f3(fc1aa040) 2de8b1f3 Visual structure_type DECL
 611f5 O 2de8b1f3(deb4b00f) 2de8b1f3 Visual structure_type DEF
...

Since it starts with a DECL, it will be reordered such that the DEF is at
the start.  However, that breaks the code in create_import_tree that checks
for duplicate chain members from the same CU, which assumes that those are
adjacent.

Fix this in create_import_tree.

Committed to trunk.

Thanks,
- Tom

Handle reordered dup chains in create_import_tree

2021-03-16  Tom de Vries  <tdevries@suse.de>

	PR dwz/27578
	* dwz.c (create_import_tree): Handle reorder duplicate chain.

---
 dwz.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/dwz.c b/dwz.c
index 11c9114..d72ec28 100644
--- a/dwz.c
+++ b/dwz.c
@@ -9135,11 +9135,18 @@ create_import_tree (void)
       ipu->cu = pu;
       pu->u1.cu_icu = ipu;
       assert (rdie->die_toplevel);
+      dw_die_ref firstdie = NULL;
+      dw_cu_ref firstdiecu = NULL;
       for (die = rdie->die_nextdup, prev_cu = NULL;
 	   die; die = die->die_nextdup)
 	{
 	  dw_cu_ref diecu = die_cu (die);
-	  if (diecu == prev_cu)
+	  if (firstdie == NULL)
+	    {
+	      firstdie = die;
+	      firstdiecu = die_cu (firstdie);
+	    }
+	  if (diecu == prev_cu || (die != firstdie && diecu == firstdiecu))
 	    continue;
 	  ipu->incoming_count++;
 	  size += 1 + (diecu->cu_version == 2 ? ptr_size : 4);
@@ -9149,11 +9156,18 @@ create_import_tree (void)
 		       obstack_alloc (&ob2,
 				      ipu->incoming_count
 				      * sizeof (*ipu->incoming));
+      firstdie = NULL;
+      firstdiecu = NULL;
       for (die = rdie->die_nextdup, i = 0, prev_cu = NULL;
 	   die; die = die->die_nextdup)
 	{
 	  dw_cu_ref diecu = die_cu (die);
-	  if (diecu == prev_cu)
+	  if (firstdie == NULL)
+	    {
+	      firstdie = die;
+	      firstdiecu = die_cu (firstdie);
+	    }
+	  if (diecu == prev_cu || (die != firstdie && diecu == firstdiecu))
 	    continue;
 	  icu = diecu->u1.cu_icu;
 	  if (icu == NULL)

                 reply	other threads:[~2021-03-16 15:55 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=20210316155456.GA32267@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.org \
    /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).