diff mbox series

libgcov: report about a different timestamp (PR gcov-profile/85759).

Message ID 73474dc8-6b97-35ab-f0b2-b514fdf599e5@suse.cz
State New
Headers show
Series libgcov: report about a different timestamp (PR gcov-profile/85759). | expand

Commit Message

Martin Liška May 29, 2018, 9:32 a.m. UTC
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  <mliska@suse.cz>

        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  <mliska@suse.cz>

        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(-)

Comments

Nathan Sidwell May 29, 2018, 11:18 a.m. UTC | #1
On 05/29/2018 05:32 AM, Martin Liška wrote:
> 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?


ok, thanks
diff mbox series

Patch

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;;)