This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH GOLD] [5/N mingw host] open files in binary mode
- From: Ian Lance Taylor <iant at google dot com>
- To: Andrew Pinski <Andrew_Pinski at playstation dot sony dot com>
- Cc: binutils <binutils at sourceware dot org>
- Date: Fri, 09 Oct 2009 21:57:48 -0700
- Subject: Re: [PATCH GOLD] [5/N mingw host] open files in binary mode
- References: <de8d50360910071214g34c25b9fw4eb7d4ec82f5537c@mail.gmail.com>
Andrew Pinski <Andrew_Pinski@playstation.sony.com> writes:
> Under mingw, files are opened by default in text mode which means
> /n/r is converted into /n but since we are reading in binary files,
> this confuses the rest of the linker.
>
> OK? Built and tested on i686-linux-gnu.
>
> Thanks,
> Andrew Pinski
>
> ChangeLog:
>
> * descriptor.c: Include binary-io.h.
> (Descriptors::open): Open the files in binary mode always.
This could cause linker scripts to see \r. Also binary-io.h says to
be sure to include <stdio.h> first. I committed the patch as follows.
Thanks.
Ian
2009-10-09 Andrew Pinski <andrew_pinski@playstation.sony.com>
Ian Lance Taylor <iant@google.com>
* descriptor.cc: Include <cstdio> and "binary-io.h".
(Descriptors::open): Open the files in binary mode always.
* script.cc (Lex::get_token): Treat \r as whitespace.
Index: descriptors.cc
===================================================================
RCS file: /cvs/src/src/gold/descriptors.cc,v
retrieving revision 1.7
diff -u -r1.7 descriptors.cc
--- descriptors.cc 24 Mar 2009 04:50:32 -0000 1.7
+++ descriptors.cc 10 Oct 2009 04:55:54 -0000
@@ -23,6 +23,7 @@
#include "gold.h"
#include <cerrno>
+#include <cstdio>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
@@ -31,6 +32,7 @@
#include "options.h"
#include "gold-threads.h"
#include "descriptors.h"
+#include "binary-io.h"
// Very old systems may not define FD_CLOEXEC.
#ifndef FD_CLOEXEC
@@ -98,6 +100,9 @@
// require callers to pass it.
flags |= O_CLOEXEC;
+ // Always open the file as a binary file.
+ flags |= O_BINARY;
+
int new_descriptor = ::open(name, flags, mode);
if (new_descriptor < 0
&& errno != ENFILE
Index: script.cc
===================================================================
RCS file: /cvs/src/src/gold/script.cc,v
retrieving revision 1.55
diff -u -r1.55 script.cc
--- script.cc 6 Jul 2009 23:11:21 -0000 1.55
+++ script.cc 10 Oct 2009 04:55:55 -0000
@@ -743,7 +743,7 @@
}
// Skip whitespace quickly.
- while (*p == ' ' || *p == '\t')
+ while (*p == ' ' || *p == '\t' || *p == '\r')
++p;
if (*p == '\n')