From patchwork Thu Jul 3 00:20:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teresa Johnson X-Patchwork-Id: 366511 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 DA7DB1400B0 for ; Thu, 3 Jul 2014 10:20:58 +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:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=vZ5NKpEf6c+evwm+Jg PDDiadPRxeu1IfVEH7Yw4ALPqsb0ljiw0EU8NTw2KC453jCwp5rgSYljPh6W/FWm rMUUpXJcCGk3cJ5V4tRyfJy1J7QxQAl4WmUJhKUA7F5JEoT+CUIee9P7S+lGNP3Z a7yYp+P3OO/dbWVAv/v+zxit0= 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:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=JIDEMh2VkhMWXRc3RAiZtTQ9 o4c=; b=K1e1biwscAkUJIpz0eExX3WLCbORFEF/zGI43HQV8Yt6bozF6YG2TgUA YagqCIjzexzyrnptnO+hO4pSBhv/O/tE86+9rPTDiIrX5b3LLkcFeVgyqP8x6QNh Jzxi8CP2fgUjz7nZg3pA5MoVIA491LnOhWsDdEYkDpshvCRHKnc= Received: (qmail 26354 invoked by alias); 3 Jul 2014 00:20:49 -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 26213 invoked by uid 89); 3 Jul 2014 00:20:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-qg0-f53.google.com Received: from mail-qg0-f53.google.com (HELO mail-qg0-f53.google.com) (209.85.192.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 03 Jul 2014 00:20:41 +0000 Received: by mail-qg0-f53.google.com with SMTP id i50so5544910qgf.12 for ; Wed, 02 Jul 2014 17:20:38 -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:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=wljTDM6ho9wI8DZ4kAfVs51VMjf60v5fSunxSCGPA70=; b=Wkxd+OQhQDxWe7fTPgizvXN1/RlHfM9m76z8UPBVHEvkMzI+cWPTkH9nIYRFUf2zCw ntfaLIV1vx3nVmedHjVQ1tgTL7snxOgG17vNjKMMDZfGy5bL/YkiqHM/rfUP15C6KiuE x6gudE8WNjCtVYfC3cnKwnjt5j8bSexEnKynLjvGkOuK4wwVwZyDSalUfPjAytDhqMbC p1xwo1YLEzv5WoEt+z5kcec8fd8ev6LOTAOuGUj0IV4jN24k6th7goylHtPqq+oZZPNH yBFZhJx3Lyrc2b0+ffcqmf5R6xAmjqtMOb9mWbHqr5vSOswfrqSyUltrI2Muj/H0LEMd MWNA== X-Gm-Message-State: ALoCoQkoCdhxWXbJmZgPHi0MLIbrdZaKUn5J6HvSyBJ+FeFgucH1ukoXaF+n3DxK6wN6dndi6EO5 MIME-Version: 1.0 X-Received: by 10.224.98.145 with SMTP id q17mr1740673qan.97.1404346838811; Wed, 02 Jul 2014 17:20:38 -0700 (PDT) Received: by 10.229.156.5 with HTTP; Wed, 2 Jul 2014 17:20:38 -0700 (PDT) In-Reply-To: References: Date: Wed, 2 Jul 2014 17:20:38 -0700 Message-ID: Subject: Re: [GOOGLE] Define libgcov interface for distinguishing -ftest-coverage from -fprofile-generate From: Teresa Johnson To: Xinliang David Li Cc: "gcc-patches@gcc.gnu.org" X-IsSubscribed: yes New patch below. Retested. 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_for_test_coverage): New function. On Wed, Jul 2, 2014 at 1:25 PM, Xinliang David Li wrote: > The reason is that test coverage is using the same underlying > profiling. Returning false when calling '__gcov_profiling_enabled()) > in coverage mode is a little misleading. > > David > > On Wed, Jul 2, 2014 at 1:22 PM, Teresa Johnson wrote: >> On Wed, Jul 2, 2014 at 1:15 PM, Xinliang David Li wrote: >>> Should the interface be something like: >>> >>> int __gcov_profiling_for_test_coverage(void)? >> >> I was equating the term "profiling" with -fprofile-generate, as >> opposed to -ftest-coverage instrumentation. But I can change it to >> this if you think that is clearer. >> >> Teresa >> >>> >>> David >>> >>> >>> On Wed, Jul 2, 2014 at 12:55 PM, Teresa Johnson wrote: >>>> 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 >>>> >>>> >>>> -- >>>> Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413 >> >> >> >> -- >> Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413 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_for_test_coverage (void); +char *(*__gcov_dummy_ref7)(void) = &__gcov_profiling_for_test_coverage; /* 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_for_test_coverage (void); + +/* Function that can be called from application to distinguish binaries + instrumented for coverage from those instrumented for profile + optimization (e.g. -fprofile-generate). */ + +unsigned int __gcov_profiling_for_test_coverage (void) +{ + return __gcov_test_coverage; +} + #endif /* L_gcov_dump */ #ifdef L_gcov_sampling