From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83247 invoked by alias); 2 Apr 2015 15:45:23 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 83234 invoked by uid 89); 2 Apr 2015 15:45:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f42.google.com Received: from mail-wg0-f42.google.com (HELO mail-wg0-f42.google.com) (74.125.82.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 02 Apr 2015 15:45:21 +0000 Received: by wgin8 with SMTP id n8so96883wgi.0 for ; Thu, 02 Apr 2015 08:45:18 -0700 (PDT) X-Received: by 10.194.200.166 with SMTP id jt6mr93390135wjc.66.1427989518690; Thu, 02 Apr 2015 08:45:18 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by mx.google.com with ESMTPSA id o5sm1857786wia.0.2015.04.02.08.45.15 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Apr 2015 08:45:18 -0700 (PDT) Date: Thu, 02 Apr 2015 15:45:00 -0000 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, CHKP] Fix ipa-comdats for instrumentation thunks Message-ID: <20150402154507.GD6244@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00067.txt.bz2 Hi, With r221574 (https://gcc.gnu.org/ml/gcc-cvs/2015-03/msg00495.html) thunks don't get comdat groups assigned and this causes a failure in cgraph checker for instrumentation thunks. It happens because instrumentation thunk may reference local symbol in comdat not being in comdat by itself. This patch fixes the problem. Doesn't affect not instrumented code. Testing is in progress. Does it look OK? Thanks, Ilya -- gcc/ 2015-04-02 Ilya Enkovich * ipa-comdats.c (ipa_comdats): Visit all instrumentation thunks to set proper comdat group. gcc/testsuite/ 2015-04-02 Ilya Enkovich * gcc.target/i386/mpx/chkp-thunk-comdat-1.cc: New. * gcc.target/i386/mpx/chkp-thunk-comdat-2.cc: New. diff --git a/gcc/ipa-comdats.c b/gcc/ipa-comdats.c index f349f9f..30bcad8 100644 --- a/gcc/ipa-comdats.c +++ b/gcc/ipa-comdats.c @@ -348,10 +348,9 @@ ipa_comdats (void) } /* Finally assign symbols to the sections. */ - + cgraph_node *fun; FOR_EACH_DEFINED_SYMBOL (symbol) { - struct cgraph_node *fun; symbol->aux = NULL; if (!symbol->get_comdat_group () && !symbol->alias @@ -388,6 +387,20 @@ ipa_comdats (void) true); } } + + /* Instrumentation thunks reference original node and thus + need to be in the same comdat group. Otherwise we may + get a local instrumented symbol in a comdat group and + the referencing original node outside of it. */ + FOR_EACH_DEFINED_FUNCTION (fun) + if (fun->instrumentation_clone + && fun->instrumented_version + && !fun->instrumented_version->alias + && fun->get_comdat_group () + && !fun->instrumented_version->get_comdat_group ()) + fun->instrumented_version->call_for_symbol_and_aliases + (set_comdat_group_1, fun, true); + return 0; } diff --git a/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-1.cc b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-1.cc new file mode 100644 index 0000000..26d3c48 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-1.cc @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcheck-pointer-bounds -mmpx" } */ + +namespace +{ + template + int __attribute__((noinline)) + f1 () + { + return dim; + } +} + +int +test () +{ + return f1<3> (); +} diff --git a/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-2.cc b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-2.cc new file mode 100644 index 0000000..2b1abe9 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-2.cc @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcheck-pointer-bounds -mmpx" } */ + +class c1 +{ +public: + virtual int test1 (const char *); +}; + +class c2 +{ +public: + int test2 (const char *); +}; + +int +c1::test1 (const char *) +{ + return 0; +} + +int +c2::test2 (const char *) +{ + return 0; +}