From patchwork Tue Apr 7 14:11:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 458684 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 15E90140290 for ; Wed, 8 Apr 2015 00:12:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=UF38272I; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=OeHyXJ2cm6eJ3CXNO O2Ms79VwGNSO+8+33SWADBWJ9J852DiI9mUFtfO9JtJpgaRxpfb87B0YRfKJmlEg nB8NCRDBRj6ZLr65czd2gefKlzkD4dnpzVMi4rrvrh8cP/2mNK3Qzf5g/xHoNRsO Dfoaue83okZNWNiYCRXgusEKks= 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=vr2Bk+zOOgcYo4Qbrpb5639 u04M=; b=UF38272Io8W78a7iLEDY0gvny5hMCqCESxS/BKyyXvjpGQC8Bazkrm7 t45s6ViXvcf5snwh/RIYo3A0fkn3QAVdPzXLGazrH/iBSrLZ8CWSR2Pb90oRizib Hy78cx3zk2AVFkp1KGLmypI7ir7bq6WO+ygbSwYi9SMJtP13kC9M= Received: (qmail 71689 invoked by alias); 7 Apr 2015 14:12:32 -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 71675 invoked by uid 89); 7 Apr 2015 14:12:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 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-f52.google.com Received: from mail-wg0-f52.google.com (HELO mail-wg0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 07 Apr 2015 14:12:29 +0000 Received: by wgin8 with SMTP id n8so57527203wgi.0 for ; Tue, 07 Apr 2015 07:12:26 -0700 (PDT) X-Received: by 10.180.89.34 with SMTP id bl2mr5069219wib.23.1428415946691; Tue, 07 Apr 2015 07:12:26 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by mx.google.com with ESMTPSA id fa8sm11188783wib.14.2015.04.07.07.12.23 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Apr 2015 07:12:25 -0700 (PDT) Date: Tue, 7 Apr 2015 17:11:33 +0300 From: Ilya Enkovich To: Jan Hubicka Cc: gcc-patches Subject: Re: [CHKP] Support returned bounds in thunks expand Message-ID: <20150407141133.GC11622@msticlxl57.ims.intel.com> References: <20150306141531.GA27860@msticlxl57.ims.intel.com> <20150402205551.GJ21276@atrey.karlin.mff.cuni.cz> <20150403170510.GO21276@atrey.karlin.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150403170510.GO21276@atrey.karlin.mff.cuni.cz> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes > > > > The problem with instrumented call is that instrumented function > > returns two values and call lhs gets only the first one. Thus we > > generate bndret call to get the second one to build own return with > > two values. > > I see, patch is OK then (preferably merging as much as possible with ipa-split) > > Honza Here is a refactored version with common code moved to tree-chkp.c. Bootstrapped and tested on x86_64-unknown-linux-gnu. Does it look OK? Thanks, Ilya --- gcc/ 2015-04-07 Ilya Enkovich * tree-chkp.h (chkp_insert_retbnd_call): New. * tree-chkp.c (chkp_insert_retbnd_call): New. * ipa-split.c (insert_bndret_call_after): Remove. (split_function): Use chkp_insert_retbnd_call. * cgraphunit.c (cgraph_node::expand_thunk): Build returned bounds for instrumented functions. gcc/testsuite/ 2015-04-07 Ilya Enkovich * gcc/testsuite/gcc.target/i386/thunk-retbnd.c: New. diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 8ac92e1..ca34c31 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1581,6 +1581,7 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk) int i; tree resdecl; tree restmp = NULL; + tree resbnd = NULL; gcall *call; greturn *ret; @@ -1697,6 +1698,17 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk) gsi_insert_after (&bsi, call, GSI_NEW_STMT); if (!alias_is_noreturn) { + if (instrumentation_clone + && !DECL_BY_REFERENCE (resdecl) + && restmp + && BOUNDED_P (restmp)) + { + resbnd = chkp_insert_retbnd_call (NULL, restmp, &bsi); + create_edge (get_create (gimple_call_fndecl (gsi_stmt (bsi))), + as_a (gsi_stmt (bsi)), + callees->count, callees->frequency); + } + if (restmp && !this_adjusting && (fixed_offset || virtual_offset)) { @@ -1766,6 +1778,7 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk) ret = gimple_build_return (restmp); else ret = gimple_build_return (resdecl); + gimple_return_set_retbnd (ret, resbnd); gsi_insert_after (&bsi, ret, GSI_NEW_STMT); } diff --git a/gcc/ipa-split.c b/gcc/ipa-split.c index 5d5db0e..f4bd8d7 100644 --- a/gcc/ipa-split.c +++ b/gcc/ipa-split.c @@ -1230,20 +1230,6 @@ find_split_points (basic_block return_bb, int overall_time, int overall_size) BITMAP_FREE (current.ssa_names_to_pass); } -/* Build and insert initialization of returned bounds RETBND - for returned value RETVAL. Statements are inserted after - a statement pointed by GSI and GSI is modified to point to - the last inserted statement. */ - -static void -insert_bndret_call_after (tree retbnd, tree retval, gimple_stmt_iterator *gsi) -{ - tree fndecl = targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDRET); - gimple bndret = gimple_build_call (fndecl, 1, retval); - gimple_call_set_lhs (bndret, retbnd); - gsi_insert_after (gsi, bndret, GSI_CONTINUE_LINKING); -} - /* Split function at SPLIT_POINT. */ static void @@ -1650,7 +1636,7 @@ split_function (basic_block return_bb, struct split_point *split_point, } /* Build bndret call to obtain returned bounds. */ if (retbnd) - insert_bndret_call_after (retbnd, retval, &gsi); + chkp_insert_retbnd_call (retbnd, retval, &gsi); gimple_call_set_lhs (call, retval); update_stmt (call); } @@ -1700,7 +1686,7 @@ split_function (basic_block return_bb, struct split_point *split_point, gsi_insert_after (&gsi, call, GSI_NEW_STMT); /* Build bndret call to obtain returned bounds. */ if (retbnd) - insert_bndret_call_after (retbnd, retval, &gsi); + chkp_insert_retbnd_call (retbnd, retval, &gsi); if (tsan_func_exit_call) gsi_insert_after (&gsi, tsan_func_exit_call, GSI_NEW_STMT); ret = gimple_build_return (retval); diff --git a/gcc/testsuite/gcc.target/i386/thunk-retbnd.c b/gcc/testsuite/gcc.target/i386/thunk-retbnd.c new file mode 100644 index 0000000..d9bd031 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/thunk-retbnd.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target mpx } */ +/* { dg-options "-O2 -fcheck-pointer-bounds -mmpx -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump-times "return &glob," 2 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ + +int glob; + +int * +test1 (void) +{ + return &glob; +} + +int * +test2 (void) +{ + return test1 (); +} diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 03f75b3..541af29 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -500,6 +500,35 @@ chkp_expand_bounds_reset_for_mem (tree mem, tree ptr) expand_normal (bndstx); } +/* Build retbnd call for returned value RETVAL. + + If BNDVAL is not NULL then result is stored + in it. Otherwise a temporary is created to + hold returned value. + + GSI points to a position for a retbnd call + and is set to created stmt. + + Cgraph edge is created for a new call if + UPDATE_EDGE is 1. + + Obtained bounds are returned. */ +tree +chkp_insert_retbnd_call (tree bndval, tree retval, + gimple_stmt_iterator *gsi) +{ + gimple call; + + if (!bndval) + bndval = create_tmp_reg (pointer_bounds_type_node, "retbnd"); + + call = gimple_build_call (chkp_ret_bnd_fndecl, 1, retval); + gimple_call_set_lhs (call, bndval); + gsi_insert_after (gsi, call, GSI_CONTINUE_LINKING); + + return bndval; +} + /* Mark statement S to not be instrumented. */ static void chkp_mark_stmt (gimple s) diff --git a/gcc/tree-chkp.h b/gcc/tree-chkp.h index 86f3618..1bafe99 100644 --- a/gcc/tree-chkp.h +++ b/gcc/tree-chkp.h @@ -54,5 +54,7 @@ extern void chkp_copy_bounds_for_assign (gimple assign, extern bool chkp_gimple_call_builtin_p (gimple call, enum built_in_function code); extern void chkp_expand_bounds_reset_for_mem (tree mem, tree ptr); +extern tree chkp_insert_retbnd_call (tree bndval, tree retval, + gimple_stmt_iterator *gsi); #endif /* GCC_TREE_CHKP_H */