From patchwork Mon Jul 16 07:48:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 944170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481589-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="RkRK9NFM"; dkim-atps=neutral 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 41TbCn4PpNz9s9N for ; Mon, 16 Jul 2018 17:49:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:in-reply-to:references:message-id; q=dns; s= default; b=xHMGmJ8W1IIRgzYv4co5Y7lg5R9RK1ttG9bbf7SqSN4gNBKzIH6Xg cZdJqQ3xITBUKXfeWXVlOHgC103ET+dn7JgINu+8D/0LmBmmQTtDkRNRDWGnlLwp xQAU0VsOohQAhJf2ecbV6btIIWm4YXLvyPqDkM6Ss6a2KH0w83DAL0= 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:from :to:cc:subject:date:in-reply-to:references:message-id; s= default; bh=FVzR0A39MefF6/G/pMEeO0WTnRE=; b=RkRK9NFMtYCRzdukQGR8 S+2gYHpNxjULaC6cxPUHaegbi4LZHhMk6ZCROOMc7t1ZIRJ1kSRg/MbS1bNElXPG fGzt7ENlupRAekMInzUBLlGUBYgOVvHSgfFlzfEABHEmyuaWG16F3iz+P+YGoxg7 luyuyPcrTpgl78RGRocBbBs= Received: (qmail 43052 invoked by alias); 16 Jul 2018 07:49:12 -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 42859 invoked by uid 89); 16 Jul 2018 07:49:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=CPUs, cpus, Hx-languages-length:4618, GOT X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jul 2018 07:49:04 +0000 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6G7n1wb000742 for ; Mon, 16 Jul 2018 03:49:02 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k8h6tc44b-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 16 Jul 2018 03:49:02 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Jul 2018 08:48:49 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 16 Jul 2018 08:48:47 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6G7mjDi40370244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 16 Jul 2018 07:48:45 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DFBCAE055; Mon, 16 Jul 2018 10:49:03 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46D6FAE04D; Mon, 16 Jul 2018 10:49:03 +0100 (BST) Received: from white.boeblingen.de.ibm.com (unknown [9.152.97.127]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 16 Jul 2018 10:49:03 +0100 (BST) From: Ilya Leoshkevich To: gcc-patches@gcc.gnu.org Cc: krebbel@linux.ibm.com, Ilya Leoshkevich Subject: [PATCH 1/3] S/390: Implement -mfentry Date: Mon, 16 Jul 2018 09:48:05 +0200 In-Reply-To: <20180716074807.43653-1-iii@linux.ibm.com> References: <20180716074807.43653-1-iii@linux.ibm.com> x-cbid: 18071607-0028-0000-0000-000002DC03D5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18071607-0029-0000-0000-00002393BF5E Message-Id: <20180716074807.43653-2-iii@linux.ibm.com> This is the counterpart of the i386 feature introduced by 39a5a6a4: Add direct support for Linux kernel __fentry__ patching. On i386, the difference between mcount and fentry is that fentry comes before the prolog. On s390 mcount already comes before the prolog, but takes 4 instructions. This patch introduces the more efficient implementation (just 1 instruction) and puts it under -mfentry flag. The produced code is compatible only with newer glibc versions, which provide the __fentry__ symbol and do not clobber %r0 when resolving lazily bound functions. Because 31-bit PLT stubs assume %r12 contains GOT address, which is not the case when the code runs before the prolog, -mfentry is allowed only for 64-bit code. Also, code compiled with -mfentry cannot be used for the nested C functions, since they both use %r0. In this case instrumentation is not insterted, and a new warning is issued for each affected nested function. * gcc/common.opt: Add the new warning. * gcc/config/s390/s390.c (s390_function_profiler): Emit "brasl %r0,__fentry__" when -mfentry is specified. (s390_option_override_internal): Disallow -mfentry for 31-bit CPUs. * gcc/config/s390/s390.opt: Add the new option. * gcc/testsuite/gcc.target/s390/mfentry-m64.c: New testcase. --- gcc/common.opt | 5 +++++ gcc/config/s390/s390.c | 18 ++++++++++++++++-- gcc/config/s390/s390.opt | 5 +++++ gcc/testsuite/gcc.target/s390/mfentry-m64.c | 8 ++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/s390/mfentry-m64.c diff --git a/gcc/common.opt b/gcc/common.opt index c29abdb5cb1..4d031e81b09 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -571,6 +571,11 @@ Wattribute-alias Common Var(warn_attributes) Init(1) Warning Warn about type safety and similar errors in attribute alias and related. +Wcannot-profile +Common Var(warn_cannot_profile) Init(1) Warning +Warn when profiling instrumentation was requested, but could not be applied to +a certain function. + Wcast-align Common Var(warn_cast_align) Warning Warn about pointer casts which increase alignment. diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index 23c3f3db621..3a406b955a0 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -13144,14 +13144,22 @@ s390_function_profiler (FILE *file, int labelno) op[3] = gen_rtx_SYMBOL_REF (Pmode, label); SYMBOL_REF_FLAGS (op[3]) = SYMBOL_FLAG_LOCAL; - op[4] = gen_rtx_SYMBOL_REF (Pmode, "_mcount"); + op[4] = gen_rtx_SYMBOL_REF (Pmode, flag_fentry ? "__fentry__" : "_mcount"); if (flag_pic) { op[4] = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op[4]), UNSPEC_PLT); op[4] = gen_rtx_CONST (Pmode, op[4]); } - if (TARGET_64BIT) + if (flag_fentry) + { + if (cfun->static_chain_decl) + warning (OPT_Wcannot_profile, "nested functions cannot be profiled " + "with -mfentry on s390"); + else + output_asm_insn ("brasl\t0,%4", op); + } + else if (TARGET_64BIT) { output_asm_insn ("stg\t%0,%1", op); output_asm_insn ("larl\t%2,%3", op); @@ -15562,6 +15570,12 @@ s390_option_override_internal (bool main_args_p, /* Call target specific restore function to do post-init work. At the moment, this just sets opts->x_s390_cost_pointer. */ s390_function_specific_restore (opts, NULL); + + /* Check whether -mfentry is supported. It cannot be used in 31-bit mode, + because 31-bit PLT stubs assume that %r12 contains GOT address, which is + not the case when the code runs before the prolog. */ + if (opts->x_flag_fentry && !TARGET_64BIT) + error ("-mfentry is supported only for 64-bit CPUs"); } static void diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt index eb16f9c821f..59e97d031b4 100644 --- a/gcc/config/s390/s390.opt +++ b/gcc/config/s390/s390.opt @@ -293,3 +293,8 @@ locations which have been patched as part of using one of the -mindirect-branch* or -mfunction-return* options. The sections consist of an array of 32 bit elements. Each entry holds the offset from the entry to the patched location. + +mfentry +Target Report Var(flag_fentry) +Emit profiling counter call at function entry before prologue. The compiled +code will require a 64-bit CPU and glibc 2.29 or newer to run. diff --git a/gcc/testsuite/gcc.target/s390/mfentry-m64.c b/gcc/testsuite/gcc.target/s390/mfentry-m64.c new file mode 100644 index 00000000000..aa3fc81248f --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/mfentry-m64.c @@ -0,0 +1,8 @@ +/* { dg-do compile { target { lp64 } } } */ +/* { dg-options "-pg -mfentry" } */ + +void +profileme (void) +{ + /* { dg-final { scan-assembler "brasl\t0,__fentry__" } } */ +} From patchwork Mon Jul 16 07:48:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 944169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481588-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NA531M8b"; dkim-atps=neutral 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 41TbCZ40VMz9s3q for ; Mon, 16 Jul 2018 17:49:30 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:in-reply-to:references:message-id; q=dns; s= default; b=EOPBMeOCTbvY5AlETx29jYeFUN2ld1PoOkP8oOH40vHmiKrmO+c9J 2ColX8ELG0W5tfY3MuK7x4PEz/svSVoqWdRJR2mBkxxZwUp6ds95iirqp1lIhkTi IPVH5c7VMRpf9L2A8ZQkZc7z+1lbWkkVSzx4gmzz6OGGfsEI6L2j7M= 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:from :to:cc:subject:date:in-reply-to:references:message-id; s= default; bh=/L4bA7paLTmlJSHgZg+porWykfU=; b=NA531M8bqN2lUXqBDbGx ck3xQcX3CTvCZKVFPF2cMSHksV7CwlQ92l7+4wZNe6cwf2myHodEGgDdKSEi4VS3 CBpUfaI3tjo19ZNTcKW8ui2xw0nUVX+RNfk4WG18L0j5+KooqzO5n3iqFlzPeKcY 3zpJEgNIYhUyL25dvadrbCE= Received: (qmail 42990 invoked by alias); 16 Jul 2018 07:49:12 -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 42744 invoked by uid 89); 16 Jul 2018 07:48:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=2.29, symbol_ref X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jul 2018 07:48:57 +0000 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6G7msb0146035 for ; Mon, 16 Jul 2018 03:48:56 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k8pm49nw4-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 16 Jul 2018 03:48:55 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Jul 2018 08:48:53 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 16 Jul 2018 08:48:50 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6G7mnPX41943092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 16 Jul 2018 07:48:49 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D60C3AE057; Mon, 16 Jul 2018 10:49:06 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B9EE2AE059; Mon, 16 Jul 2018 10:49:06 +0100 (BST) Received: from white.boeblingen.de.ibm.com (unknown [9.152.97.127]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 16 Jul 2018 10:49:06 +0100 (BST) From: Ilya Leoshkevich To: gcc-patches@gcc.gnu.org Cc: krebbel@linux.ibm.com, Ilya Leoshkevich Subject: [PATCH 2/3] S/390: Implement -mrecord-mcount Date: Mon, 16 Jul 2018 09:48:06 +0200 In-Reply-To: <20180716074807.43653-1-iii@linux.ibm.com> References: <20180716074807.43653-1-iii@linux.ibm.com> x-cbid: 18071607-0012-0000-0000-0000028A9684 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18071607-0013-0000-0000-000020BC4D78 Message-Id: <20180716074807.43653-3-iii@linux.ibm.com> This is the counterpart of the i386 feature introduced by 39a5a6a4: Add direct support for Linux kernel __fentry__ patching. * gcc/config/s390/s390.c (s390_function_profiler): Generate __mcount_loc section. * gcc/config/s390/s390.opt: Add the new option. * gcc/testsuite/gcc.target/s390/mrecord-mcount.c: New testcase. --- gcc/config/s390/s390.c | 10 ++++++++++ gcc/config/s390/s390.opt | 4 ++++ gcc/testsuite/gcc.target/s390/mrecord-mcount.c | 10 ++++++++++ 3 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/gcc.target/s390/mrecord-mcount.c diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index 3a406b955a0..600501c1e27 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -13151,6 +13151,9 @@ s390_function_profiler (FILE *file, int labelno) op[4] = gen_rtx_CONST (Pmode, op[4]); } + if (flag_record_mcount) + fprintf (file, "1:\n"); + if (flag_fentry) { if (cfun->static_chain_decl) @@ -13204,6 +13207,13 @@ s390_function_profiler (FILE *file, int labelno) output_asm_insn ("basr\t%0,%0", op); output_asm_insn ("l\t%0,%1", op); } + + if (flag_record_mcount) + { + fprintf (file, "\t.section __mcount_loc, \"a\",@progbits\n"); + fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long"); + fprintf (file, "\t.previous\n"); + } } /* Encode symbol attributes (local vs. global, tls model) of a SYMBOL_REF diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt index 59e97d031b4..9a3ed651450 100644 --- a/gcc/config/s390/s390.opt +++ b/gcc/config/s390/s390.opt @@ -298,3 +298,7 @@ mfentry Target Report Var(flag_fentry) Emit profiling counter call at function entry before prologue. The compiled code will require a 64-bit CPU and glibc 2.29 or newer to run. + +mrecord-mcount +Target Report Var(flag_record_mcount) +Generate __mcount_loc section with all _mcount and __fentry__ calls. diff --git a/gcc/testsuite/gcc.target/s390/mrecord-mcount.c b/gcc/testsuite/gcc.target/s390/mrecord-mcount.c new file mode 100644 index 00000000000..d8a23ffdca4 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/mrecord-mcount.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-pg -mrecord-mcount" } */ + +void +profileme (void) +{ + /* { dg-final { scan-assembler ".section __mcount_loc, \"a\",@progbits" } } */ + /* { dg-final { scan-assembler ".quad 1b" } } */ + /* { dg-final { scan-assembler ".previous" } } */ +} From patchwork Mon Jul 16 07:48:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 944172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481590-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="a/FYUAjr"; dkim-atps=neutral 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 41TbD115Qxz9s9N for ; Mon, 16 Jul 2018 17:49:52 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:in-reply-to:references:message-id; q=dns; s= default; b=Fjsgtpg2JdQp88jbciVJ5IaOfQYVgyQQWxuj6BEkTVvjeCW+Xj+nz K9v+6z2dGu6xnz+IwKsb/EPyK/LMk80DM2mSpHjan5zLvHU7mNvU0Vfk+srRzt2U 6i8A3y3YlEPTYhf4s0tp8elmufqsWRgktU/1ctManuJj/p+Ty5QzfI= 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:from :to:cc:subject:date:in-reply-to:references:message-id; s= default; bh=uB2tCXHSDD+WH07A7GoGHUVAvEU=; b=a/FYUAjrfnlB/N/Chh4t 5GjjWXYJ4Ly9FivtlKjFgGA23xl8UgR29lM16RMJzz0ZHfdqsRV9znrjjRSeNIUp 4tPHlz3FHZfFJa2TaaOlR4RB+Z/EWuUuNHG10HhKjEdvOyEWWLMypdih+QkWHXjO 0JUZJ3klCkFKlm76SnG+5TM= Received: (qmail 43105 invoked by alias); 16 Jul 2018 07:49:12 -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 42933 invoked by uid 89); 16 Jul 2018 07:49:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=bras, m31, consists X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jul 2018 07:49:08 +0000 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6G7n4pF135092 for ; Mon, 16 Jul 2018 03:49:07 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k8gg6whhs-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 16 Jul 2018 03:49:06 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Jul 2018 08:48:57 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 16 Jul 2018 08:48:54 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6G7mqMb32833598 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 16 Jul 2018 07:48:52 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8001FAE056; Mon, 16 Jul 2018 10:49:10 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 542FCAE04D; Mon, 16 Jul 2018 10:49:10 +0100 (BST) Received: from white.boeblingen.de.ibm.com (unknown [9.152.97.127]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 16 Jul 2018 10:49:10 +0100 (BST) From: Ilya Leoshkevich To: gcc-patches@gcc.gnu.org Cc: krebbel@linux.ibm.com, Ilya Leoshkevich Subject: [PATCH 3/3] S/390: Implement -mnop-mcount Date: Mon, 16 Jul 2018 09:48:07 +0200 In-Reply-To: <20180716074807.43653-1-iii@linux.ibm.com> References: <20180716074807.43653-1-iii@linux.ibm.com> x-cbid: 18071607-4275-0000-0000-0000029967C0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18071607-4276-0000-0000-000037A17923 Message-Id: <20180716074807.43653-4-iii@linux.ibm.com> This is the counterpart of the i386 feature introduced by 39a5a6a4: Add direct support for Linux kernel __fentry__ patching. On i386 the profiler call sequence always consists of 1 call instruction, so -mnop-mcount generates a single nop with the same length as a call. For S/390 longer sequences may be used in some cases, so -mnop-mcount generates the corresponding amount of nops. * gcc/config/s390/s390.c (s390_function_profiler): Generate nops instead of profiler call sequences. * gcc/config/s390/s390.opt: Add the new option. * gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c: New testcase. * gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c New testcase. * gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c New testcase. * gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c New testcase. * gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c New testcase. --- gcc/config/s390/s390.c | 113 +++++++++++++----- gcc/config/s390/s390.opt | 5 + .../gcc.target/s390/mnop-mcount-m31-fpic.c | 8 ++ .../gcc.target/s390/mnop-mcount-m31-mzarch.c | 8 ++ .../gcc.target/s390/mnop-mcount-m31.c | 8 ++ .../gcc.target/s390/mnop-mcount-m64-mfentry.c | 8 ++ .../gcc.target/s390/mnop-mcount-m64.c | 8 ++ 7 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c create mode 100644 gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index 600501c1e27..ba18cb1c39a 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -13123,6 +13123,30 @@ s390_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt) emit_move_insn (mem, fnaddr); } +static void +output_asm_nops (const char *user, int hw) +{ + asm_fprintf (asm_out_file, "\t# NOPs for %s (%d halfwords)\n", user, hw); + while (hw > 0) + { + if (TARGET_CPU_ZARCH && hw >= 3) + { + output_asm_insn ("brcl\t0,0", NULL); + hw -= 3; + } + else if (hw >= 2) + { + output_asm_insn ("bc\t0,0", NULL); + hw -= 2; + } + else + { + output_asm_insn ("bcr\t0,0", NULL); + hw -= 1; + } + } +} + /* Output assembler code to FILE to increment profiler label # LABELNO for profiling a function entry. */ @@ -13156,7 +13180,9 @@ s390_function_profiler (FILE *file, int labelno) if (flag_fentry) { - if (cfun->static_chain_decl) + if (flag_nop_mcount) + output_asm_nops ("-mnop-mcount", /* brasl */ 3); + else if (cfun->static_chain_decl) warning (OPT_Wcannot_profile, "nested functions cannot be profiled " "with -mfentry on s390"); else @@ -13164,48 +13190,77 @@ s390_function_profiler (FILE *file, int labelno) } else if (TARGET_64BIT) { - output_asm_insn ("stg\t%0,%1", op); - output_asm_insn ("larl\t%2,%3", op); - output_asm_insn ("brasl\t%0,%4", op); - output_asm_insn ("lg\t%0,%1", op); + if (flag_nop_mcount) + output_asm_nops ("-mnop-mcount", /* stg */ 3 + /* larl */ 3 + + /* brasl */ 3 + /* lg */ 3); + else + { + output_asm_insn ("stg\t%0,%1", op); + output_asm_insn ("larl\t%2,%3", op); + output_asm_insn ("brasl\t%0,%4", op); + output_asm_insn ("lg\t%0,%1", op); + } } else if (TARGET_CPU_ZARCH) { - output_asm_insn ("st\t%0,%1", op); - output_asm_insn ("larl\t%2,%3", op); - output_asm_insn ("brasl\t%0,%4", op); - output_asm_insn ("l\t%0,%1", op); + if (flag_nop_mcount) + output_asm_nops ("-mnop-mcount", /* st */ 2 + /* larl */ 3 + + /* brasl */ 3 + /* l */ 2); + else + { + output_asm_insn ("st\t%0,%1", op); + output_asm_insn ("larl\t%2,%3", op); + output_asm_insn ("brasl\t%0,%4", op); + output_asm_insn ("l\t%0,%1", op); + } } else if (!flag_pic) { op[6] = gen_label_rtx (); - output_asm_insn ("st\t%0,%1", op); - output_asm_insn ("bras\t%2,%l6", op); - output_asm_insn (".long\t%4", op); - output_asm_insn (".long\t%3", op); - targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (op[6])); - output_asm_insn ("l\t%0,0(%2)", op); - output_asm_insn ("l\t%2,4(%2)", op); - output_asm_insn ("basr\t%0,%0", op); - output_asm_insn ("l\t%0,%1", op); + if (flag_nop_mcount) + output_asm_nops ("-mnop-mcount", /* st */ 2 + /* bras */ 2 + + /* .long */ 2 + /* .long */ 2 + /* l */ 2 + + /* l */ 2 + /* basr */ 1 + /* l */ 2); + else + { + output_asm_insn ("st\t%0,%1", op); + output_asm_insn ("bras\t%2,%l6", op); + output_asm_insn (".long\t%4", op); + output_asm_insn (".long\t%3", op); + targetm.asm_out.internal_label (file, "L", + CODE_LABEL_NUMBER (op[6])); + output_asm_insn ("l\t%0,0(%2)", op); + output_asm_insn ("l\t%2,4(%2)", op); + output_asm_insn ("basr\t%0,%0", op); + output_asm_insn ("l\t%0,%1", op); + } } else { op[5] = gen_label_rtx (); op[6] = gen_label_rtx (); - output_asm_insn ("st\t%0,%1", op); - output_asm_insn ("bras\t%2,%l6", op); - targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (op[5])); - output_asm_insn (".long\t%4-%l5", op); - output_asm_insn (".long\t%3-%l5", op); - targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (op[6])); - output_asm_insn ("lr\t%0,%2", op); - output_asm_insn ("a\t%0,0(%2)", op); - output_asm_insn ("a\t%2,4(%2)", op); - output_asm_insn ("basr\t%0,%0", op); - output_asm_insn ("l\t%0,%1", op); + if (flag_nop_mcount) + output_asm_nops ("-mnop-mcount", /* st */ 2 + /* bras */ 2 + + /* .long */ 2 + /* .long */ 2 + /* lr */ 1 + + /* a */ 2 + /* a */ 2 + /* basr */ 1 + /* l */ 2); + else + { + output_asm_insn ("st\t%0,%1", op); + output_asm_insn ("bras\t%2,%l6", op); + targetm.asm_out.internal_label (file, "L", + CODE_LABEL_NUMBER (op[5])); + output_asm_insn (".long\t%4-%l5", op); + output_asm_insn (".long\t%3-%l5", op); + targetm.asm_out.internal_label (file, "L", + CODE_LABEL_NUMBER (op[6])); + output_asm_insn ("lr\t%0,%2", op); + output_asm_insn ("a\t%0,0(%2)", op); + output_asm_insn ("a\t%2,4(%2)", op); + output_asm_insn ("basr\t%0,%0", op); + output_asm_insn ("l\t%0,%1", op); + } } if (flag_record_mcount) diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt index 9a3ed651450..4214b1714c2 100644 --- a/gcc/config/s390/s390.opt +++ b/gcc/config/s390/s390.opt @@ -302,3 +302,8 @@ code will require a 64-bit CPU and glibc 2.29 or newer to run. mrecord-mcount Target Report Var(flag_record_mcount) Generate __mcount_loc section with all _mcount and __fentry__ calls. + +mnop-mcount +Target Report Var(flag_nop_mcount) +Generate mcount/__fentry__ calls as nops. To activate they need to be +patched in. diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c new file mode 100644 index 00000000000..5b00ab65668 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-fpic.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-m31 -mesa -march=g5 -fPIC -pg -mnop-mcount -Wno-deprecated" } */ + +void +profileme (void) +{ + /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(16 halfwords\\)\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0" } } */ +} diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c new file mode 100644 index 00000000000..b2ad9f5bced --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31-mzarch.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-m31 -mzarch -pg -mnop-mcount" } */ + +void +profileme (void) +{ + /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(10 halfwords\\)\n.*brcl\t0,0\n.*brcl\t0,0\n.*brcl\t0,0\n.*bcr\t0,0" } } */ +} diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c new file mode 100644 index 00000000000..e64c8d7d7bc --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m31.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-m31 -mesa -march=g5 -pg -mnop-mcount -Wno-deprecated" } */ + +void +profileme (void) +{ + /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(15 halfwords\\)\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bc\t0,0\n.*bcr\t0,0" } } */ +} diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c new file mode 100644 index 00000000000..9c1504e8d63 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m64-mfentry.c @@ -0,0 +1,8 @@ +/* { dg-do compile { target { lp64 } } } */ +/* { dg-options "-pg -mfentry -mnop-mcount" } */ + +void +profileme (void) +{ + /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(3 halfwords\\)\n.*brcl\t0,0" } } */ +} diff --git a/gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c b/gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c new file mode 100644 index 00000000000..c0e3c4e91b1 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/mnop-mcount-m64.c @@ -0,0 +1,8 @@ +/* { dg-do compile { target { lp64 } } } */ +/* { dg-options "-pg -mnop-mcount" } */ + +void +profileme (void) +{ + /* { dg-final { scan-assembler "NOPs for -mnop-mcount \\(12 halfwords\\)\n.*brcl\t0,0\n.*brcl\t0,0\n.*brcl\t0,0\n.*brcl\t0,0" } } */ +}