diff mbox

Don't use priority {cd}tors if not supported by a target (PR, gcov-profile/78086)

Message ID ceaca122-ddfb-b81a-f1db-f943601c6e99@suse.cz
State New
Headers show

Commit Message

Martin Liška Oct. 31, 2016, 12:13 p.m. UTC
On 10/31/2016 11:07 AM, Rainer Orth wrote:
> Hi Martin,

> 

>> Using priority {cd}tors on a target that does not support that can cause

>> failures (see the PR).

>> Apart from that, I decided to use priority 100 for both gcov_init and

>> gcov_exit functions as

>> the reserved range includes priority 100. Moreover, I enhanced test-cases

>> we have.

> 

> just two nits:

> 

> diff --git a/gcc/testsuite/g++.dg/gcov/pr16855-priority.C b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C

> new file mode 100644

> index 0000000..7e39565

> --- /dev/null

> +++ b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C

> [...]

> +static void __attribute__ ((constructor ((101)))) ctor_100 ()

> 

> Should be called ctor_101 now.  Same for dtor_100 below.

> 

> 	Rainer

> 


Thanks for the note. Fixed in attached patch.

Martin

Comments

Martin Liška Nov. 14, 2016, 12:12 p.m. UTC | #1
PING^1

On 10/31/2016 01:13 PM, Martin Liška wrote:
> On 10/31/2016 11:07 AM, Rainer Orth wrote:

>> Hi Martin,

>>

>>> Using priority {cd}tors on a target that does not support that can cause

>>> failures (see the PR).

>>> Apart from that, I decided to use priority 100 for both gcov_init and

>>> gcov_exit functions as

>>> the reserved range includes priority 100. Moreover, I enhanced test-cases

>>> we have.

>>

>> just two nits:

>>

>> diff --git a/gcc/testsuite/g++.dg/gcov/pr16855-priority.C b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C

>> new file mode 100644

>> index 0000000..7e39565

>> --- /dev/null

>> +++ b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C

>> [...]

>> +static void __attribute__ ((constructor ((101)))) ctor_100 ()

>>

>> Should be called ctor_101 now.  Same for dtor_100 below.

>>

>> 	Rainer

>>

> 

> Thanks for the note. Fixed in attached patch.

> 

> Martin

>
Martin Liška Nov. 23, 2016, 2:05 p.m. UTC | #2
PING^2

On 11/14/2016 01:12 PM, Martin Liška wrote:
> PING^1

> 

> On 10/31/2016 01:13 PM, Martin Liška wrote:

>> On 10/31/2016 11:07 AM, Rainer Orth wrote:

>>> Hi Martin,

>>>

>>>> Using priority {cd}tors on a target that does not support that can cause

>>>> failures (see the PR).

>>>> Apart from that, I decided to use priority 100 for both gcov_init and

>>>> gcov_exit functions as

>>>> the reserved range includes priority 100. Moreover, I enhanced test-cases

>>>> we have.

>>>

>>> just two nits:

>>>

>>> diff --git a/gcc/testsuite/g++.dg/gcov/pr16855-priority.C b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C

>>> new file mode 100644

>>> index 0000000..7e39565

>>> --- /dev/null

>>> +++ b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C

>>> [...]

>>> +static void __attribute__ ((constructor ((101)))) ctor_100 ()

>>>

>>> Should be called ctor_101 now.  Same for dtor_100 below.

>>>

>>> 	Rainer

>>>

>>

>> Thanks for the note. Fixed in attached patch.

>>

>> Martin

>>

>
diff mbox

Patch

From 0bd345d168bd18754bcb04a72e9717028d601a5f Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 26 Oct 2016 12:50:35 +0200
Subject: [PATCH] Don't use priority {cd}tors if not supported by a target (PR
 gcov-profile/78086)

gcc/testsuite/ChangeLog:

2016-10-26  Martin Liska  <mliska@suse.cz>

	* g++.dg/gcov/pr16855.C: Clean up the test case.
	* g++.dg/gcov/pr16855-priority.C: New test.

gcc/ChangeLog:

2016-10-26  Martin Liska  <mliska@suse.cz>

	* coverage.c (build_init_ctor): Don't use priority {cd}tors if
	not supported by a target.  Set priority to 100 if possible.
	(build_gcov_exit_decl): Likewise.
---
 gcc/coverage.c                               | 13 +++--
 gcc/testsuite/g++.dg/gcov/pr16855-priority.C | 79 ++++++++++++++++++++++++++++
 gcc/testsuite/g++.dg/gcov/pr16855.C          | 55 +++++++++----------
 3 files changed, 116 insertions(+), 31 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gcov/pr16855-priority.C

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 8810710..4167e26 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -1056,8 +1056,10 @@  build_init_ctor (tree gcov_info_type)
   stmt = build_call_expr (init_fn, 1, stmt);
   append_to_statement_list (stmt, &ctor);
 
-  /* Generate a constructor to run it (with priority 99).  */
-  cgraph_build_static_cdtor ('I', ctor, DEFAULT_INIT_PRIORITY - 1);
+  /* Generate a constructor to run it.  */
+  int priority = SUPPORTS_INIT_PRIORITY
+    ? MAX_RESERVED_INIT_PRIORITY: DEFAULT_INIT_PRIORITY;
+  cgraph_build_static_cdtor ('I', ctor, priority);
 }
 
 /* Generate the destructor function to call __gcov_exit.  */
@@ -1078,8 +1080,11 @@  build_gcov_exit_decl (void)
   tree stmt = build_call_expr (init_fn, 0);
   append_to_statement_list (stmt, &dtor);
 
