From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70287 invoked by alias); 5 Nov 2018 00:02:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 70266 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 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 08A4D86862; Mon, 5 Nov 2018 01:02:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=firstfloor.org; s=mail; t=1541376154; bh=WbLvk7enddjudldP8W32kFVwPd9ZotkjO2PT9GlpXbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UYxNs7M106F3w3WowxuTV/87do8Wemgw2Yd98OuLT+0/NiEEwyeRdtlGwSUiGGBdY +Wjd540EUBXkAN1aysLLvn7jDNIdTCSBd2nj7mZC7XLcBlPzvDzXPoh7QX3ekGqgzx /MNpRtQN5wwXWZcnyWgG6EOrch2fc4GCLd2t9Q9s= Received: by firstfloor.org (Postfix, from userid 1000) id CC81CA0729; Sun, 4 Nov 2018 16:02:30 -0800 (PST) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH 3/3] Allow changing the fentry section per file and per function Date: Mon, 05 Nov 2018 00:02:00 -0000 Message-Id: <20181105000221.32180-3-andi@firstfloor.org> In-Reply-To: <20181105000221.32180-2-andi@firstfloor.org> References: <20181105000221.32180-1-andi@firstfloor.org> <20181105000221.32180-2-andi@firstfloor.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SW-Source: 2018-11/txt/msg00190.txt.bz2 From: Andi Kleen When dynamically patching in/out instrumentation it can be useful to handle different classes of functions differently. Add support for changing the fentry section name on the command line or as a function attributes. This allows to mark functions differently, and handle them differently in dynamic patching. gcc/: 2018-11-04 Andi Kleen * config/i386/i386.c (current_fentry_section): Add. (x86_function_profiler): Handle fentry section. (ix86_attribute_table): Add fentry section. * config/i386/i386.opt: Add -mfentry-section. * doc/extend.texi: Document fentry_section attribute. * doc/invoke.texi: Document -mfentry-section. gcc/testsuite/: 2018-11-04 Andi Kleen * gcc.target/i386/fentryname2.c: New test. * gcc.target/i386/fentryname3.c: New test. --- gcc/config/i386/i386.c | 28 ++++++++++++++++++--- gcc/config/i386/i386.opt | 4 +++ gcc/doc/extend.texi | 6 +++++ gcc/doc/invoke.texi | 6 ++++- gcc/testsuite/gcc.target/i386/fentryname2.c | 15 +++++++++++ gcc/testsuite/gcc.target/i386/fentryname3.c | 10 ++++++++ 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/fentryname2.c create mode 100644 gcc/testsuite/gcc.target/i386/fentryname3.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 8af8a523cb3..56a54c7da18 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -41224,6 +41224,17 @@ current_fentry_name (const char **name) return true; } +static bool +current_fentry_section (const char **name) +{ + tree attr = lookup_attribute ("fentry_section", + 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 @@ -41269,9 +41280,18 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED) x86_print_call_or_nop (file, mcount_name); } - if (flag_record_mcount) + if (flag_record_mcount + || lookup_attribute ("fentry_section", + DECL_ATTRIBUTES (current_function_decl))) { - fprintf (file, "\t.section __mcount_loc, \"a\",@progbits\n"); + const char *sname = "__mcount_loc"; + + if (current_fentry_section (&sname)) + ; + else if (fentry_section) + sname = fentry_section; + + fprintf (file, "\t.section %s, \"a\",@progbits\n", sname); fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long"); fprintf (file, "\t.previous\n"); } @@ -45062,7 +45082,7 @@ ix86_expand_round_sse4 (rtx op0, rtx op1) emit_move_insn (op0, res); } -/* Handle fentry_name attribute. */ +/* Handle fentry_name / fentry_section attribute. */ static tree ix86_handle_fentry_name (tree *node, tree name, tree args, @@ -45159,6 +45179,8 @@ static const struct attribute_spec ix86_attribute_table[] = NULL, NULL }, { "fentry_name", 1, 1, true, false, false, false, ix86_handle_fentry_name, NULL }, + { "fentry_section", 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 e56f9bce9b0..e82aca5c882 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -934,6 +934,10 @@ mfentry-name= Target RejectNegative Joined Var(fentry_name) Set name of __fentry__ symbol called at function entry. +mfentry-section= +Target RejectNegative Joined Var(fentry_section) +Set name of section to record mrecord-mcount calls. + 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 c8761cda151..e9c7f0856b7 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -5973,6 +5973,12 @@ 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. +@item fentry_section("@var{name}") +@cindex @code{fentry_section} function attribute, x86 +On x86 targets, the @code{fentry_section} attribute sets the name +of the section to record function entry instrumentation calls in when +enabled with @option{-pg -mrecord-mcount} + @end table On the x86, the inliner does not inline a diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index aaa4a596a31..06741145769 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} -mfentry-name=@var{name} @gol +-minstrument-return=@var{type} -mfentry-name=@var{name} -mfentry-section=@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 @@ -28460,6 +28460,10 @@ Generate a __return_loc section pointing to all return instrumentation code. @opindex mfentry-name Set name of __fentry__ symbol called at function entry for -pg -mfentry functions. +@item -mfentry-section=@var{name} +@opindex mfentry-section +Set name of section to record -mrecord-mcount calls (default __mcount_loc). + @item -mskip-rax-setup @itemx -mno-skip-rax-setup @opindex mskip-rax-setup diff --git a/gcc/testsuite/gcc.target/i386/fentryname2.c b/gcc/testsuite/gcc.target/i386/fentryname2.c new file mode 100644 index 00000000000..7d102bfccbc --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/fentryname2.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-pg -mfentry -mrecord-mcount -mfentry-section=foo" } */ +/* { dg-final { scan-assembler "section.*foo" } } */ +/* { dg-final { scan-assembler "section.*bar" } } */ + +int func(int a) +{ + return a+1; +} + +__attribute__((fentry_section("bar"))) +int func2(int a) +{ + return a+1; +} diff --git a/gcc/testsuite/gcc.target/i386/fentryname3.c b/gcc/testsuite/gcc.target/i386/fentryname3.c new file mode 100644 index 00000000000..777f4e4b0ff --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/fentryname3.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-pg -mfentry" } */ +/* { dg-final { scan-assembler "section.*__entry_loc" } } */ +/* { dg-final { scan-assembler "0x0f, 0x1f, 0x44, 0x00, 0x00" } } */ +/* { dg-final { scan-assembler-not "__fentry__" } } */ + +__attribute__((fentry_name("nop"), fentry_section("__entry_loc"))) +void foo(void) +{ +} -- 2.19.1