Skip to content

Commit

Permalink
Use O_BINARY when opening GCDA file on Windows
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marco-c committed Oct 18, 2017
1 parent 30247fd commit 17103fc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions compiler-rt/lib/profile/GCDAProfiling.c
Expand Up @@ -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__)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 17103fc

Please sign in to comment.