From patchwork Wed Feb 24 21:52:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Conole X-Patchwork-Id: 587758 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 2AA091401C7 for ; Thu, 25 Feb 2016 08:52:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=S7FAOpfO; 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=WR1nGFRl2kKDoOX xkdzgGgo5BR9GL/FEbcJl3heJIxmJfPBIAv6fRFMvTGTh27q3AL9XFXEiqP4XE6z qydaueA5dCOoJS8YxzOqOlBPOphY5Uv7fOgo3ewaW1n0L3MhIF7CF1GUo5FESoVf CKDz+KE48/UHSSu/OsKH0pqH7j8Y= 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=dFGzcSxislQlOB3asK2o5 xIojhQ=; b=S7FAOpfOTJTMHXYWKQ6WEp9MpdxyseIO3LZ7zuQogOmdEOV2CQDR+ NuJGYhNmu6n3QpGNmPKBCzpTOt8NatKOSmaEYJQI11ofL0+4rysjwHiawxFV1Frb nWntrnfZdVS3GdyLGnvopoNWnrI3pzyQp5HoILtdIbMgNdvGbNHCA4= Received: (qmail 116694 invoked by alias); 24 Feb 2016 21:52:25 -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 116679 invoked by uid 89); 24 Feb 2016 21:52:24 -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=2324, va_end, Hx-languages-length:2847, configuring X-HELO: mail-qg0-f68.google.com Received: from mail-qg0-f68.google.com (HELO mail-qg0-f68.google.com) (209.85.192.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 24 Feb 2016 21:52:23 +0000 Received: by mail-qg0-f68.google.com with SMTP id y89so2076330qge.0 for ; Wed, 24 Feb 2016 13:52:23 -0800 (PST) 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=zIx/7tL4zbHUzMA+JM5bGwNBy5kIE674Xklwu71K52U=; b=fyJ5nm/AqWKK9Vu45c0oUibI2KYssWVr5rfE3gS/DIG/duerI3Tj4hy/L5BzdG24QX oNl34wgDwr8fd6ormD3llxgskRowewfmSHY2I9A2acy3+zbGPkLyMe8kUyo1E3GUDR2d Vl7yQygrh3f2heslmaA7Yz2z540XGAYtUF6jgeINmRQP4LCe1Z8rhflXANqzAYrZwLtS u09pIYZEoVdll3HFElxV5FUSZ9JF2dtPXU7iJWtzDSG+NAdr3It2PzUn8fAl/yLLZ9bj YROHIsMLTlnC/pOPxreT+bfuVzQRwDM4eC0DMP+kHBkPrkWkIsHzUE3mX1C3M/dleQc5 G87g== X-Gm-Message-State: AG10YOQqujB8OQ+LqzIgtaT/UvbeXX9JJKHDnzR5K1IhHbYaF18SGNwFfMTtl01QTt0FYg== X-Received: by 10.140.29.116 with SMTP id a107mr32908128qga.45.1456350741086; Wed, 24 Feb 2016 13:52:21 -0800 (PST) Received: from aconole-fed23.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id y99sm2053422qge.3.2016.02.24.13.52.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Feb 2016 13:52:20 -0800 (PST) From: Aaron Conole To: gcc-patches@gcc.gnu.org, Nathan Sidwell , Jan Hubicka , Nathan Sidwell Subject: [PATCH v2] gcov: Runtime configurable destination output Date: Wed, 24 Feb 2016 16:52:12 -0500 Message-Id: <1456350732-8272-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. --- v2: * Retitled subject * Cleaned up whitespace in libgcov-driver-system.c diff * Lazy error file opening * non-static error file * No warnings during compilation libgcc/libgcov-driver-system.c | 35 ++++++++++++++++++++++++++++++++++- libgcc/libgcov-driver.c | 6 ++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 4e3b244..0eb9755 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -23,6 +23,24 @@ a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +FILE *__gcov_error_file = NULL; + +static FILE * +get_gcov_error_file(void) +{ + char *gcov_error_filename = getenv("GCOV_ERROR_FILE"); + FILE *gcov_error_file = NULL; + 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; +} + /* A utility function for outputing errors. */ static int __attribute__((format(printf, 1, 2))) @@ -30,12 +48,27 @@ 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); + } +} +#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..83d84c5c 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -46,6 +46,10 @@ void __gcov_init (struct gcov_info *p __attribute__ ((unused))) {} /* A utility function for outputing 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