From patchwork Mon Oct 31 09:16:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 80140 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp15774qge; Mon, 31 Oct 2016 02:17:11 -0700 (PDT) X-Received: by 10.99.64.132 with SMTP id n126mr38816478pga.87.1477905431697; Mon, 31 Oct 2016 02:17:11 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v14si23419544pfa.189.2016.10.31.02.17.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Oct 2016 02:17:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439920-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439920-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439920-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=VZr60XMQhkqlMznHPtigEy6JmqjA0fAhalvJOktfU3a0JIixct 0EEPdrvDiDjiqlrEzVgxRvchwBjF41e/60UnUW1Og23bwE41BG46kujEHhDkPgFM j3mWcoiIn1XNA7f+xDaUD9ql1JJGyUa7QLBsDEEc0bPtVQflRPcJQVAyo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=4sr1v/qRGNzaHzeV1jvdtM0dfVo=; b=wVhRxcDoJxbN/cbRxt8o WEBANPCb03lafs116shOOLZIAiwpIgu/+ychrfKg7v8AyvBhlOyBR6ILTcmDhpmo fu2m7M4Iacbu73dGqTLTL8xAmNC9EYy2CN5psZpBoGEMmrGG9rQEeviKSZzj6LqF zoOIvOkyHOXFO8b9+EaU0og= Received: (qmail 114302 invoked by alias); 31 Oct 2016 09:16:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 114092 invoked by uid 89); 31 Oct 2016 09:16:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:append_, sk:destroy, H*M:95ac, H*MI:95ac X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 31 Oct 2016 09:16:40 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 56121AB03; Mon, 31 Oct 2016 09:16:37 +0000 (UTC) To: GCC Patches Cc: danglin@gcc.gnu.org, Nathan Sidwell From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Don't use priority {cd}tors if not supported by a target (PR, gcov-profile/78086) Message-ID: <4b281a98-6567-95ac-6695-0fe963c7d79d@suse.cz> Date: Mon, 31 Oct 2016 10:16:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi. 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. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin >From 05a0dcb13d608facdd1c85f4101cd821634d07cd Mon Sep 17 00:00:00 2001 From: marxin 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 * 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 * 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..7e39565 --- /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 +#include + +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_100 () +{ + 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_100 () +{ + 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 +#include int a; -void foo() +void +foo () { - a = 123; /* count(1) */ + fprintf (stderr, "In foo\n"); + a = 123; /* count(1) */ } -#include 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 +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