This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFA: ensure binary objects opened in binary mode
- From: Charles Wilson <cygwin at cwilson dot fastmail dot fm>
- To: gdb-patches at sourceware dot org
- Date: Fri, 17 Feb 2006 16:59:27 -0500
- Subject: RFA: ensure binary objects opened in binary mode
gdb uses solib_open() to open solibs via open(), openp(), or
ops->find_and_open_solib(), using the O_RDONLY flag. Later, bfd_open uses
fdopen(filedescriptor_from_solib_open, "rb")
to change the text/binary mode (to binary) on platforms where that
matters -- like cygwin and mingw.
Now, cygwin's fdopen implementation does the right thing and does, in
fact, change the mode to binary. So, on cygwin, this "bug" has no
practical effect; this is not true for mingw, where the mode is NOT
changed to binary (which leads to all sorts of problems parsing the file).
However, even on cygwin, it's still *wrong* for gdb to open a solib
(which is by definition a binary object) in text mode -- even if it gets
"fixed" later by bfd_open(). So IMO this patch is "the right thing" for
both cygwin and mingw, even tho there is no observable change in
cygwin's behavior -- and it DOES fix a serious bug on mingw.
Oh, and about the #ifndef O_BINARY stuff in this .c file: look at
gdb/source.c before commenting. Also, as this patch adds only three
non-blank lines and modifies only six more (all in exactly the same
way), I believe it falls under the FSF definition of trivial.
2006-02-17 Charles Wilson <...>
* gdb/solib.c(solib_open): ensure solib files are opened in
binary mode.
--
Chuck
Index: gdb/solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.83
diff -u -r1.83 solib.c
--- gdb/solib.c 21 Jan 2006 22:23:27 -0000 1.83
+++ gdb/solib.c 1 Feb 2006 21:27:52 -0000
@@ -47,6 +47,10 @@
#include "observer.h"
#include "readline/readline.h"
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
/* Architecture-specific operations. */
/* Per-architecture data key. */
@@ -171,7 +175,7 @@
}
/* Now see if we can open it. */
- found_file = open (temp_pathname, O_RDONLY, 0);
+ found_file = open (temp_pathname, O_RDONLY|O_BINARY, 0);
}
/* If the search in solib_absolute_prefix failed, and the path name is
@@ -192,32 +196,32 @@
/* If not found, search the solib_search_path (if any). */
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
- in_pathname, O_RDONLY, 0, &temp_pathname);
+ in_pathname, O_RDONLY|O_BINARY, 0, &temp_pathname);
/* If not found, next search the solib_search_path (if any) for the basename
only (ignoring the path). This is to allow reading solibs from a path
that differs from the opened path. */
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
- lbasename (in_pathname), O_RDONLY, 0,
+ lbasename (in_pathname), O_RDONLY|O_BINARY, 0,
&temp_pathname);
/* If not found, try to use target supplied solib search method */
if (found_file < 0 && ops->find_and_open_solib)
- found_file = ops->find_and_open_solib (in_pathname, O_RDONLY,
+ found_file = ops->find_and_open_solib (in_pathname, O_RDONLY|O_BINARY,
&temp_pathname);
/* If not found, next search the inferior's $PATH environment variable. */
if (found_file < 0 && solib_absolute_prefix == NULL)
found_file = openp (get_in_environ (inferior_environ, "PATH"),
- OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+ OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY|O_BINARY, 0,
&temp_pathname);
/* If not found, next search the inferior's $LD_LIBRARY_PATH
environment variable. */
if (found_file < 0 && solib_absolute_prefix == NULL)
found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"),
- OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+ OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY|O_BINARY, 0,
&temp_pathname);
/* Done. If not found, tough luck. Return found_file and