aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-12-18 07:28:57 -0800
committerNathan Sidwell <nathan@acm.org>2020-12-18 07:31:55 -0800
commit785b49434d27377208f6b058e589507cd0feadb3 (patch)
treef6739b919d46ef139c4b9760847f79bbf2c2b914
parentce8dcc9105cbd4043d575d8b2c91309a423951a9 (diff)
downloadgcc-785b49434d27377208f6b058e589507cd0feadb3.zip
gcc-785b49434d27377208f6b058e589507cd0feadb3.tar.gz
gcc-785b49434d27377208f6b058e589507cd0feadb3.tar.bz2
c++: Fix windows binary files [PR 98362]
Windows has unique and special needs for open(2). gcc/cp/ * module.cc (O_CLOEXEC, O_BINARY): Add window's support. (elf_in::defrost, module_state::do_import) (finish_module_processing): Use O_BINARY.
-rw-r--r--gcc/cp/module.cc23
1 files changed, 19 insertions, 4 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index b2b8190..fc918d2 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -252,9 +252,23 @@ Classes used:
#endif
#endif
-#if !HOST_HAS_O_CLOEXEC
+/* Some open(2) flag differences, what a colourful world it is! */
+#if defined (O_CLOEXEC)
+// OK
+#elif defined (_O_NOINHERIT)
+/* Windows' _O_NOINHERIT matches O_CLOEXEC flag */
+#define O_CLOEXEC _O_NOINHERIT
+#else
#define O_CLOEXEC 0
#endif
+#if defined (O_BINARY)
+// Ok?
+#elif defined (_O_BINARY)
+/* Windows' open(2) call defaults to text! */
+#define O_BINARY _O_BINARY
+#else
+#define O_BINARY 0
+#endif
static inline cpp_hashnode *cpp_node (tree id)
{
@@ -1596,7 +1610,7 @@ elf_in::defrost (const char *name)
gcc_checking_assert (is_frozen ());
struct stat stat;
- fd = open (name, O_RDONLY | O_CLOEXEC);
+ fd = open (name, O_RDONLY | O_CLOEXEC | O_BINARY);
if (fd < 0 || fstat (fd, &stat) < 0)
set_error (errno);
else
@@ -18568,7 +18582,7 @@ module_state::do_import (cpp_reader *reader, bool outermost)
{
const char *file = maybe_add_cmi_prefix (filename);
dump () && dump ("CMI is %s", file);
- fd = open (file, O_RDONLY | O_CLOEXEC);
+ fd = open (file, O_RDONLY | O_CLOEXEC | O_BINARY);
e = errno;
}
@@ -19704,7 +19718,8 @@ finish_module_processing (cpp_reader *reader)
if (!errorcount)
for (unsigned again = 2; ; again--)
{
- fd = open (tmp_name, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC,
+ fd = open (tmp_name,
+ O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC | O_BINARY,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
e = errno;
if (fd >= 0 || !again || e != ENOENT)