-  /* Generate a destructor to run it (with priority 99).  */
-  cgraph_build_static_cdtor ('D', dtor, MAX_RESERVED_INIT_PRIORITY - 1);
+  /* Generate a destructor to run it.  */
+  int priority = SUPPORTS_INIT_PRIORITY
+    ? MAX_RESERVED_INIT_PRIORITY: DEFAULT_INIT_PRIORITY;
+
+  cgraph_build_static_cdtor ('D', dtor, priority);
 }
 
 /* Create the gcov_info types and object.  Generate the constructor
diff --git a/gcc/testsuite/g++.dg/gcov/pr16855-priority.C b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C
new file mode 100644
index 0000000..5c1fbc4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C
@@ -0,0 +1,79 @@ 
+/* { dg-options "-fprofile-arcs -ftest-coverage" } */
+/* { dg-do run { target native } } */
+/* { dg-require-effective-target init_priority } */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int a;
+
+void
+foo ()
+{
+  fprintf (stderr, "In foo\n");
+  a = 123; /* count(1) */
+}
+
+using namespace std;
+class Test
+{
+public:
+  Test (void) { fprintf (stderr, "In Test::Test\n"); /* count(1) */ }
+  ~Test (void) { fprintf (stderr, "In Test::~Test\n"); /* count(1) */ }
+} T1;
+
+void
+uncalled (void)
+{
+  fprintf (stderr, "In uncalled\n"); /* count(#####) */
+}
+
+int
+main (void)
+{
+  atexit (&foo);
+  fprintf (stderr, "In main\n"); /* count(1) */
+  return 0;
+}
+
+static void __attribute__ ((constructor)) ctor_default ()
+{
+  fprintf (stderr, "in constructor(())\n"); /* count(1) */
+}
+
+static void __attribute__ ((constructor ((101)))) ctor_101 ()
+{
+  fprintf (stderr, "in constructor((101))\n"); /* count(1) */
+}
+
+static void __attribute__ ((constructor ((500)))) ctor_500 ()
+{
+  fprintf (stderr, "in constructor((500))\n"); /* count(1) */
+}
+
+static void __attribute__ ((constructor ((65535)))) ctor_65535 ()
+{
+  fprintf (stderr, "in constructor((65535))\n"); /* count(1) */
+}
+
+static void __attribute__ ((destructor)) dtor_default ()
+{
+  fprintf (stderr, "in destructor(())\n"); /* count(1) */
+}
+
+static void __attribute__ ((destructor ((101)))) dtor_101 ()
+{
+  fprintf (stderr, "in destructor((101))\n"); /* count(1) */
+}
+
+static void __attribute__ ((destructor ((500)))) dtor_500 ()
+{
+  fprintf (stderr, "in destructor((500))\n"); /* count(1) */
+}
+
+static void __attribute__ ((destructor ((65535)))) dtor_65535 ()
+{
+  fprintf (stderr, "in destructor((65535))\n"); /* count(1) */
+}
+
+/* { dg-final { run-gcov branches { -b pr16855-priority.C } } } */
diff --git a/gcc/testsuite/g++.dg/gcov/pr16855.C b/gcc/testsuite/g++.dg/gcov/pr16855.C
index 91801d4..d7aa8a4 100644
--- a/gcc/testsuite/g++.dg/gcov/pr16855.C
+++ b/gcc/testsuite/g++.dg/gcov/pr16855.C
@@ -2,46 +2,47 @@ 
 /* { dg-do run { target native } } */
 
 #include <stdlib.h>
+#include <stdio.h>
 
 int a;
 
-void foo()
+void
+foo ()
 {
-  a = 123;						  /* count(1) */
+  fprintf (stderr, "In foo\n");
+  a = 123; /* count(1) */
 }
 
-#include <iostream>
 using namespace std;
-class Test {
+class Test
+{
 public:
-	Test(void){
-	cout<< "In Test ctor" << endl;			  /* count(1) */
-	}
-	~Test(void){
-	cout<< "In Test dtor" << endl;			  /* count(1) */
-	}
-}T1;
-
-void uncalled(void){
-	cout<< "In uncalled" << endl;			  /* count(#####) */
-}
-int main(void){
-atexit (&foo);
-// Test T2;
-cout<< "In main" << endl;				  /* count(1) */
-return 0;
+  Test (void) { fprintf (stderr, "In Test::Test\n"); /* count(1) */ }
+  ~Test (void) { fprintf (stderr, "In Test::~Test\n"); /* count(1) */ }
+} T1;
+
+void
+uncalled (void)
+{
+  fprintf (stderr, "In uncalled\n"); /* count(#####) */
 }
 
-#include <stdio.h>
+int
+main (void)
+{
+  atexit (&foo);
+  fprintf (stderr, "In main\n"); /* count(1) */
+  return 0;
+}
 
-__attribute__((constructor))
-static void construct_navigationBarImages() {
-  fprintf (stderr,  "((construct_navigationBarImages))"); /* count(1) */
+static void __attribute__ ((constructor)) ctor_default ()
+{
+  fprintf (stderr, "in constructor(())\n"); /* count(1) */
 }
 
-__attribute__((destructor))
-static void destroy_navigationBarImages() {
-  fprintf (stderr,  "((destroy_navigationBarImages))");	  /* count(1) */
+static void __attribute__ ((destructor)) dtor_default ()
+{
+  fprintf (stderr, "in destructor(())\n"); /* count(1) */
 }
 
 /* { dg-final { run-gcov branches { -b pr16855.C } } } */
-- 
2.10.1