From patchwork Tue Mar 10 10:12:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 448455 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 00AE71401AA for ; Tue, 10 Mar 2015 21:13:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=rRsXkJWp; 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=OH7B9VURZgjF+B6nK5JJ1IKrEAmfS+ilu1hIg1oPONL4ioaP4eeOG fsHhnKzXbI3/85ehENjFDNHEq6gWqiSfYJTivXQxAoOOb4Zo/X7pD8VlwonZF8lB gRSGQMdk/epiDAo+CkUjXWxKxQigljoOvZcQknpUWwFCyt0Wfo23SQ= 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:subject:message-id:mime-version:content-type; s= default; bh=D8zsM3B4yNkzpVkG3i4tWOovdt8=; b=rRsXkJWp+qfE1U/zHv1R 2i/IC23nqOpHJ3YOVYGMHX/5tBzBmWvGNJBUf2F7lgZFUtE4NsIa25IZoczgEmqb DnkGJn4KMqishZxMIEW6wZmde7LkIp+XUm3mZ3Zj+1IyRGWPjyfWixA+HHpNCv2W UrbvYK0MAbrdonFX0dfo54s= Received: (qmail 130853 invoked by alias); 10 Mar 2015 10:13:01 -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 130844 invoked by uid 89); 10 Mar 2015 10:13:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ie0-f170.google.com Received: from mail-ie0-f170.google.com (HELO mail-ie0-f170.google.com) (209.85.223.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 10 Mar 2015 10:12:59 +0000 Received: by iecsf10 with SMTP id sf10so7186687iec.2 for ; Tue, 10 Mar 2015 03:12:57 -0700 (PDT) X-Received: by 10.43.64.134 with SMTP id xi6mr32888045icb.83.1425982377315; Tue, 10 Mar 2015 03:12:57 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr02-ext.fm.intel.com. [192.55.55.37]) by mx.google.com with ESMTPSA id g74sm211845ioi.42.2015.03.10.03.12.55 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Mar 2015 03:12:56 -0700 (PDT) Date: Tue, 10 Mar 2015 13:12:45 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [CHKP] Support returned bounds in thunks expand Message-ID: <20150306141531.GA27860@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, Currentl we loose returned bounds when functions are merged. This patch fixes it by adding returne bounds support for cgraph_node::expand_thunk. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk? Thanks, Ilya --- gcc/ 2015-03-06 Ilya Enkovich * cgraphunit.c (cgraph_node::expand_thunk): Build returned bounds for instrumented functions. gcc/testsuite/ 2015-03-06 Ilya Enkovich * gcc/testsuite/gcc.target/i386/thunk-retbnd.c: New. diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index e640907..fc38e67 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,21 @@ 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)) + { + tree fn = targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDRET); + gcall *retbnd = gimple_build_call (fn, 1, restmp); + + resbnd = create_tmp_reg (pointer_bounds_type_node, "retbnd"); + gimple_call_set_lhs (retbnd, resbnd); + + gsi_insert_after (&bsi, retbnd, GSI_NEW_STMT); + create_edge (get_create (fn), retbnd, callees->count, callees->frequency); + } + if (restmp && !this_adjusting && (fixed_offset || virtual_offset)) { @@ -1766,6 +1782,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/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 (); +}