From patchwork Mon Nov 5 00:02:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 992814 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-488990-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=firstfloor.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Q9v3m8dL"; dkim=pass (1024-bit key; unprotected) header.d=firstfloor.org header.i=@firstfloor.org header.b="MS2JPQ5o"; 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 42pCYq1HJtzB6PX for ; Mon, 5 Nov 2018 11:03:10 +1100 (AEDT) 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:message-id:in-reply-to:references :mime-version:content-transfer-encoding; q=dns; s=default; b=VPK VhBt+Uag2IDafaa2bB+w2LocwpzpIFv9k1KSjEPsNplY1+vShrEE8H0jZFrchtKX CTlHdPy+3SG/9lEgKNdMga4bw1H6uGGR8IgooE+bqlgXSDF8LhdkWFb1H/gnpcOr dqWgUWW8HOaFghF9nc7CjE9FYbU6YkhJvrw/rCFY= 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:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=default; bh=2YiBil7w9 ZRiLu27xNcepTRGQ0Y=; b=Q9v3m8dLcEqKSt31OTquNlqSEjNrjAgFMutUq6kyN Mzp+iBZFpoX2f9hjZiMIPp2xB1v7c289BYLK948JEeG3b4zbyqomuZLNovk+erOZ psCPt0lcARuCzeKAt3VcHqHiaRiiHCgInR6lLK7qaD56ILUo6brc8k03Dx5AMTVv /E= Received: (qmail 70432 invoked by alias); 5 Nov 2018 00:02:42 -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 70264 invoked by uid 89); 5 Nov 2018 00:02:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=mx32, flexibility, patched X-HELO: one.firstfloor.org Received: from one.firstfloor.org (HELO one.firstfloor.org) (193.170.194.197) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Nov 2018 00:02:37 +0000 Received: from firstfloor.org (c-71-238-43-142.hsd1.or.comcast.net [71.238.43.142]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by one.firstfloor.org (Postfix) with ESMTPSA id 0650086861; Mon, 5 Nov 2018 01:02:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=firstfloor.org; s=mail; t=1541376154; bh=hoMXDPXJEdkgo5oLBCXFuI/s4ogogkrvf/c2OxCTImE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MS2JPQ5oaFVBP+IprlCSOmhizUEgDVQKS5cXPkDVFW0gwESe4Wr1yyqfVVJpAUaWL 2Il7VZEAKoNQ+o2ipW2uc5lw0zYX8xieZVV1Ux7CapIfb8zvQZL7FRg0lCcO/0MfyU zYCOMVETPJxjWy4VleG05lLWCSZf9koubH43UO28= Received: by firstfloor.org (Postfix, from userid 1000) id C6FD4A0727; Sun, 4 Nov 2018 16:02:30 -0800 (PST) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH 2/3] Support changing fentry name per function Date: Sun, 4 Nov 2018 16:02:20 -0800 Message-Id: <20181105000221.32180-2-andi@firstfloor.org> In-Reply-To: <20181105000221.32180-1-andi@firstfloor.org> References: <20181105000221.32180-1-andi@firstfloor.org> MIME-Version: 1.0 From: Andi Kleen It can be useful to have some classes of functions that use a different __fentry__ instrumentation than others. Currently it is only possible to disable instrumentation on the command line or with no_instrument_function, but not to change the instrumentation function on a case by case base. Add some flexibility to allow to change the instrumentation function name per file with an option or per function with a new attribute. This also allows switching to nops for individual functions. gcc/: 2018-11-04 Andi Kleen * config/i386/i386.c (x86_print_call_or_nop): Handle nop name. (current_fentry_name): Add. (x86_function_profiler): Handle fentry_name attribute. (ix86_handle_fentry_name): Add. (ix86_attribute_table): Add fentry_name. * config/i386/i386.opt: Add -mfentry-name * doc/extend.texi: Document fentry_name. * doc/invoke.texi: Document minstrument-return. gcc/testsuite/: 2018-11-04 Andi Kleen * gcc.target/i386/fentryname1.c: New test. --- gcc/config/i386/i386.c | 48 ++++++++++++++++++--- gcc/config/i386/i386.opt | 4 ++ gcc/doc/extend.texi | 7 +++ gcc/doc/invoke.texi | 6 ++- gcc/testsuite/gcc.target/i386/fentryname1.c | 15 +++++++ 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/fentryname1.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index f7cd94a8139..8af8a523cb3 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -41206,24 +41206,41 @@ x86_field_alignment (tree type, int computed) static void x86_print_call_or_nop (FILE *file, const char *target) { - if (flag_nop_mcount) + if (flag_nop_mcount || !strcmp (target, "nop")) /* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */ fprintf (file, "1:" ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n"); else fprintf (file, "1:\tcall\t%s\n", target); } +static bool +current_fentry_name (const char **name) +{ + tree attr = lookup_attribute ("fentry_name", + DECL_ATTRIBUTES (current_function_decl)); + if (!attr) + return false; + *name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); + return true; +} + /* Output assembler code to FILE to increment profiler label # LABELNO for profiling a function entry. */ void x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED) { - const char *mcount_name = (flag_fentry ? MCOUNT_NAME_BEFORE_PROLOGUE - : MCOUNT_NAME); - if (cfun->machine->endbr_queued_at_entrance) fprintf (file, "\t%s\n", TARGET_64BIT ? "endbr64" : "endbr32"); + const char *mcount_name = MCOUNT_NAME; + + if (current_fentry_name (&mcount_name)) + ; + else if (fentry_name) + mcount_name = fentry_name; + else if (flag_fentry) + mcount_name = MCOUNT_NAME_BEFORE_PROLOGUE; + if (TARGET_64BIT) { #ifndef NO_PROFILE_COUNTERS @@ -45044,6 +45061,26 @@ ix86_expand_round_sse4 (rtx op0, rtx op1) emit_move_insn (op0, res); } + +/* Handle fentry_name attribute. */ + +static tree +ix86_handle_fentry_name (tree *node, tree name, tree args, + int, bool *no_add_attrs) +{ + if (TREE_CODE (*node) == FUNCTION_DECL + && TREE_CODE (TREE_VALUE (args)) == STRING_CST) + /* Do nothing else, just set the attribute. We'll get at + it later with lookup_attribute. */ + ; + else + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} /* Table of valid machine attributes. */ @@ -45120,7 +45157,8 @@ static const struct attribute_spec ix86_attribute_table[] = ix86_handle_fndecl_attribute, NULL }, { "indirect_return", 0, 0, false, true, true, false, NULL, NULL }, - + { "fentry_name", 1, 1, true, false, false, false, + ix86_handle_fentry_name, NULL }, /* End element. */ { NULL, 0, 0, false, false, false, false, NULL, NULL } }; diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index 5925b75244f..e56f9bce9b0 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -930,6 +930,10 @@ Target Report Var(flag_nop_mcount) Generate mcount/__fentry__ calls as nops. To activate they need to be patched in. +mfentry-name= +Target RejectNegative Joined Var(fentry_name) +Set name of __fentry__ symbol called at function entry. + mskip-rax-setup Target Report Var(flag_skip_rax_setup) Skip setting up RAX register when passing variable arguments. diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 924037ff586..c8761cda151 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -5966,6 +5966,13 @@ The @code{indirect_return} attribute can be applied to a function, as well as variable or type of function pointer to inform the compiler that the function may return via indirect branch. +@item fentry_name("@var{name}") +@cindex @code{fentry_name} function attribute, x86 +On x86 targets, the @code{fentry_name} attribute sets the function to +call on function entry when function instrumentation is enabled +with @option{-pg -mfentry}. When @var{name} is nop then a 5 byte +nop sequence is generated. + @end table On the x86, the inliner does not inline a diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 939be3e251b..aaa4a596a31 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1301,7 +1301,7 @@ See RS/6000 and PowerPC Options. -mcmodel=@var{code-model} -mabi=@var{name} -maddress-mode=@var{mode} @gol -m32 -m64 -mx32 -m16 -miamcu -mlarge-data-threshold=@var{num} @gol -msse2avx -mfentry -mrecord-mcount -mnop-mcount -m8bit-idiv @gol --minstrument-return=@var{type} @gol +-minstrument-return=@var{type} -mfentry-name=@var{name} @gol -mavx256-split-unaligned-load -mavx256-split-unaligned-store @gol -malign-data=@var{type} -mstack-protector-guard=@var{guard} @gol -mstack-protector-guard-reg=@var{reg} @gol @@ -28456,6 +28456,10 @@ or @var{nop5} to generate a 5 byte nop. @opindex mrecord-return Generate a __return_loc section pointing to all return instrumentation code. +@item -mfentry-name=@var{name} +@opindex mfentry-name +Set name of __fentry__ symbol called at function entry for -pg -mfentry functions. + @item -mskip-rax-setup @itemx -mno-skip-rax-setup @opindex mskip-rax-setup diff --git a/gcc/testsuite/gcc.target/i386/fentryname1.c b/gcc/testsuite/gcc.target/i386/fentryname1.c new file mode 100644 index 00000000000..6d2e76d223a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/fentryname1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-pg -mfentry -mfentry-name=foo" } */ +/* { dg-final { scan-assembler "call.*foo" } } */ +/* { dg-final { scan-assembler "call.*bar" } } */ + +int func(int a) +{ + return a+1; +} + +__attribute__((fentry_name("bar"))) +int func2(int a) +{ + return a+1; +}