From patchwork Thu Nov 19 16:31:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 546566 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 60D80141434 for ; Fri, 20 Nov 2015 03:31:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=abCq3Jzv; 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=XfNCW9pBofuctVTlFo3WHptuXuNluDlA0n8oH4bp4QWFgH/2Acy4M hk9mAMhnck2F/uxSAh2yTzbSkPPRTEFFIbX/psHimnQOdhmQJ08KB9TvIMbRFuO0 BjR0Xt0An03L13xyv6OaoKWRLjCPkwcD8pBltWY/TTySztIIW+Wlsg= 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=oi1uyE/yw8LjSdz5qkJCTZlSSrU=; b=abCq3JzvjJKiD2N3VF22 2yJtd9ayhIHncPcOL+IVgDcuSjFbvxmPUX6mRi+drT/s+ixCL3YK4NcraYp4Gtl6 a2xXjJyTZkantRAnW3SIuXbaU1PjPf5MzP5MxuWkhzFlBGJO2kiyIY1Kmw3f3MqL B/zyc53R116cBr9TR+K/GhA= Received: (qmail 59742 invoked by alias); 19 Nov 2015 16:31:47 -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 59013 invoked by uid 89); 19 Nov 2015 16:31:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.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-qk0-f176.google.com Received: from mail-qk0-f176.google.com (HELO mail-qk0-f176.google.com) (209.85.220.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 19 Nov 2015 16:31:41 +0000 Received: by qkfo3 with SMTP id o3so27326794qkf.1 for ; Thu, 19 Nov 2015 08:31:39 -0800 (PST) X-Received: by 10.55.80.138 with SMTP id e132mr7614177qkb.74.1447950698921; Thu, 19 Nov 2015 08:31:38 -0800 (PST) Received: from msticlxl57.ims.intel.com ([134.134.139.76]) by smtp.gmail.com with ESMTPSA id t47sm2532379qgt.28.2015.11.19.08.31.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Nov 2015 08:31:38 -0800 (PST) Date: Thu, 19 Nov 2015 19:31:10 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, PR68337] Don't fold memcpy/memmove we want to instrument Message-ID: <20151119163110.GG42296@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi, Currently we fold all memcpy/memmove calls with a known data size. It causes two problems when used with Pointer Bounds Checker. The first problem is that we may copy pointers as integer data and thus loose bounds. The second problem is that if we inline memcpy, we also have to inline bounds copy and this may result in a huge amount of code and significant compilation time growth. This patch disables folding for functions we want to instrument. Does it look reasonable for trunk and GCC5 branch? Bootstrapped and regtested on x86_64-unknown-linux-gnu. Thanks, Ilya --- gcc/ 2015-11-19 Ilya Enkovich * gimple-fold.c (gimple_fold_builtin_memory_op): Don't fold non-useless call if we are going to instrument it. gcc/testsuite/ 2015-11-19 Ilya Enkovich * gcc.target/i386/mpx/pr68337.c: New test. diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 1ab20d1..b3a1229 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -53,6 +53,7 @@ along with GCC; see the file COPYING3. If not see #include "gomp-constants.h" #include "optabs-query.h" #include "omp-low.h" +#include "ipa-chkp.h" /* Return true when DECL can be referenced from current unit. @@ -664,6 +665,13 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, unsigned int src_align, dest_align; tree off0; + /* Inlining of memcpy/memmove may cause bounds lost (if we copy + pointers as wide integer) and also may result in huge function + size because of inlined bounds copy. Thus don't inline for + functions we want to instrument. */ + if (flag_check_pointer_bounds && chkp_instrumentable_p (cfun->decl)) + return false; + /* Build accesses at offset zero with a ref-all character type. */ off0 = build_int_cst (build_pointer_type_for_mode (char_type_node, ptr_mode, true), 0); diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr68337.c b/gcc/testsuite/gcc.target/i386/mpx/pr68337.c new file mode 100644 index 0000000..3f8d79d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/mpx/pr68337.c @@ -0,0 +1,32 @@ +/* { dg-do run } */ +/* { dg-options "-fcheck-pointer-bounds -mmpx" } */ + +#include "mpx-check.h" + +#define N 2 + +extern void abort (); + +static int +mpx_test (int argc, const char **argv) +{ + char ** src = (char **)malloc (sizeof (char *) * N); + char ** dst = (char **)malloc (sizeof (char *) * N); + int i; + + for (i = 0; i < N; i++) + src[i] = __bnd_set_ptr_bounds (argv[0] + i, i + 1); + + __builtin_memcpy(dst, src, sizeof (char *) * N); + + for (i = 0; i < N; i++) + { + char *p = dst[i]; + if (p != argv[0] + i + || __bnd_get_ptr_lbound (p) != p + || __bnd_get_ptr_ubound (p) != p + i) + abort (); + } + + return 0; +}