[PATCH] D38984: Use fopen instead of fdopen for opening GCDA files as fdopen seems to cause files to get corrupted
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 16 17:45:34 PDT 2017
Try passing _O_BINARY to the original open() call and then seeing if fdopen
works.
If you really want true reliability you should use native win32 APIs for
file i/o, but that’s a large rewrite, so I agree targeted fixes make more
sense here
On Mon, Oct 16, 2017 at 5:14 PM Marco Castelluccio via Phabricator <
reviews at reviews.llvm.org> wrote:
> marco-c created this revision.
>
> Fixes https://bugs.llvm.org/show_bug.cgi?id=34922.
>
> When using fdopen, the GCDA file is very often not correctly written to
> disk. I honestly have no idea why, perhaps somebody more familiar with
> Windows would know.
> This doesn't only apply to the simple case from bug 34922. I have built
> Firefox to collect coverage and before this change most GCDA files were
> corrupted.
>
>
> https://reviews.llvm.org/D38984
>
> Files:
> lib/profile/GCDAProfiling.c
>
>
> Index: lib/profile/GCDAProfiling.c
> ===================================================================
> --- lib/profile/GCDAProfiling.c
> +++ lib/profile/GCDAProfiling.c
> @@ -263,8 +263,9 @@
> * same GCDA. This can fail if the filesystem doesn't support it, but
> in that
> * case we'll just carry on with the old racy behaviour and hope for
> the best.
> */
> - flock(fd, LOCK_EX);
> - output_file = fdopen(fd, mode);
> + close(fd);
> + output_file = fopen(filename, mode);
> + flock(fileno(output_file), LOCK_EX);
>
> /* Initialize the write buffer. */
> write_buffer = NULL;
> @@ -462,7 +463,7 @@
> unmap_file();
> }
>
> - flock(fd, LOCK_UN);
> + flock(fileno(output_file), LOCK_UN);
> fclose(output_file);
> output_file = NULL;
> write_buffer = NULL;
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171017/60b6f4d0/attachment.html>
More information about the llvm-commits
mailing list