From 3cdea2b453e83eea7296e4e4502470ab8f6ed316 Mon Sep 17 00:00:00 2001 From: Andy Hutchinson Date: Mon, 11 Jan 2010 23:15:32 +0000 Subject: lto.c (O_BINARY): Define. 2010-01-11 Andy Hutchinson * lto.c (O_BINARY): Define. (lto_read_section_data): Open file in binary mode. * lto-elf.c (O_BINARY): Define. (lto_elf_file_open): Open file in binary mode. From-SVN: r155820 --- gcc/lto/ChangeLog | 7 +++++++ gcc/lto/lto-elf.c | 10 +++++++++- gcc/lto/lto.c | 10 +++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'gcc') diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog index 5e52527..a726d32 100644 --- a/gcc/lto/ChangeLog +++ b/gcc/lto/ChangeLog @@ -1,3 +1,10 @@ +2010-01-11 Andy Hutchinson + + * lto.c (O_BINARY): Define. + (lto_read_section_data): Open file in binary mode. + * lto-elf.c (O_BINARY): Define. + (lto_elf_file_open): Open file in binary mode. + 2010-01-08 Richard Guenther PR lto/42528 diff --git a/gcc/lto/lto-elf.c b/gcc/lto/lto-elf.c index 0311dde..b70648d 100644 --- a/gcc/lto/lto-elf.c +++ b/gcc/lto/lto-elf.c @@ -29,6 +29,13 @@ along with GCC; see the file COPYING3. If not see #include "ggc.h" #include "lto-streamer.h" +/* Handle opening elf files on hosts, such as Windows, that may use + text file handling that will break binary access. */ + +#ifndef O_BINARY +# define O_BINARY 0 +#endif + /* Initialize FILE, an LTO file object for FILENAME. */ static void @@ -580,7 +587,8 @@ lto_elf_file_open (const char *filename, bool writable) elf_file->fd = -1; /* Open the file. */ - elf_file->fd = open (fname, writable ? O_WRONLY|O_CREAT : O_RDONLY, 0666); + elf_file->fd = open (fname, writable ? O_WRONLY|O_CREAT|O_BINARY + : O_RDONLY|O_BINARY, 0666); if (elf_file->fd == -1) { error ("could not open file %s", fname); diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index 1608e56..de53a09 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -50,6 +50,14 @@ along with GCC; see the file COPYING3. If not see #include #endif +/* Handle opening elf files on hosts, such as Windows, that may use + text file handling that will break binary access. */ + +#ifndef O_BINARY +# define O_BINARY 0 +#endif + + DEF_VEC_P(bitmap); DEF_VEC_ALLOC_P(bitmap,heap); @@ -421,7 +429,7 @@ lto_read_section_data (struct lto_file_decl_data *file_data, if (fd == -1) { fd_name = xstrdup (file_data->file_name); - fd = open (file_data->file_name, O_RDONLY); + fd = open (file_data->file_name, O_RDONLY|O_BINARY); if (fd == -1) return NULL; } -- cgit v1.1