From patchwork Wed Jul 2 19:55:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teresa Johnson X-Patchwork-Id: 366469 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 113E21400AB for ; Thu, 3 Jul 2014 05:56:03 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=RVJ/ODJqkRp1I9diW17tOCRAom1ME/viSaRbGTYVngKfCx GRlbFwlOTf+exLurdP7FcGp3hvbiDY85QNbKVRxmciy/KHkWQI2bX8/RjO+Z0Seq ee83OMRH59PKJfElxbBi/BLTFfR2cETqdp/xceBp36YWAEH8RQYUnQBpaG3Mo= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=LqPXlock8dggbGPR18iVhN63IHI=; b=TxKxP+enAtcon9NrC7qE l1wyDU/2N9LMcdNxFz95M+50jdnhUenLPzDz1sLAawWFYHAbF/pfBacVOY2ombS7 hxzbBPV277i0hyeJXr/XbDA15sQF860l3hUZ8Jgp9achP57HnWSB0wFokZyCFRrk fVGeR+/xxKJVPI1Qfj+r3ag= Received: (qmail 24039 invoked by alias); 2 Jul 2014 19:55:56 -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 24020 invoked by uid 89); 2 Jul 2014 19:55:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-qa0-f49.google.com Received: from mail-qa0-f49.google.com (HELO mail-qa0-f49.google.com) (209.85.216.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 02 Jul 2014 19:55:51 +0000 Received: by mail-qa0-f49.google.com with SMTP id w8so9262957qac.8 for ; Wed, 02 Jul 2014 12:55:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=nbNGuOZqSUL22DXkuaFGCQQaXo67bwlvq/H2OoxklXo=; b=TZqTDDz05YcgqdeS+/Vra0f7po14t3cfSCa3WGZjE/Fzv4t8VyTUIsaZBq7BRFfrEz ONzzpsdh3fwBXyM3ZJdb9xVNKN2Sf88WXDUbiwTdTq2lpdNTe4sU/CCOHsnr/ga7JX5Q fVGLbfKlaPElMlmJFfCNX1Q2gA7BKD8O6PWahErF36dMdziq1TzpF31f5iJOUkTblB4n s7pGWxFw7HrwG0qGd9LS21rhonRgAry4yv4XKnElCk9z6e0SWXSThqsJEDqj7yscpXyv 9o77mmCyzBS2rEnJQtatRjIJZu++5uFnkanR4B14hU8Z/+oEU5bvpqumCeke7rXMjTyP IWAQ== X-Gm-Message-State: ALoCoQlNWGWBxpBIemkKWfK6+b2oZ+H5/reIDpPf9uoTH/yyS7lXAGebTy5z6n+wojCYjJe8VO+t MIME-Version: 1.0 X-Received: by 10.224.2.196 with SMTP id 4mr191617qak.60.1404330948947; Wed, 02 Jul 2014 12:55:48 -0700 (PDT) Received: by 10.229.156.5 with HTTP; Wed, 2 Jul 2014 12:55:48 -0700 (PDT) Date: Wed, 2 Jul 2014 12:55:48 -0700 Message-ID: Subject: [GOOGLE] Define libgcov interface for distinguishing -ftest-coverage from -fprofile-generate From: Teresa Johnson To: "gcc-patches@gcc.gnu.org" , David Li X-IsSubscribed: yes The following patch adds support for a new libgcov interface, __gcov_profiling_enabled, that can be used by applications to determine whether a binary has been instrumented for test coverage or profile optimization. Passes regression tests and manual testing with different options. Ok for google branches? Thanks, Teresa 2014-07-02 Teresa Johnson Google ref b/15378201. * gcc/tree-profile.c (gcov_test_coverage_decl): Declare. (tree_init_instrumentation): Initialize gcov_test_coverage_decl. * libgcc/libgcov-driver.c (__gcov_dummy_ref7): Define. * libgcc/libgcov-interface.c (__gcov_profiling_enabled): New function. Index: gcc/tree-profile.c =================================================================== --- gcc/tree-profile.c (revision 212044) +++ gcc/tree-profile.c (working copy) @@ -164,6 +164,9 @@ static GTY(()) tree gcov_sample_counter_decl = NUL /* extern gcov_unsigned_t __gcov_profile_prefix */ static tree GTY(()) gcov_profile_prefix_decl = NULL_TREE; +/* extern gcov_unsigned_t __gcov_test_coverage */ +static tree GTY(()) gcov_test_coverage_decl = NULL_TREE; + /* extern gcov_unsigned_t __gcov_sampling_period */ static GTY(()) tree gcov_sampling_period_decl = NULL_TREE; @@ -498,6 +501,27 @@ tree_init_instrumentation (void) DECL_INITIAL (gcov_profile_prefix_decl) = prefix_ptr; varpool_finalize_decl (gcov_profile_prefix_decl); } + + if (!gcov_test_coverage_decl) + { + /* Initialize __gcov_test_coverage to 1 if -ftest-coverage + specified, 0 otherwise. Used by libgcov to determine whether + a binary was instrumented for coverage or profile optimization. */ + gcov_test_coverage_decl = build_decl ( + UNKNOWN_LOCATION, + VAR_DECL, + get_identifier ("__gcov_test_coverage"), + get_gcov_unsigned_t ()); + TREE_PUBLIC (gcov_test_coverage_decl) = 1; + DECL_ARTIFICIAL (gcov_test_coverage_decl) = 1; + DECL_COMDAT_GROUP (gcov_test_coverage_decl) + = DECL_ASSEMBLER_NAME (gcov_test_coverage_decl); + TREE_STATIC (gcov_test_coverage_decl) = 1; + DECL_INITIAL (gcov_test_coverage_decl) = build_int_cst ( + get_gcov_unsigned_t (), + flag_test_coverage ? 1 : 0); + varpool_finalize_decl (gcov_test_coverage_decl); + } } /* Initialization function for FDO sampling. */ Index: libgcc/libgcov-driver.c =================================================================== --- libgcc/libgcov-driver.c (revision 212044) +++ libgcc/libgcov-driver.c (working copy) @@ -79,6 +79,8 @@ extern unsigned int __gcov_sampling_enabled (void) char *(*__gcov_dummy_ref5)(void) = &__gcov_sampling_enabled; extern void __gcov_flush (void); char *(*__gcov_dummy_ref6)(void) = &__gcov_flush; +extern unsigned int __gcov_profiling_enabled (void); +char *(*__gcov_dummy_ref7)(void) = &__gcov_profiling_enabled; /* Default callback function for profile instrumentation callback. */ extern void __coverage_callback (gcov_type, int); Index: libgcc/libgcov-interface.c =================================================================== --- libgcc/libgcov-interface.c (revision 212044) +++ libgcc/libgcov-interface.c (working copy) @@ -116,6 +116,20 @@ __gcov_dump (void) set_gcov_dump_complete (); } +/* Emitted in coverage.c. */ +extern gcov_unsigned_t __gcov_test_coverage; + +unsigned int __gcov_profiling_enabled (void); + +/* Function that can be called from application to distinguish binaries + instrumented from coverage fro those instrumented for profiling + (e.g. -fprofile-generate). */ + +unsigned int __gcov_profiling_enabled (void) +{ + return !__gcov_test_coverage; +} + #endif /* L_gcov_dump */ #ifdef L_gcov_sampling