diff options
Diffstat (limited to 'libgcc/libgcov-driver-system.c')
-rw-r--r-- | libgcc/libgcov-driver-system.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 4e3b244c7c..5cfc950ab0 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -1,6 +1,6 @@ /* Routines required for instrumenting a program. */ /* Compile this one with gcc. */ -/* Copyright (C) 1989-2016 Free Software Foundation, Inc. +/* Copyright (C) 1989-2017 Free Software Foundation, Inc. This file is part of GCC. @@ -23,19 +23,62 @@ a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see <http://www.gnu.org/licenses/>. */ -/* A utility function for outputing errors. */ +#if !IN_GCOV_TOOL +/* 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; +#endif + +/* 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 + if (!__gcov_error_file) + { + const char *gcov_error_filename = getenv ("GCOV_ERROR_FILE"); + + if (gcov_error_filename) + __gcov_error_file = fopen (gcov_error_filename, "a"); + 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; + va_start (argp, fmt); - ret = vfprintf (stderr, fmt, argp); + ret = vfprintf (get_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. */ |