public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [Bug default/24198] [dwz, c++] Merge odr type definitions
  2019-01-01  0:00 [Bug default/24198] New: [dwz, c++] Merge odr type definitions vries at gcc dot gnu.org
  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
@ 2019-01-01  0:00 ` vries at gcc dot gnu.org
  2021-03-02 10:29 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz

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

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
Created attachment 11704
  --> https://sourceware.org/bugzilla/attachment.cgi?id=11704&action=edit
Proof of concept patch

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug default/24198] [dwz, c++] Merge odr type definitions
  2019-01-01  0:00 [Bug default/24198] New: [dwz, c++] Merge odr type definitions vries at gcc dot gnu.org
@ 2019-01-01  0:00 ` vries at gcc dot gnu.org
  2019-01-01  0:00 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug default/24198] New: [dwz, c++] Merge odr type definitions
@ 2019-01-01  0:00 vries at gcc dot gnu.org
  2019-01-01  0:00 ` [Bug default/24198] " vries at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz

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

            Bug ID: 24198
           Summary: [dwz, c++] Merge odr type definitions
           Product: dwz
           Version: unspecified
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: default
          Assignee: nobody at sourceware dot org
          Reporter: vries at gcc dot gnu.org
                CC: dwz at sourceware dot org
  Target Milestone: ---

Consider this test-case with this:
...
$ cat test.c
struct bbb;
struct ccc {
  int c;
};
#include "aaa.h"

extern void foo (struct aaa *);

int
main (void)
{
  struct aaa *p = (struct aaa *)0;
  foo (p);
  return 0;
}
...

and this file:
...
$ cat test2.c
struct bbb
{
  int b;
};
struct ccc;
#include "aaa.h"

void
foo (struct aaa *p)
{
}
...

and this header file:
...
$ cat aaa.h
struct aaa
{
  struct bbb *b;
  struct ccc *c;
};
...

Compiled for c++:
...
$ g++ test.c test2.c -g -c
$ g++ test.o test2.o -g
...

This results in two DWARF definitions of aaa.

This one, with ccc a complete type and bbb an incomplete one:
...
 <1><f4>: Abbrev Number: 2 (DW_TAG_structure_type)
    <f5>   DW_AT_name        : ccc
    <f9>   DW_AT_byte_size   : 4
    <fa>   DW_AT_decl_file   : 1
    <fb>   DW_AT_decl_line   : 2
    <fc>   DW_AT_decl_column : 8
    <fd>   DW_AT_sibling     : <0x10d>
 <1><114>: Abbrev Number: 2 (DW_TAG_structure_type)
    <115>   DW_AT_name        : aaa
    <119>   DW_AT_byte_size   : 16
    <11a>   DW_AT_decl_file   : 2
    <11b>   DW_AT_decl_line   : 1
    <11c>   DW_AT_decl_column : 8
    <11d>   DW_AT_sibling     : <0x138>
 <2><121>: Abbrev Number: 3 (DW_TAG_member)
    <122>   DW_AT_name        : b
    <124>   DW_AT_decl_file   : 2
    <125>   DW_AT_decl_line   : 3
    <126>   DW_AT_decl_column : 15
    <127>   DW_AT_type        : <0x13d>
    <12b>   DW_AT_data_member_location: 0
 <2><12c>: Abbrev Number: 3 (DW_TAG_member)
    <12d>   DW_AT_name        : c
    <12f>   DW_AT_decl_file   : 2
    <130>   DW_AT_decl_line   : 4
    <131>   DW_AT_decl_column : 15
    <132>   DW_AT_type        : <0x143>
    <136>   DW_AT_data_member_location: 8
 <1><138>: Abbrev Number: 5 (DW_TAG_structure_type)
    <139>   DW_AT_name        : bbb
    <13d>   DW_AT_declaration : 1
 <1><13d>: Abbrev Number: 6 (DW_TAG_pointer_type)
    <13e>   DW_AT_byte_size   : 8
    <13f>   DW_AT_type        : <0x138>
 <1><143>: Abbrev Number: 6 (DW_TAG_pointer_type)
    <144>   DW_AT_byte_size   : 8
    <145>   DW_AT_type        : <0xf4>
...

And this one, with bbb a complete type and ccc an incomplete one:
...
 <1><1ad>: Abbrev Number: 2 (DW_TAG_structure_type)
    <1ae>   DW_AT_name        : bbb
    <1b2>   DW_AT_byte_size   : 4
    <1b3>   DW_AT_decl_file   : 1
    <1b4>   DW_AT_decl_line   : 1
    <1b5>   DW_AT_decl_column : 8
    <1b6>   DW_AT_sibling     : <0x1c6>
 <1><1cd>: Abbrev Number: 2 (DW_TAG_structure_type)
    <1ce>   DW_AT_name        : aaa
    <1d2>   DW_AT_byte_size   : 16
    <1d3>   DW_AT_decl_file   : 2
    <1d4>   DW_AT_decl_line   : 1
    <1d5>   DW_AT_decl_column : 8
    <1d6>   DW_AT_sibling     : <0x1f1>
 <2><1da>: Abbrev Number: 3 (DW_TAG_member)
    <1db>   DW_AT_name        : b
    <1dd>   DW_AT_decl_file   : 2
    <1de>   DW_AT_decl_line   : 3
    <1df>   DW_AT_decl_column : 15
    <1e0>   DW_AT_type        : <0x1f1>
    <1e4>   DW_AT_data_member_location: 0
 <2><1e5>: Abbrev Number: 3 (DW_TAG_member)
    <1e6>   DW_AT_name        : c
    <1e8>   DW_AT_decl_file   : 2
    <1e9>   DW_AT_decl_line   : 4
    <1ea>   DW_AT_decl_column : 15
    <1eb>   DW_AT_type        : <0x1fc>
    <1ef>   DW_AT_data_member_location: 8
 <1><1f1>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <1f2>   DW_AT_byte_size   : 8
    <1f3>   DW_AT_type        : <0x1ad>
 <1><1f7>: Abbrev Number: 6 (DW_TAG_structure_type)
    <1f8>   DW_AT_name        : ccc
    <1fc>   DW_AT_declaration : 1
 <1><1fc>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <1fd>   DW_AT_byte_size   : 8
    <1fe>   DW_AT_type        : <0x1f7>
...

Using the C++ one-definition-rule, we can merge the two definitions.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug default/24198] [dwz, c++] Merge odr type definitions
  2019-01-01  0:00 [Bug default/24198] New: [dwz, c++] Merge odr type definitions vries at gcc dot gnu.org
  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
  2019-01-01  0:00 ` vries at gcc dot gnu.org
  2021-03-02 10:29 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz

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

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
Posted RFC: https://sourceware.org/ml/dwz/2019-q4/msg00045.html

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug default/24198] [dwz, c++] Merge odr type definitions
  2019-01-01  0:00 [Bug default/24198] New: [dwz, c++] Merge odr type definitions vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2019-01-01  0:00 ` vries at gcc dot gnu.org
@ 2021-03-02 10:29 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2021-03-02 10:29 UTC (permalink / raw)
  To: dwz

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

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
The feature was committed to trunk, disabled by default, and marked as
experimental.  I'd say that covers the scope of this PR.  Marking fixed.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-02 10:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  0:00 [Bug default/24198] New: [dwz, c++] Merge odr type definitions vries at gcc dot gnu.org
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
2019-01-01  0:00 ` vries at gcc dot gnu.org
2021-03-02 10:29 ` vries at gcc dot gnu.org

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