From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 77536 invoked by alias); 7 Apr 2015 08:10:37 -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 77524 invoked by uid 89); 7 Apr 2015 08:10:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f178.google.com Received: from mail-ie0-f178.google.com (HELO mail-ie0-f178.google.com) (209.85.223.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 07 Apr 2015 08:10:35 +0000 Received: by iedfl3 with SMTP id fl3so45802209ied.1 for ; Tue, 07 Apr 2015 01:10:33 -0700 (PDT) X-Received: by 10.42.79.204 with SMTP id s12mr24975688ick.78.1428394233219; Tue, 07 Apr 2015 01:10:33 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by mx.google.com with ESMTPSA id 16sm4365428ion.20.2015.04.07.01.10.31 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Apr 2015 01:10:32 -0700 (PDT) Date: Tue, 07 Apr 2015 08:10:00 -0000 From: Ilya Enkovich To: Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH, CHKP] Fix static const bounds creation in LTO Message-ID: <20150407081021.GA11622@msticlxl57.ims.intel.com> References: <20150402152154.GC6244@msticlxl57.ims.intel.com> <20150402204513.GI21276@atrey.karlin.mff.cuni.cz> <20150403161131.GB61994@msticlxl57.ims.intel.com> <20150403170110.GL21276@atrey.karlin.mff.cuni.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150403170110.GL21276@atrey.karlin.mff.cuni.cz> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00215.txt.bz2 On 03 Apr 19:01, Jan Hubicka wrote: > > Sadly I think this won't work on targets that adds prefix to assembler name, > like djgpp/mingw. > To obtain mangled assembler name you need to call > id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl)); > that in turn requires decl to already exist. That is why I guess you may want > to just build the new var and see if already exists.... > > Honza I see. Thank you for review! Here is an updated version. Testing passed. Does it look OK? Thanks, Ilya -- gcc/ 2015-04-07 Ilya Enkovich * tree-chkp.c (chkp_find_const_bounds_var): Remove. (chkp_make_static_const_bounds): Search existing symbol by assembler name. Use make_decl_one_only. gcc/testsuite/ 2015-04-07 Ilya Enkovich * gcc.dg/lto/chkp-static-bounds_0.c: New. diff --git a/gcc/testsuite/gcc.dg/lto/chkp-static-bounds_0.c b/gcc/testsuite/gcc.dg/lto/chkp-static-bounds_0.c new file mode 100644 index 0000000..596e551 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/chkp-static-bounds_0.c @@ -0,0 +1,26 @@ +/* { dg-lto-do link } */ +/* { dg-require-effective-target mpx } */ +/* { dg-lto-options { { -flto -flto-partition=max -fcheck-pointer-bounds -mmpx } } } */ + +const char *cc; + +int test1 (const char *c) +{ + c = __builtin___bnd_init_ptr_bounds (c); + cc = c; + return c[0] * 2; +} + +struct S +{ + int (*fnptr) (const char *); +} S; + +struct S s1 = {test1}; +struct S s2 = {test1}; +struct S s3 = {test1}; + +int main (int argc, const char **argv) +{ + return s1.fnptr (argv[0]) + s2.fnptr (argv[1]); +} diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 03f75b3..f5accce 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -1873,33 +1873,6 @@ chkp_add_bounds_to_call_stmt (gimple_stmt_iterator *gsi) gimple_call_set_with_bounds (new_call, true); } -/* Return constant static bounds var with specified LB and UB - if such var exists in varpool. Return NULL otherwise. */ -static tree -chkp_find_const_bounds_var (HOST_WIDE_INT lb, - HOST_WIDE_INT ub) -{ - tree val = targetm.chkp_make_bounds_constant (lb, ub); - struct varpool_node *node; - - /* We expect bounds constant is represented as a complex value - of two pointer sized integers. */ - gcc_assert (TREE_CODE (val) == COMPLEX_CST); - - FOR_EACH_VARIABLE (node) - if (POINTER_BOUNDS_P (node->decl) - && TREE_READONLY (node->decl) - && DECL_INITIAL (node->decl) - && TREE_CODE (DECL_INITIAL (node->decl)) == COMPLEX_CST - && tree_int_cst_equal (TREE_REALPART (DECL_INITIAL (node->decl)), - TREE_REALPART (val)) - && tree_int_cst_equal (TREE_IMAGPART (DECL_INITIAL (node->decl)), - TREE_IMAGPART (val))) - return node->decl; - - return NULL; -} - /* Return constant static bounds var with specified bounds LB and UB. If such var does not exists then new var is created with specified NAME. */ static tree @@ -1907,37 +1880,38 @@ chkp_make_static_const_bounds (HOST_WIDE_INT lb, HOST_WIDE_INT ub, const char *name) { + tree id = get_identifier (name); tree var; + varpool_node *node; + symtab_node *snode; + + var = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, + pointer_bounds_type_node); + TREE_STATIC (var) = 1; /* With LTO we may have constant bounds already in varpool. Try to find it. */ - var = chkp_find_const_bounds_var (lb, ub); - - if (var) - return var; - - var = build_decl (UNKNOWN_LOCATION, VAR_DECL, - get_identifier (name), pointer_bounds_type_node); + if ((snode = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (var)))) + { + /* We don't allow this symbol usage for non bounds. */ + gcc_assert (snode->type == SYMTAB_VARIABLE); + gcc_assert (POINTER_BOUNDS_P (snode->decl)); + return snode->decl; + } - TREE_PUBLIC (var) = 1; TREE_USED (var) = 1; TREE_READONLY (var) = 1; - TREE_STATIC (var) = 1; TREE_ADDRESSABLE (var) = 0; DECL_ARTIFICIAL (var) = 1; DECL_READ_P (var) = 1; + DECL_INITIAL (var) = targetm.chkp_make_bounds_constant (lb, ub); + make_decl_one_only (var, DECL_ASSEMBLER_NAME (var)); /* We may use this symbol during ctors generation in chkp_finish_file when all symbols are emitted. Force output to avoid undefined symbols in ctors. */ - if (!in_lto_p) - { - DECL_INITIAL (var) = targetm.chkp_make_bounds_constant (lb, ub); - DECL_COMDAT (var) = 1; - varpool_node::get_create (var)->set_comdat_group (DECL_ASSEMBLER_NAME (var)); - varpool_node::get_create (var)->force_output = 1; - } - else - DECL_EXTERNAL (var) = 1; + node = varpool_node::get_create (var); + node->force_output = 1; + varpool_node::finalize_decl (var); return var;