This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Tue, Sep 22, 2009 at 5:26 AM, Nathan Sidwell <nathan@codesourcery.com> wrote:
> 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). ?This patch modifies
>> the behavior of gcov_open to only open the file in write mode if the
>> MODE argument is >= 0.
>>
>> Bootstrapped/regtested on x86_64-linux and i686-linux. ?Verified that
>> FDO still works. ?Ok for trunk?
>>
>> 2009-09-17 ?Neil Vachharajani ?<nvachhar@gmail.com>
>>
>> ? ? ? ?* gcov-io.c (gcov_open): Open files read-only when MODE < 0
>
> Can you protect the new read-only code with #if !IN_LIBGCOV, so we don't
> unnecessarily bloat that? ?It looks like that's the locking calls as the
> open call is already in such a #if block.

I'm not quite sure I follow.  While the textual change looks large,
the patch changes only 2 things.  First, if GCOV_LOCKED is true, then
s_flock.l_type is set conditionally rather than unconditionally (note
the if statement guarding that assignment already existed guarding two
different calls to open).  Second, instead of always passing "r+b" to
fopen (or fdopen) the parameter is now selected with ?: on mode.

If IN_LIBGCOV is true, mode is set to 0 in the function itself (mode
is not an argument in that case).  I believe that this constant will
be propagated to all the conditions on mode and the generated code
will not at all be bloated by the read-only code as it will be dead
code eliminated away.

Apologies in advance if I am missing something

Neil

>
> nathan
>
> --
> Nathan Sidwell ? ?:: ? http://www.codesourcery.com ? :: ? ? ? ? CodeSourcery
>
>



-- 
Neil Vachharajani
Google
650-214-1804


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]