From patchwork Tue May 29 09:32:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 921905 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-478636-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HgyvIXxb"; 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 40w7v93pszz9s0y for ; Tue, 29 May 2018 19:38:13 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=uKbLjTL+8A8JqZeS64K3Fqaf1YLB7qgkI6I1wEfJxt5T3xZFlf Xl6z3FAfQY28TrAfGIq6g9SuN6UUWAsxJ3h6rWx3G8LdWrv29l1+VRPCy/aopFQM t9YljJtRn34iB9uys0u8gKESRko/tV8QLS2dmYhkPTQ2F2wZNAccLGTiM= 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 :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=ps2qL/oPrKH/jpHaV5x1UCnYvTA=; b=HgyvIXxbJql8zCGWr+B7 /Sl1NRDGOsDFmEj3AOMX1HuaEOVzVZZpOIMQ7y8KxIvYTtiMDkewTROGEBzOGE3d UE1zixUA7EeF13QSnxCgtCP17udrWJQVIDi8R3RDZvO3JM5hXBCq8Q0Gzp3n5y6b d1rpvEs4wDnWKjzOhnCrL6w= Received: (qmail 49640 invoked by alias); 29 May 2018 09:34:47 -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 66798 invoked by uid 89); 29 May 2018 09:32:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.2 spammy=intentional, Files, deserves, stamp X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 May 2018 09:32:33 +0000 Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6B57DAF95; Tue, 29 May 2018 09:32:28 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] libgcov: report about a different timestamp (PR gcov-profile/85759). To: gcc-patches@gcc.gnu.org Cc: Nathan Sidwell Message-ID: <73474dc8-6b97-35ab-f0b2-b514fdf599e5@suse.cz> Date: Tue, 29 May 2018 11:32:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi. As showed twice in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85759 it's quite problematic when a profile data file is overwritten for a different compilation unit. I believe it's not intentional in most cases and it deserves an error message in libgcov. Moreover, to be really sure we don't break a profile, users should use GCOV_EXIT_AT_ERROR. Tested on gcov.exp on x86_64-linux-gnu. Ready to install after proper bootstrap? Thanks, Martin gcc/ChangeLog: 2018-05-29 Martin Liska PR gcov-profile/85759 * doc/gcov.texi: Document GCOV_ERROR_FILE and GCOV_EXIT_AT_ERROR env variables. libgcc/ChangeLog: 2018-05-29 Martin Liska PR gcov-profile/85759 * libgcov-driver-system.c (gcov_error): Introduce usage of GCOV_EXIT_AT_ERROR env. variable. * libgcov-driver.c (merge_one_data): Print error that we overwrite a gcov file with a different timestamp. --- gcc/doc/gcov.texi | 8 ++++++++ libgcc/libgcov-driver-system.c | 10 +++++++++- libgcc/libgcov-driver.c | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi index 4bd976db0b5..1cdca118b45 100644 --- a/gcc/doc/gcov.texi +++ b/gcc/doc/gcov.texi @@ -801,6 +801,14 @@ as well as handlers registered with @code{atexit}. If an executable loads a dynamic shared object via dlopen functionality, @option{-Wl,--dynamic-list-data} is needed to dump all profile data. +Profiling run-time library reports various errors related to profile +manipulation and profile saving. Errors are printed into standard error output +or @samp{GCOV_ERROR_FILE} file, if environment variable is used. +In order to terminate immediately after an errors occurs +set @samp{GCOV_EXIT_AT_ERROR} environment variable. +That can help users to find profile clashing which leads +to a misleading profile. + @c man end @node Gcov Data Files diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 0df44239363..bf125869dc0 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -62,8 +62,16 @@ gcov_error (const char *fmt, ...) va_list argp; va_start (argp, fmt); - ret = vfprintf (get_gcov_error_file (), fmt, argp); + FILE *f = get_gcov_error_file (); + ret = vfprintf (f, fmt, argp); va_end (argp); + + if (getenv ("GCOV_EXIT_AT_ERROR")) + { + fprintf (f, "profiling:exiting after an error\n"); + exit (1); + } + return ret; } diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index b4f195b8259..610356383f1 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -372,8 +372,12 @@ merge_one_data (const char *filename, length = gcov_read_unsigned (); if (length != gi_ptr->stamp) - /* Read from a different compilation. Overwrite the file. */ - return 0; + { + /* Read from a different compilation. Overwrite the file. */ + gcov_error ("profiling:%s:overwriting an existing profile data " + "with a different timestamp\n", filename); + return 0; + } /* Look for program summary. */ for (f_ix = 0;;)