public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: dwz@sourceware.org
Subject: [Bug default/24198] [dwz, c++] Merge odr type definitions
Date: Tue, 01 Jan 2019 00:00:00 -0000	[thread overview]
Message-ID: <bug-24198-11298-zG8Zwt0Fup@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-24198-11298@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=24198

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #1)
> Created attachment 11704 [details]
> Proof of concept patch

Rationale not visible in all views, so posting it here:
...
[proof-of-concept] Implement odr for DW_TAG_structure_type

This merges a struct declaration in one CU with a struct definition with the
same name in another CU, based on the c++ one-definition-rule.

So, for an executable build from these c++ sources:
...
$ cat odr.h
struct aaa {struct bbb *b; struct ccc *c; };
$ cat odr.cc
struct bbb;
struct ccc { int c; };
//struct aaa {
//  struct bbb *b; //Pointer to declared type.
//  struct ccc *c; //Pointer to defined type.
//};
$ cat odr2.cc
struct bbb { int b; };
struct ccc;
//struct aaa {
//  struct bbb *b; //Pointer to defined type.
//  struct ccc *c; //Pointer to declared type.
//};
...
we manage to get a partial unit containing dwarf describing:
...
struct bbb { int b; };
struct ccc { int c; }
struct aaa {
  struct bbb *b; //Pointer to defined type.
  struct ccc *c; //Pointer to defined type.
}
...
So, one definition of aaa with both fields pointing to definitions of bbb and
ccc.

The size reduction with current (ecd2704) master is 14%:
...
$ diff.sh odr odr.dwz.master
.debug_info      red: 18%       980     805
.debug_abbrev    red: 33%       610     413
.debug_str       red: 0%        1232    1232
total            red: 14%       2822    2450
...

And with this patch, we get 10%:
...
$ ../diff.sh odr odr.dwz.patch
.debug_info      red: 15%       980     835
.debug_abbrev    red: 22%       610     481
.debug_str       red: 0%        1232    1232
total            red: 10%       2822    2548
...
which AFAICT is due to PR24388: in the 14% variant, we have no partial units,
in the 10% variant, we do.

This is to be fixed:
...
$ gdb -batch -ex "info types" --args odr.dwz.master \
      | egrep -B1 'aaa|bbb|ccc'
File odr-2.cc:
1:      bbb;
--
File odr.cc:
2:      ccc;
--
File odr.h:
1:      aaa;
$ gdb -batch -ex "info types" --args odr.dwz.patch \
      | egrep -B1 'aaa|bbb|ccc'
File odr.cc:
1:      bbb;
2:      ccc;
--
File odr.h:
1:      aaa;
...
The file for bbb should remain odr-2.cc.

Todo:
- check for c++ language
- try out example with class: handle DW_TAG_class_type
- try out example with union: handle DW_TAG_union_type
- try out .debug_types example (die_struct_decl_p has DEBUG_INFO hardcoded)
- fix code in copy_die_tree breaking invariant that new_die points to
  reference die, which points to all other duplicate dies.
- check whether replacing declaration with definition in copy_die_tree
  is the right point to do this substitution.
- handle DIEs where DW_AT_name is not the first attribute

2019-03-26  Tom de Vries  <tdevries@suse.de>

        PR dwz/24198
        * dwz.c (checksum_die, checksum_ref_die, die_eq_1): Honour odr for
        DW_TAG_structure_type.
        (die_struct_decl_p): New function.
        (copy_die_tree): Copy definition rather than declaration.
        * Makefile (TEST_EXECS): Add odr.
        (odr): New target.
        * testsuite/dwz.tests/odr.sh: New test.
        * testsuite/dwz.tests/odr-2.cc: New test source.
        * testsuite/dwz.tests/odr.cc: Same.
        * testsuite/dwz.tests/odr.h: Same.

---
 Makefile                     |   5 ++-
 dwz.c                        | 101 +++++++++++++++++++++++++++++++++++++++++--
 testsuite/dwz.tests/odr-2.cc |   8 ++++
 testsuite/dwz.tests/odr.cc   |  13 ++++++
 testsuite/dwz.tests/odr.h    |   5 +++
 testsuite/dwz.tests/odr.sh   |  24 ++++++++++
 6 files changed, 151 insertions(+), 5 deletions(-)
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  reply	other threads:[~2019-03-26 17:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-01  0:00 [Bug default/24198] New: " vries at gcc dot gnu.org
2019-01-01  0:00 ` vries at gcc dot gnu.org [this message]
2019-01-01  0:00 ` [Bug default/24198] " vries at gcc dot gnu.org
2019-01-01  0:00 ` vries at gcc dot gnu.org
2021-03-02 10:29 ` vries at gcc dot gnu.org

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=bug-24198-11298-zG8Zwt0Fup@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=dwz@sourceware.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).