cgraphunit: Don't emit asm thunks for -dx [PR106261]

Message ID YuEHj/BMEVuC5OvQ@tucnak
State New, archived
Headers
Series cgraphunit: Don't emit asm thunks for -dx [PR106261] |

Commit Message

Jakub Jelinek July 27, 2022, 9:38 a.m. UTC
  Hi!

When -dx option is used (didn't know we have it and no idea what is it
useful for), we just expand functions to RTL and then omit all further
RTL passes, so the normal functions aren't actually emitted into assembly,
just variables.
The following testcase ICEs, because we don't emit the methods, but do
emit thunks pointing to that and those thunks have unwind info and rely on
at least some real functions to be emitted (which is normally the case,
thunks are only emitted for locally defined functions) because otherwise
there are no CIEs, only FDEs and dwarf2out is upset about it.

The following patch fixes that by not emitting assembly thunks for -dx
either.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2022-07-27  Jakub Jelinek  <jakub@redhat.com>

	PR debug/106261
	* cgraphunit.cc (cgraph_node::assemble_thunks_and_aliases): Don't
	output asm thunks for -dx.

	* g++.dg/debug/pr106261.C: New test.


	Jakub
  

Comments

Richard Biener July 27, 2022, 9:39 a.m. UTC | #1
On Wed, 27 Jul 2022, Jakub Jelinek wrote:

> Hi!
> 
> When -dx option is used (didn't know we have it and no idea what is it
> useful for), we just expand functions to RTL and then omit all further
> RTL passes, so the normal functions aren't actually emitted into assembly,
> just variables.
> The following testcase ICEs, because we don't emit the methods, but do
> emit thunks pointing to that and those thunks have unwind info and rely on
> at least some real functions to be emitted (which is normally the case,
> thunks are only emitted for locally defined functions) because otherwise
> there are no CIEs, only FDEs and dwarf2out is upset about it.
> 
> The following patch fixes that by not emitting assembly thunks for -dx
> either.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK/

> 2022-07-27  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR debug/106261
> 	* cgraphunit.cc (cgraph_node::assemble_thunks_and_aliases): Don't
> 	output asm thunks for -dx.
> 
> 	* g++.dg/debug/pr106261.C: New test.
> 
> --- gcc/cgraphunit.cc.jj	2022-06-27 11:18:02.048066608 +0200
> +++ gcc/cgraphunit.cc	2022-07-26 16:01:38.696956950 +0200
> @@ -1753,7 +1753,7 @@ cgraph_node::assemble_thunks_and_aliases
>  	cgraph_node *thunk = e->caller;
>  
>  	e = e->next_caller;
> -	expand_thunk (thunk, true, false);
> +	expand_thunk (thunk, !rtl_dump_and_exit, false);
>  	thunk->assemble_thunks_and_aliases ();
>        }
>      else
> --- gcc/testsuite/g++.dg/debug/pr106261.C.jj	2022-07-26 15:59:04.082979550 +0200
> +++ gcc/testsuite/g++.dg/debug/pr106261.C	2022-07-26 15:58:37.301329916 +0200
> @@ -0,0 +1,36 @@
> +// PR debug/106261
> +// { dg-do compile }
> +// { dg-options "-dx -fno-dwarf2-cfi-asm" }
> +
> +struct A
> +{
> +  virtual void foo ();
> +  int a;
> +};
> +class C : virtual public A
> +{
> +};
> +struct B
> +{
> +  A *b;
> +
> +  B (A *x) : b (x) { b->foo (); }
> +};
> +struct E
> +{
> +  virtual ~E ();
> +};
> +class D : public C, E
> +{
> +};
> +struct F : D
> +{
> +  F (int);
> +
> +  static void bar ()
> +  {
> +    F a (0);
> +    B b (&a);
> +  }
> +};
> +void baz () { F::bar (); }
> 
> 	Jakub
> 
>
  

Patch

--- gcc/cgraphunit.cc.jj	2022-06-27 11:18:02.048066608 +0200
+++ gcc/cgraphunit.cc	2022-07-26 16:01:38.696956950 +0200
@@ -1753,7 +1753,7 @@  cgraph_node::assemble_thunks_and_aliases
 	cgraph_node *thunk = e->caller;
 
 	e = e->next_caller;
-	expand_thunk (thunk, true, false);
+	expand_thunk (thunk, !rtl_dump_and_exit, false);
 	thunk->assemble_thunks_and_aliases ();
       }
     else
--- gcc/testsuite/g++.dg/debug/pr106261.C.jj	2022-07-26 15:59:04.082979550 +0200
+++ gcc/testsuite/g++.dg/debug/pr106261.C	2022-07-26 15:58:37.301329916 +0200
@@ -0,0 +1,36 @@ 
+// PR debug/106261
+// { dg-do compile }
+// { dg-options "-dx -fno-dwarf2-cfi-asm" }
+
+struct A
+{
+  virtual void foo ();
+  int a;
+};
+class C : virtual public A
+{
+};
+struct B
+{
+  A *b;
+
+  B (A *x) : b (x) { b->foo (); }
+};
+struct E
+{
+  virtual ~E ();
+};
+class D : public C, E
+{
+};
+struct F : D
+{
+  F (int);
+
+  static void bar ()
+  {
+    F a (0);
+    B b (&a);
+  }
+};
+void baz () { F::bar (); }