Do not open .gcda/.gcno files in write mode unnecessarily.

Neil Vachharajani nvachhar@google.com
Fri Sep 18 05:10:00 GMT 2009


On Thu, Sep 17, 2009 at 6:22 PM, Ben Elliston <bje@au1.ibm.com> wrote:
>
> On Thu, 2009-09-17 at 11:23 -0700, Neil Vachharajani wrote:
>
> > GCC currently always opens .gcda/.gcno files in write mode.  This
> > leads to permission denied errors when opening these files if the
> > files are read-only.  Having read-only .gcda files is useful to ensure
> > that one does not unintentionally modify profile data (by default, an
> > instrumented binary will append to .gcda files).
>
> I agree with the need to allow users to protect profile data in this
> way.  I just wonder if the runtime code should produce a warning so that
> users don't have to spend debugging time trying to work out why their
> profile data isn't being updated?

I'm not sure I follow.  In any case where the file was being written
to, the file is still opened in read-write mode.  In particular, when
gcov_open is being called from within libgcov, IN_LIBGCOV is true, and
mode is set to 0.  So, for any binary that is trying to update the
.gcda files (i.e., invocations from within libgcov), the behavior is
unchanged from before.  Are you suggesting that instead of simply
returning 0, if gcov_open cannot open the .gcda/.gcno file it prints
an error?  If so, I think this is already handled by the client code.
Consider libgcov.c.  If it cannot open the .gcda file (i.e., gcov_open
returns 0), it tries to create the appropriate directory and then it
tries the open again.  If it fails again, it then prints:

309 	 if (!gcov_open (gi_filename))
310 	{
311 	fprintf (stderr, "profiling:%s:Cannot open\n", gi_filename);
312 	continue;
313 	}

Am I misunderstanding something?

>
> Cheers,
> Ben
>
>



--
Neil Vachharajani
Google
650-214-1804



More information about the Gcc-patches mailing list