Use O_BINARY when opening GCDA file on Windows

Summary:
Fixes https://bugs.llvm.org/show_bug.cgi?id=34922.

Apparently, the mode in **fdopen** gets simply ignored and Windows only cares about the mode of the original **open**.

I have verified this both with the simple case from bug 34922 and with a full Firefox build.

Reviewers: zturner

Reviewed By: zturner

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D38984

llvm-svn: 316048
This commit is contained in:
Marco Castelluccio 2017-10-18 00:22:01 +00:00
parent 30247fd1d9
commit 17103fc12f

View File

@ -37,6 +37,9 @@
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
#ifndef O_BINARY
#define O_BINARY 0
#endif
#endif
#if defined(__FreeBSD__) && defined(__i386__)
@ -238,17 +241,17 @@ void llvm_gcda_start_file(const char *orig_filename, const char version[4],
/* Try just opening the file. */
new_file = 0;
fd = open(filename, O_RDWR);
fd = open(filename, O_RDWR | O_BINARY);
if (fd == -1) {
/* Try opening the file, creating it if necessary. */
new_file = 1;
mode = "w+b";
fd = open(filename, O_RDWR | O_CREAT, 0644);
fd = open(filename, O_RDWR | O_CREAT | O_BINARY, 0644);
if (fd == -1) {
/* Try creating the directories first then opening the file. */
__llvm_profile_recursive_mkdir(filename);
fd = open(filename, O_RDWR | O_CREAT, 0644);
fd = open(filename, O_RDWR | O_CREAT | O_BINARY, 0644);
if (fd == -1) {
/* Bah! It's hopeless. */
int errnum = errno;