From patchwork Wed Oct 31 10:37:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 196067 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]) by ozlabs.org (Postfix) with SMTP id 11A2B2C021D for ; Thu, 1 Nov 2012 12:17:55 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352337476; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: From:To:Cc:Subject:Date:Message-Id:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=xUVwumQ9CmPeKnq4ntaqhOtyb98=; b=W6cIwINSLBPYgQk tTEwLVuu+H/GPYjgwNocBsUm3w7B0CtEfpBX4mt9cRI5uNJLB/9MYUQY9fP6f8sX osMkJs3qbAewr5wCxpeEmaSp4+FKrm7mlOXo1m7xdgZLZyD0o2YniqVmKdzHKcrX WpHzGgCj+VsRiSa/SBNkoCKr8l98= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=LxD7WXQB45bbgcENPE+OaBCLk4Q1GhQpFYsIWGW1OW0KyCzV8FB66//BZJ7oeT 9P6kd6aGDjO2HA4BlALtMQDRv6SOBNShPdOLhufhTPOlJligwoAQ02rW0wpVByr2 1JOPvqNYT9uSndUIKUE+deAFY4qs/tgEKe/WwWdD5b3yw=; Received: (qmail 24748 invoked by alias); 1 Nov 2012 01:17:51 -0000 Received: (qmail 24726 invoked by uid 22791); 1 Nov 2012 01:17:50 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from one.firstfloor.org (HELO one.firstfloor.org) (213.235.205.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Nov 2012 01:17:42 +0000 Received: from basil.firstfloor.org (71-222-29-29.ptld.qwest.net [71.222.29.29]) by one.firstfloor.org (Postfix) with ESMTP id DC23A1A9806D; Thu, 1 Nov 2012 02:17:38 +0100 (CET) Received: by basil.firstfloor.org (Postfix, from userid 1000) id F421FB15DA; Wed, 31 Oct 2012 03:37:36 -0700 (PDT) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH] Add -fno-instrument-function Date: Wed, 31 Oct 2012 03:37:31 -0700 Message-Id: <1351679851-4522-1-git-send-email-andi@firstfloor.org> 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 From: Andi Kleen This adds a new C/C++ option to force __attribute__((no_instrument_function)) on every function compiled. This is useful together with LTO. You may want to have the whole program compiled with -pg and have to specify that in the LTO link, but want to disable it for some specific files. As the option works on the frontend level it is already passed through properly by LTO. Without LTO it is equivalent to not specifing -pg or -mfentry. This fixes some missing functionality in the Linux kernel LTO port. Passed bootstrap and test suite on x86_64-linux. Ok? gcc/: 2012-10-31 Andi Kleen * c.opt (fno-instrument-function): Document. gcc/c: 2012-10-31 Andi Kleen * c-decl.c (start_function): Handle force_no_instrument_function gcc/testsuite: 2012-10-31 Andi Kleen * g++.dg/fno-instrument-function.C: Add. * gcc.dg/fno-instrument-function.c: Add. --- gcc/c-family/c.opt | 4 ++++ gcc/c/c-decl.c | 3 +++ gcc/doc/invoke.texi | 8 +++++++- gcc/testsuite/g++.dg/fno-instrument-function.C | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/fno-instrument-function.c | 24 ++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/fno-instrument-function.C create mode 100644 gcc/testsuite/gcc.dg/fno-instrument-function.c diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 7eb66c6..62dfc57 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -967,6 +967,10 @@ fnil-receivers ObjC ObjC++ Var(flag_nil_receivers) Init(1) Assume that receivers of Objective-C messages may be nil +fno-instrument-function +C C++ ObjC ObjC++ RejectNegative Report Var(force_no_instrument_function) +Force __attribute__((no_instrument_function)) for all functions in translation unit. + fnonansi-builtins C++ ObjC++ Var(flag_no_nonansi_builtin, 0) diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 80867ca..fe957ab 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -7875,6 +7875,9 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, if (current_scope == file_scope) maybe_apply_pragma_weak (decl1); + if (force_no_instrument_function) + DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl1) = 1; + /* Warn for unlikely, improbable, or stupid declarations of `main'. */ if (warn_main && MAIN_NAME_P (DECL_NAME (decl1))) { diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 15ecaf1..dbabc72 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -174,7 +174,7 @@ in the following sections. -aux-info @var{filename} -fallow-parameterless-variadic-functions @gol -fno-asm -fno-builtin -fno-builtin-@var{function} @gol -fhosted -ffreestanding -fopenmp -fms-extensions -fplan9-extensions @gol --trigraphs -traditional -traditional-cpp @gol +-trigraphs -traditional -traditional-cpp -fno-instrument-function @gol -fallow-single-precision -fcond-mismatch -flax-vector-conversions @gol -fsigned-bitfields -fsigned-char @gol -funsigned-bitfields -funsigned-char} @@ -1858,6 +1858,12 @@ Allow implicit conversions between vectors with differing numbers of elements and/or incompatible element types. This option should not be used for new code. +@item -fno-instrument-function +@opindex fno-instrument-function +Override @option{-pg} for this translation unit. This is useful with +Link Time Optimization (LTO) to override the effects of -pg for a +specific source file. + @item -funsigned-char @opindex funsigned-char Let the type @code{char} be unsigned, like @code{unsigned char}. diff --git a/gcc/testsuite/g++.dg/fno-instrument-function.C b/gcc/testsuite/g++.dg/fno-instrument-function.C new file mode 100644 index 0000000..b15cd94 --- /dev/null +++ b/gcc/testsuite/g++.dg/fno-instrument-function.C @@ -0,0 +1,18 @@ +/* Test -fno-instrument-function */ +/* { dg-do compile } */ +/* { dg-options "-fno-instrument-function" } */ +/* { dg-final { scan-assembler-not "mcount" } } */ +/* Origin: Andi Kleen */ +extern void foobar(const char *); + +void func(void) +{ + foobar ("Hello world\n"); +} + +void func2(void) +{ + int i; + for (i = 0; i < 10; i++) + foobar ("Hello world"); +} diff --git a/gcc/testsuite/gcc.dg/fno-instrument-function.c b/gcc/testsuite/gcc.dg/fno-instrument-function.c new file mode 100644 index 0000000..4fafe4f --- /dev/null +++ b/gcc/testsuite/gcc.dg/fno-instrument-function.c @@ -0,0 +1,24 @@ +/* Test -fno-instrument-function */ +/* { dg-do compile } */ +/* { dg-options "-fno-instrument-function" } */ +/* { dg-final { scan-assembler-not "mcount" } } */ +/* Origin: Andi Kleen */ +extern void foobar(char *); + +void func(void) +{ + foobar ("Hello world\n"); +} + +void func2(void) +{ + int i; + for (i = 0; i < 10; i++) + foobar ("Hello world"); +} + +void func3(a) +char *a; +{ + foobar("Hello world"); +}