[PATCH] D38984: Use fopen instead of fdopen for opening GCDA files as fdopen seems to cause files to get corrupted
Marco Castelluccio via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 16 17:14:53 PDT 2017
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 --------------
A non-text attachment was scrubbed...
Name: D38984.119232.patch
Type: text/x-patch
Size: 767 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171017/33d2d1cc/attachment.bin>
More information about the llvm-commits
mailing list