X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Flto%2Flto-elf.c;h=356e513953667465dba03f219241d83929a2e26c;hp=368d8d4d75fc7ddb5af0d6fc259d688fb3f54a17;hb=2bd888dc62ee6298b759613c47a05300bd23e8ba;hpb=b7fedf62194c73508da653990c3d0a792a814271 diff --git a/gcc/lto/lto-elf.c b/gcc/lto/lto-elf.c index 368d8d4d75f..356e5139536 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 @@ -543,35 +550,33 @@ lto_elf_file_open (const char *filename, bool writable) lto_elf_file *elf_file; lto_file *result = NULL; off_t offset; + long loffset; off_t header_offset; const char *offset_p; char *fname; + int consumed; - offset_p = strchr (filename, '@'); - if (!offset_p) - { - fname = xstrdup (filename); - offset = 0; - header_offset = 0; - } - else + offset_p = strrchr (filename, '@'); + if (offset_p + && offset_p != filename + && sscanf (offset_p, "@%li%n", &loffset, &consumed) >= 1 + && strlen (offset_p) == (unsigned int)consumed) { fname = (char *) xmalloc (offset_p - filename + 1); memcpy (fname, filename, offset_p - filename); fname[offset_p - filename] = '\0'; - offset_p++; - errno = 0; - offset = strtoll (offset_p, NULL, 10); - if (errno != 0) - { - error ("could not parse offset %s", offset_p); - goto fail; - } + offset = (off_t)loffset; /* elf_rand expects the offset to point to the ar header, not the object itself. Subtract the size of the ar header (60 bytes). We don't uses sizeof (struct ar_hd) to avoid including ar.h */ header_offset = offset - 60; } + else + { + fname = xstrdup (filename); + offset = 0; + header_offset = 0; + } /* Set up. */ elf_file = XCNEW (lto_elf_file); @@ -580,7 +585,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);