Bug 6449

Summary: objdump -S and DOS-style line-endings
Product: binutils Reporter: Martin Thomas <mthomas>
Component: binutilsAssignee: unassigned
Severity: minor CC: bug-binutils, eric.weddington, hjl.tools, ktietz
Priority: P3    
Version: 2.19   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Martin Thomas 2008-04-23 16:47:10 UTC
When using objdump to create intermixed source/disassembly (-S) with build/host
mingw/minsys a size-check fails for source-files with DOS-line endings (\r\n)
since this gets translated "internally" to a single char. When opening the file
in binary mode the sizes match. Proposed fix/patch:

--- binutils-2.18.50_org/binutils/objdump.c	Sat Mar  1 07:19:06 2008
+++ binutils-2.18.50/binutils/objdump.c	Thu Mar 13 12:29:47 2008
@@ -70,6 +70,14 @@
 #include <sys/stat.h>
+#ifndef O_BINARY
+#ifdef _O_BINARY
+#define O_BINARY 0
 /* Internal headers for the ELF .stab-dump code - sorry.  */
 #define	BYTES_IN_WORD	32
 #include "aout/aout64.h"
@@ -975,7 +983,7 @@
   const char *map;
   struct stat st;
-  int fd = open (fn, O_RDONLY);
+  int fd = open (fn, O_RDONLY | O_BINARY);
   if (fd < 0)
     return NULL;
Comment 1 H.J. Lu 2008-04-24 12:57:56 UTC
There are so many

#ifndef O_BINARY
#ifdef _O_BINARY
#define setmode _setmode
#define O_BINARY 0

in binutils sources. It should go into sysdep.h.
Comment 2 Kai Tietz 2012-02-15 12:13:13 UTC
It was added to sysdep.h (via including include/binary-io.h) and objdump.c in binutils also specifies O_BINARY for open.  So bug is fixed.