public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Assert we don't create recursive DW_AT_abstract_origin
@ 2023-10-30 12:57 Richard Biener
  2023-11-16 21:14 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-10-30 12:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Jakub Jelinek

We have a support case that shows GCC 7 sometimes creates
DW_TAG_label refering to itself via a DW_AT_abstract_origin
when using LTO.  This for example triggers the sanity check
added below during LTO bootstrap.

Making this check cover more than just DW_AT_abstract_origin
breaks bootstrap on trunk for

      /* GNU extension: Record what type our vtable lives in.  */
      if (TYPE_VFIELD (type))
        {
          tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));

          gen_type_die (vtype, context_die);
          add_AT_die_ref (type_die, DW_AT_containing_type,
                          lookup_type_die (vtype));

so the check is for now restricted to DW_AT_abstract_origin.

Bootstrapped on x86_64-unknown-linux-gnu, OK?

My workaround for the GCC 7 problem is

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5590845d2a4..07185a1a0d3 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -23030,7 +23031,7 @@ gen_label_die (tree decl, dw_die_ref context_die)
       lbl_die = new_die (DW_TAG_label, context_die, decl);
       equate_decl_number_to_die (decl, lbl_die);
 
-      if (origin != NULL)
+      if (origin != NULL && origin != decl)
        add_abstract_origin_attribute (lbl_die, origin);
       else
        add_name_and_src_coords_attributes (lbl_die, decl);

that's not needed on trunk because there we dont' end up
with LABEL_DECLs with self-DECL_ABSTRACT_ORIGIN (and not DECL_ABSTRACT).

Thanks,
Richard.

	* dwarf2out.cc (add_AT_die_ref): Assert we do not add
	a self-ref DW_AT_abstract_origin.
