Bug 6449 - objdump -S and DOS-style line-endings
Summary: objdump -S and DOS-style line-endings
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.19
: P3 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-23 16:47 UTC by Martin Thomas
Modified: 2012-02-15 12:13 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 _O_BINARY
+#else
+#define O_BINARY 0
+#endif
+#endif
+
 /* Internal headers for the ELF .stab-dump code - sorry.  */
 #define	BYTES_IN_WORD	32
 #include "aout/aout64.h"
@@ -975,7 +983,7 @@
 #endif
   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 O_BINARY _O_BINARY
#define setmode _setmode
#else
#define O_BINARY 0
#endif
#endif

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.