From patchwork Thu May 26 17:08:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Conole X-Patchwork-Id: 626803 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 3rFwbP0BgZz9t6B for ; Fri, 27 May 2016 03:08:48 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=mrLxlUML; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id; q=dns; s=default; b=JMpoWCMd1sNJ5gM 5EvXJjuPcJnhkQj6LAUFZEelCV8WrqyThQFmPPv97Yk32ZiTtYOSToou9DOUCmQn q7FpAI4lESEphuvo9ZG5f1T+IN5qUUi+8+1lDcLLxJWvhPVp5wGvMPqqTG+clqFn /p1SuMXx/FxiKyTjYPT9/gWa/22E= 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 :to:subject:date:message-id; s=default; bh=kQ1Gz9Rfb4nTCvBAX34fO hVmeaM=; b=mrLxlUML67xY1omTz/5lsluBDZN/rlh4kQoEQgB6dTICsSOq+Dida EvCxyQyestzZCzeizpfwVu+VwFHcU4QfbqarHYji5RxKjrfi3wkMR/WV+fWcD+Zo 99+TVRO1KtBgi0QpDZRT8rhOBnhhpxMuz3Y4Tq0URq6B+t2BZlFp40= Received: (qmail 27048 invoked by alias); 26 May 2016 17:08:41 -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 26957 invoked by uid 89); 26 May 2016 17:08:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=UD:RUNTIME, copyingruntime, COPYINGRUNTIME, copying.runtime X-HELO: mail-qk0-f195.google.com Received: from mail-qk0-f195.google.com (HELO mail-qk0-f195.google.com) (209.85.220.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 26 May 2016 17:08:30 +0000 Received: by mail-qk0-f195.google.com with SMTP id q184so10051740qkf.0 for ; Thu, 26 May 2016 10:08:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=OuV9kX4ZKaIIg9C/xOl5EEriSTfyPQ3aEynrJvaifYY=; b=gMKyyCw3VWqnmkdMBgmYBEOi2iZaU6hRcH0ARAIMsya2itewPwtyISrsXhVGYIHLuO N58LVfmN5gYK2Fi4lyhTFLBhVu6i3D7yKZZvF57n0arp4fiaiNLLrZ7xqCPArsoL/y+v ja1ec0xNBl7pgpOCeriNfeTGZ5XWW1CyFEqxQLG8HO7tBZCRnV5d7IjPZ+LTG5f/8O3a GdyiR577DKVN5dWSuWlydYwJFNttPMh6vHTcOvadb8BM2e2jJgDnLnIeYy8uWSnQyjd5 aDWlApoJ3D3+B08FMr5JmUcl/4JmZzgBJJU6GKZa4Dels1vAonCfYqhWdXLcE2pHlp21 ssJA== X-Gm-Message-State: ALyK8tLVHe3wBmNUwpg1Kzrqo9HkjnR0FL8RGR9GOS2RM1H9bsQkce3q0R7PLgoTOPfvkQ== X-Received: by 10.237.35.113 with SMTP id i46mr5951216qtc.98.1464282507833; Thu, 26 May 2016 10:08:27 -0700 (PDT) Received: from aconole-fed23.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id x13sm4096890qtc.12.2016.05.26.10.08.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 10:08:26 -0700 (PDT) From: Aaron Conole To: gcc-patches@gcc.gnu.org, Nathan Sidwell Subject: [PATCH v4] gcov: Runtime configurable destination output Date: Thu, 26 May 2016 13:08:21 -0400 Message-Id: <1464282501-7696-1-git-send-email-aconole@bytheb.org> X-IsSubscribed: yes The previous gcov behavior was to always output errors on the stderr channel. This is fine for most uses, but some programs will require stderr to be untouched by libgcov for certain tests. This change allows configuring the gcov output via an environment variable which will be used to open the appropriate file. --- libgcc/libgcov-driver-system.c | 49 ++++++++++++++++++++++++++++++++++++++++-- libgcc/libgcov-driver.c | 8 ++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 4e3b244..ff8a521 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -23,19 +23,64 @@ a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ -/* A utility function for outputing errors. */ +/* Configured via the GCOV_ERROR_FILE environment variable; + it will either be stderr, or a file of the user's choosing. + Non-static to prevent multiple gcov-aware shared objects from + instantiating their own copies. */ +FILE *__gcov_error_file = NULL; + +/* A utility function to populate the __gcov_error_file pointer. + This should NOT be called outside of the gcov system driver code. */ + +static FILE * +get_gcov_error_file(void) +{ +#if !IN_GCOV_TOOL + return stderr; +#else + char *gcov_error_filename = getenv ("GCOV_ERROR_FILE"); + + if (gcov_error_filename) + { + FILE *openfile = fopen (gcov_error_filename, "a"); + if (openfile) + __gcov_error_file = openfile; + } + if (!__gcov_error_file) + __gcov_error_file = stderr; + return __gcov_error_file; +#endif +} + +/* A utility function for outputting errors. */ static int __attribute__((format(printf, 1, 2))) gcov_error (const char *fmt, ...) { int ret; va_list argp; + + if (!__gcov_error_file) + __gcov_error_file = get_gcov_error_file (); + va_start (argp, fmt); - ret = vfprintf (stderr, fmt, argp); + ret = vfprintf (__gcov_error_file, fmt, argp); va_end (argp); return ret; } +#if !IN_GCOV_TOOL +static void +gcov_error_exit (void) +{ + if (__gcov_error_file && __gcov_error_file != stderr) + { + fclose (__gcov_error_file); + __gcov_error_file = NULL; + } +} +#endif + /* Make sure path component of the given FILENAME exists, create missing directories. FILENAME must be writable. Returns zero on success, or -1 if an error occurred. */ diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index 9c4eeca..d51397e 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -43,9 +43,13 @@ void __gcov_init (struct gcov_info *p __attribute__ ((unused))) {} #ifdef L_gcov -/* A utility function for outputing errors. */ +/* A utility function for outputting errors. */ static int gcov_error (const char *, ...); +#if !IN_GCOV_TOOL +static void gcov_error_exit (void); +#endif + #include "gcov-io.c" struct gcov_fn_buffer @@ -878,6 +882,8 @@ gcov_exit (void) __gcov_root.prev->next = __gcov_root.next; else __gcov_master.root = __gcov_root.next; + + gcov_error_exit (); } /* Add a new object file onto the bb chain. Invoked automatically