---
 gcc/dwarf2out.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 1e0cec66c5e..0070a9e8412 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -4908,6 +4908,7 @@ add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_
 {
   dw_attr_node attr;
   gcc_checking_assert (targ_die != NULL);
+  gcc_assert (targ_die != die || attr_kind != DW_AT_abstract_origin);
 
   /* With LTO we can end up trying to reference something we didn't create
      a DIE for.  Avoid crashing later on a NULL referenced DIE.  */
-- 
2.35.3

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

* Re: [PATCH] Assert we don't create recursive DW_AT_abstract_origin
  2023-10-30 12:57 [PATCH] Assert we don't create recursive DW_AT_abstract_origin Richard Biener
@ 2023-11-16 21:14 ` Jason Merrill
  2023-11-17  7:54   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2023-11-16 21:14 UTC (permalink / raw)
  To: Richard Biener, gcc-patches; +Cc: Jakub Jelinek

On 10/30/23 08:57, Richard Biener wrote:
> We have a support case that shows GCC 7 sometimes creates
> DW_TAG_label refering to itself via a DW_AT_abstract_origin
> when using LTO.  This for example triggers the sanity check
> added below during LTO bootstrap.
> 
> Making this check cover more than just DW_AT_abstract_origin
> breaks bootstrap on trunk for
> 
>        /* GNU extension: Record what type our vtable lives in.  */
>        if (TYPE_VFIELD (type))
>          {
>            tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
> 
>            gen_type_die (vtype, context_die);
>            add_AT_die_ref (type_die, DW_AT_containing_type,
>                            lookup_type_die (vtype));
> 
> so the check is for now restricted to DW_AT_abstract_origin.
> 
> Bootstrapped on x86_64-unknown-linux-gnu, OK?

Let's also check for DW_AT_specification, since that's the other one 
get_AT follows.  OK with that change.

> My workaround for the GCC 7 problem is
> 
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index 5590845d2a4..07185a1a0d3 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -23030,7 +23031,7 @@ gen_label_die (tree decl, dw_die_ref context_die)
>         lbl_die = new_die (DW_TAG_label, context_die, decl);
>         equate_decl_number_to_die (decl, lbl_die);
>   
> -      if (origin != NULL)
> +      if (origin != NULL && origin != decl)
>          add_abstract_origin_attribute (lbl_die, origin);
>         else
>          add_name_and_src_coords_attributes (lbl_die, decl);
> 
> that's not needed on trunk because there we dont' end up
> with LABEL_DECLs with self-DECL_ABSTRACT_ORIGIN (and not DECL_ABSTRACT).
> 
> Thanks,
> Richard.
> 
> 	* dwarf2out.cc (add_AT_die_ref): Assert we do not add
> 	a self-ref DW_AT_abstract_origin.
> ---
>   gcc/dwarf2out.cc | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
> index 1e0cec66c5e..0070a9e8412 100644
> --- a/gcc/dwarf2out.cc
> +++ b/gcc/dwarf2out.cc
> @@ -4908,6 +4908,7 @@ add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_
>   {
>     dw_attr_node attr;
>     gcc_checking_assert (targ_die != NULL);
> +  gcc_assert (targ_die != die || attr_kind != DW_AT_abstract_origin);
>   
>     /* With LTO we can end up trying to reference something we didn't create
>        a DIE for.  Avoid crashing later on a NULL referenced DIE.  */


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

* Re: [PATCH] Assert we don't create recursive DW_AT_abstract_origin
  2023-11-16 21:14 ` Jason Merrill
@ 2023-11-17  7:54   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2023-11-17  7:54 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Jakub Jelinek

On Thu, 16 Nov 2023, Jason Merrill wrote:

> On 10/30/23 08:57, Richard Biener wrote:
> > We have a support case that shows GCC 7 sometimes creates
> > DW_TAG_label refering to itself via a DW_AT_abstract_origin
> > when using LTO.  This for example triggers the sanity check
> > added below during LTO bootstrap.
> > 
> > Making this check cover more than just DW_AT_abstract_origin
> > breaks bootstrap on trunk for
> > 
> >        /* GNU extension: Record what type our vtable lives in.  */
> >        if (TYPE_VFIELD (type))
> >          {
> >            tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
> > 
> >            gen_type_die (vtype, context_die);
> >            add_AT_die_ref (type_die, DW_AT_containing_type,
> >                            lookup_type_die (vtype));
> > 
> > so the check is for now restricted to DW_AT_abstract_origin.
> > 
> > Bootstrapped on x86_64-unknown-linux-gnu, OK?
> 
> Let's also check for DW_AT_specification, since that's the other one get_AT
> follows.  OK with that change.

The following is what I applied.

Richard.

From 2c070d92beea9e46947693c623b44551dc18e513 Mon Sep 17 00:00:00 2001
From: Richard Biener <rguenther@suse.de>
Date: Mon, 30 Oct 2023 13:17:11 +0100
Subject: [PATCH] Assert we don't create recursive
 DW_AT_{abstract_origin,specification}
To: gcc-patches@gcc.gnu.org

We have a support case that shows GCC 7 sometimes creates
DW_TAG_label refering to itself via a DW_AT_abstract_origin
when using LTO.  This for example triggers the sanity check
added below during LTO bootstrap.

Making this check cover more than just DW_AT_abstract_origin
breaks bootstrap on trunk for

      /* GNU extension: Record what type our vtable lives in.  */
      if (TYPE_VFIELD (type))
        {
          tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));

          gen_type_die (vtype, context_die);
          add_AT_die_ref (type_die, DW_AT_containing_type,
                          lookup_type_die (vtype));

so the check is for now restricted to DW_AT_abstract_origin
and DW_AT_specification both of which we follow within get_AT.

	* dwarf2out.cc (add_AT_die_ref): Assert we do not add
	a self-ref DW_AT_abstract_origin or DW_AT_specification.
---
 gcc/dwarf2out.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 9850d094707..d187be9b786 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -4908,6 +4908,9 @@ add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_
 {
   dw_attr_node attr;
   gcc_checking_assert (targ_die != NULL);
+  gcc_assert (targ_die != die
+	      || (attr_kind != DW_AT_abstract_origin
+		  && attr_kind != DW_AT_specification));
 
   /* With LTO we can end up trying to reference something we didn't create
      a DIE for.  Avoid crashing later on a NULL referenced DIE.  */
-- 
2.35.3


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

end of thread, other threads:[~2023-11-17  7:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30 12:57 [PATCH] Assert we don't create recursive DW_AT_abstract_origin Richard Biener
2023-11-16 21:14 ` Jason Merrill
2023-11-17  7:54   ` Richard Biener

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