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 4/13][odr] Add die_odr_state field to struct dw_die
Date: Wed, 01 Jan 2020 00:00:00 -0000	[thread overview]
Message-ID: <20200106160709.GA19886@delia> (raw)

Hi,

Add a die_odr_state field that determines whether and how a DIE participates in
the odr optimization, as well as functions that get and initialize the state.

Committed to trunk.

Thanks,
- Tom

[odr] Add die_odr_state field to struct dw_die

2020-01-06  Tom de Vries  <tdevries@suse.de>

	* dwz.c (struct dw_die): Add die_odr_state field.
	(set_die_odr_state, die_odr_state): New function.

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

diff --git a/dwz.c b/dwz.c
index c9dc56b..c82f5c9 100644
--- a/dwz.c
+++ b/dwz.c
@@ -791,6 +791,8 @@ struct dw_die
   unsigned int die_collapsed_child : 1;
   /* Set if die_parent field is reused for struct dw_cu pointer.  */
   unsigned int die_root : 1;
+  /* State for ODR optimization.  */
+  enum { ODR_UNKNOWN, ODR_NONE, ODR_DEF, ODR_DECL } die_odr_state : 2;
   /* Tree pointer to parent.  */
   dw_die_ref die_parent;
 
@@ -2339,6 +2341,104 @@ read_loclist (DSO *dso, dw_die_ref die, GElf_Addr offset)
   return 0;
 }
 
+/* Initialize die_odr_state field for DIE with CU.  */
+static void
+set_die_odr_state (dw_cu_ref cu, dw_die_ref die)
+{
+  unsigned char *ptr;
+  struct abbrev_tag *t;
+  unsigned int i;
+  bool decl_p;
+  bool name_p;
+  bool other_p;
+
+  die->die_odr_state = ODR_NONE;
+
+  if (low_mem)
+    /* Todo: allow low-mem mode.  */
+    return;
+
+  if (multifile_mode == 0)
+    /* We're in regular mode, enable the ODR optimization.  */
+    ;
+  else
+    /* One definition rule does not hold across executables and shared
+       libraries, so disable.  */
+    return;
+
+  if (!die->die_toplevel)
+    /* A nested struct is not uniquely identified by its name.  There may be a
+       different type with the same name nested in a different struct.  */
+    return;
+
+  switch (cu->lang)
+    {
+    case DW_LANG_C_plus_plus:
+      /* c++ defines one-definition-rule.  */
+      if (die->die_tag == DW_TAG_structure_type
+	  || die->die_tag == DW_TAG_class_type
+	  || die->die_tag == DW_TAG_union_type)
+	/* ODR holds for all types, but we limit the optimization to these
+	   tags, which are the ones likely to profit from it.  */
+	;
+      else
+	return;
+      break;
+    default:
+      return;
+    }
+
+  ptr = debug_sections[DEBUG_INFO].data + die->die_offset;
+  read_uleb128 (ptr);
+
+  t = die->die_abbrev;
+
+  decl_p = false;
+  name_p = false;
+  other_p = false;
+  for (i = 0; i < t->nattr; ++i)
+    {
+      if (t->attr[i].attr == DW_AT_name)
+	{
+	  name_p = true;
+	  continue;
+	}
+
+      if (t->attr[i].attr == DW_AT_declaration)
+	{
+	  decl_p = true;
+	  continue;
+	}
+
+      other_p = true;
+    }
+
+  if (!name_p)
+    /* Ignore anonymous types.  */
+    return;
+
+  if (decl_p && !other_p && die->die_child == NULL)
+    {
+      /* Detected a declaration with no attributes other than DW_AT_name and
+	 DW_AT_declaration, and no children.  */
+      die->die_odr_state = ODR_DECL;
+      return;
+    }
+
+  die->die_odr_state = ODR_DEF;
+}
+
+/* Return the initialized die_odr_state field for DIE with CU.  */
+static unsigned int UNUSED
+die_odr_state (dw_cu_ref cu, dw_die_ref die)
+{
+  if (die->die_odr_state != ODR_UNKNOWN)
+    return die->die_odr_state;
+
+  set_die_odr_state (cu, die);
+  return die->die_odr_state;
+}
+
 /* This function computes u.p1.die_hash and die_ck_state of DIE.
    The field u.p1.die_hash is an iterative hash of:
    - the die_tag,

                 reply	other threads:[~2020-01-06 16:07 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=20200106160709.GA19886@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).