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: RFA: Avoid use of ftruncate() in libgcov


Richard Sandiford wrote:
Nathan Sidwell <nathan@codesourcery.com> writes:

Richard Sandiford wrote:

So... would it be OK to drop the use of ftruncate() and rely simply on
closing and reopening the file in w+ mode?  Patch below.  I've verified
that the truncation still works on i686-pc-linux-gnu after this patch.

closing and opening will break concurrent updates. (which I think manifests on an enable-coverage bootstrap with -j<somenumber>).


This is probably a silly question, but break in what way?  ftruncate()
only gets called if the file is about to be rewritten from scratch.
If instance A of the program closes the file, then instance B opens
it before A has a chance to truncate it, I'd have expected A's second
open to fail.  How is that different from failing to open the file
in the first place?

ftruncate is used when it's detected that the coverage file was produced by a different version of the object file (it's been recompiled perhaps). We need to throw away the data and start afresh, and we want to do that exactly once. By using close/open to achieve that there will be the opportunity for the following to happen,

instanceA		instanceB
open
discover mismatch
close
			open
			discover mismatch
			close
open
write data
close
			open
			write data
			close

thus losing instanceA's data.

Anyway, I'm testing a patch that implements an EOF tag, so truncation
will not be necessary.

nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk



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