This is the mail archive of the
mailing list for the GCC project.
[PATCH] fix PR58602 (.gcno files not truncated at gcov_close)
- From: Laurent Alfonsi <laurent dot alfonsi at st dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 3 Oct 2013 17:01:51 +0200
- Subject: [PATCH] fix PR58602 (.gcno files not truncated at gcov_close)
- Authentication-results: sourceware.org; auth=none
We have discovered a bug on gcno file generation registred as PR58602.
When the .gcno graph file is opened for generating the coverage graph
information, the mode used is w+ as this code is shared with updating
tools such as libgcov.
Thus, when GCC outputs .gcno files, it may leave garbage at the end of
the file if the file already exists when opening it.
This has been trackeddown from a kernel issue on lcov:
This following patch fixes the function gcov_open() such that the .gcno
file is opened with truncation when gcc asks for creating a new file
Regression test x86-64 are ok with this patch.
Is it ok to commit in trunk ?
diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c
index 5a21c1f..342877d 100644
@@ -94,9 +94,15 @@ gcov_open (const char *name, int mode)
/* pass mode (ignored) for compatibility */
fd = open (name, O_RDONLY, S_IRUSR | S_IWUSR);
+ else if (mode < 0)
+ /* Write mode - acquire a write-lock. */
+ s_flock.l_type = F_WRLCK;
+ fd = open (name, O_RDWR | O_CREAT | O_TRUNC, 0666);
+ else /* mode == 0 */
- /* Write mode - acquire a write-lock. */
+ /* Read-Write mode - acquire a write-lock. */
s_flock.l_type = F_WRLCK;
fd = open (name, O_RDWR | O_CREAT, 0666);