From patchwork Tue May 12 10:35:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 471267 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 CBDB4140D16 for ; Tue, 12 May 2015 20:35:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=dUPA24ch; 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=y63BAt/mUDupDLe3+Tn5kazMfMMLVmGeAy9i0zcW1I68E2ZUbd0Rv CV8Jip4Ic+rUZU07DGiQEgqm1BH33L9yovEuvYpfZALxn1+Y7cwt4BR5XheP3OXb yo74/PJYyBPaCvuUaa6d7h7GfsVET2O09O7oqLR4fEVIQ292luuZg4= 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=2nOl5ACV5M0/pMNI5mJkixn9VdU=; b=dUPA24chd8EZq/umJcIi 2tt1+DEDVk3M8jUv1qdPFTlLrrESngEvZ/euHEvSzTzjsoDB92EW7lc5CtO4lybp I+/FFa9XnkhfnTmbxcvTw8v6z+nMB+nXVNbxvP9KVva+jr81N8a7UH/rpBZ3hvd1 kjmfLPigPOR2Owxf3/pxWM0= Received: (qmail 51547 invoked by alias); 12 May 2015 10:35:37 -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 51537 invoked by uid 89); 12 May 2015 10:35: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, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-wg0-f53.google.com Received: from mail-wg0-f53.google.com (HELO mail-wg0-f53.google.com) (74.125.82.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 12 May 2015 10:35:35 +0000 Received: by wgnd10 with SMTP id d10so1655058wgn.2 for ; Tue, 12 May 2015 03:35:32 -0700 (PDT) X-Received: by 10.180.97.164 with SMTP id eb4mr4042853wib.3.1431426932357; Tue, 12 May 2015 03:35:32 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr04-ext.fm.intel.com. [192.55.55.39]) by mx.google.com with ESMTPSA id fm8sm2193696wib.9.2015.05.12.03.35.30 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 May 2015 03:35:31 -0700 (PDT) Date: Tue, 12 May 2015 13:35:20 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, CHKP] Hardcode wrapper names Message-ID: <20150512103520.GB47912@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, This patch hardcodes wrapper names because builtin assembler name may vary and cannot be used to build a wrapper name. Also don't use alias chain for wrappers. Bootstrapped and regtested for x86_64-unknown-linux-gnu. Going to apply it to trunk and gcc-5 if no objections appear. Thanks, Ilya --- gcc/ 2015-05-12 Ilya Enkovich * ipa-chkp.h (chkp_wrap_function): New. * ipa-chkp.c (chkp_wrap_function): Remove 'static'. (chkp_wrap_function_name): New. (chkp_build_instrumented_fndecl): Use chkp_wrap_function_name to get wrapper name. * lto-cgraph.c: Include ipa-chkp.h. (input_cgraph_1): Avoid alias chain for wrappers. gcc/testsuite/ 2015-05-12 Ilya Enkovich * gcc.dg/lto/chkp-wrap-asm-name_0.c: New. diff --git a/gcc/ipa-chkp.c b/gcc/ipa-chkp.c index 23e08cb..ac5eb35 100644 --- a/gcc/ipa-chkp.c +++ b/gcc/ipa-chkp.c @@ -104,7 +104,7 @@ along with GCC; see the file COPYING3. If not see /* Return 1 calls to FNDECL should be replaced with a call to wrapper function. */ -static bool +bool chkp_wrap_function (tree fndecl) { if (!flag_chkp_use_wrappers) @@ -139,6 +139,51 @@ chkp_wrap_function (tree fndecl) return false; } +static const char * +chkp_wrap_function_name (tree fndecl) +{ + gcc_assert (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL); + + switch (DECL_FUNCTION_CODE (fndecl)) + { + case BUILT_IN_STRLEN: + return CHKP_WRAPPER_SYMBOL_PREFIX "strlen"; + case BUILT_IN_STRCPY: + return CHKP_WRAPPER_SYMBOL_PREFIX "strcpy"; + case BUILT_IN_STRNCPY: + return CHKP_WRAPPER_SYMBOL_PREFIX "strncpy"; + case BUILT_IN_STPCPY: + return CHKP_WRAPPER_SYMBOL_PREFIX "stpcpy"; + case BUILT_IN_STPNCPY: + return CHKP_WRAPPER_SYMBOL_PREFIX "stpncpy"; + case BUILT_IN_STRCAT: + return CHKP_WRAPPER_SYMBOL_PREFIX "strcat"; + case BUILT_IN_STRNCAT: + return CHKP_WRAPPER_SYMBOL_PREFIX "strncat"; + case BUILT_IN_MEMCPY: + return CHKP_WRAPPER_SYMBOL_PREFIX "memcpy"; + case BUILT_IN_MEMPCPY: + return CHKP_WRAPPER_SYMBOL_PREFIX "mempcpy"; + case BUILT_IN_MEMSET: + return CHKP_WRAPPER_SYMBOL_PREFIX "memset"; + case BUILT_IN_MEMMOVE: + return CHKP_WRAPPER_SYMBOL_PREFIX "memmove"; + case BUILT_IN_BZERO: + return CHKP_WRAPPER_SYMBOL_PREFIX "bzero"; + case BUILT_IN_MALLOC: + return CHKP_WRAPPER_SYMBOL_PREFIX "malloc"; + case BUILT_IN_CALLOC: + return CHKP_WRAPPER_SYMBOL_PREFIX "calloc"; + case BUILT_IN_REALLOC: + return CHKP_WRAPPER_SYMBOL_PREFIX "realloc"; + + default: + gcc_unreachable (); + } + + return ""; +} + /* Build a clone of FNDECL with a modified name. */ static tree @@ -164,9 +209,8 @@ chkp_build_instrumented_fndecl (tree fndecl) instrumented version. */ if (chkp_wrap_function(fndecl)) { - s = CHKP_WRAPPER_SYMBOL_PREFIX; - s += IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)); - new_name = get_identifier (s.c_str ()); + new_name = get_identifier (chkp_wrap_function_name (fndecl)); + DECL_VISIBILITY (new_decl) = VISIBILITY_DEFAULT; } else { diff --git a/gcc/ipa-chkp.h b/gcc/ipa-chkp.h index 6708fe9..547487e 100644 --- a/gcc/ipa-chkp.h +++ b/gcc/ipa-chkp.h @@ -24,5 +24,6 @@ extern tree chkp_copy_function_type_adding_bounds (tree orig_type); extern tree chkp_maybe_clone_builtin_fndecl (tree fndecl); extern cgraph_node *chkp_maybe_create_clone (tree fndecl); extern bool chkp_instrumentable_p (tree fndecl); +extern bool chkp_wrap_function (tree fndecl); #endif /* GCC_IPA_CHKP_H */ diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c index ac50e4b..b306c28 100644 --- a/gcc/lto-cgraph.c +++ b/gcc/lto-cgraph.c @@ -80,6 +80,7 @@ along with GCC; see the file COPYING3. If not see #include "pass_manager.h" #include "ipa-utils.h" #include "omp-low.h" +#include "ipa-chkp.h" /* True when asm nodes has been output. */ bool asm_nodes_output = false; @@ -1616,10 +1617,13 @@ input_cgraph_1 (struct lto_file_decl_data *file_data, cnode->instrumented_version->instrumented_version = cnode; } - /* Restore decl names reference. */ - IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (cnode->decl)) = 1; - TREE_CHAIN (DECL_ASSEMBLER_NAME (cnode->decl)) - = DECL_ASSEMBLER_NAME (cnode->orig_decl); + /* Restore decl names reference except for wrapper functions. */ + if (!chkp_wrap_function (cnode->orig_decl)) + { + tree name = DECL_ASSEMBLER_NAME (cnode->decl); + IDENTIFIER_TRANSPARENT_ALIAS (name) = 1; + TREE_CHAIN (name) = DECL_ASSEMBLER_NAME (cnode->orig_decl); + } } } diff --git a/gcc/testsuite/gcc.dg/lto/chkp-wrap-asm-name_0.c b/gcc/testsuite/gcc.dg/lto/chkp-wrap-asm-name_0.c new file mode 100644 index 0000000..6611bdb --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/chkp-wrap-asm-name_0.c @@ -0,0 +1,20 @@ +/* { dg-lto-do link } */ +/* { dg-require-effective-target mpx } */ +/* { dg-lto-options { { -O2 -flto -fcheck-pointer-bounds -mmpx } } } */ + +typedef long unsigned int size_t; + +extern size_t strlen (const char *); +extern __typeof (strlen) strlen __asm__ ("" "__hidden_strlen") __attribute__ ((visibility ("hidden"))); + +size_t +test1 (const char *p) { return strlen (p); } + +size_t +test2 (const char *p) { return __builtin_strlen (p); } + +int +main (int argc, const char **argv) +{ + return test1 (argv[0]) - test2 (argv[0]); +}