libgloss/arm/syscalls.c: missing BINARY mode when opening files
Thu Nov 15 19:49:00 GMT 2007
I have been experiencing issues when reading files in the following
- compilation with arm-none-eabi-gcc (ie GCC for ARM)
- execution through RVDebug (ie ARM's debugger) under Windows.
After some investigation, I have discovered that in Newlib's _swiopen()
(in libgloss/arm/syscalls.c), there are the following 4 lines:
if (flags & O_BINARY)
aflags |= 1;
where O_BINARY is NOT defined when cross-compiling for ARM.
Indeed, in newlib/libc/include/sys/fcntl.h, we can see:
#if defined (_WIN32) || defined (__CYGWIN__)
#define _FBINARY 0x10000
#define _FTEXT 0x20000
#define _FNOINHERIT 0x40000
#define O_BINARY _FBINARY
The result is that when opening a file in binary mode, (eg "rb"), the
'binary' flag is discarded before performing the semi-hosting call.
Then, rvdebug interprets this as an open in TEXT mode, which leads to
Amusingly, executing from a Linux-hosted rvdebug seems to open in BINARY
mode in the same circumstances (which is not surprising...).
So, there is a discrepancy on ARM's side, but I would also say there is
a bug on Newlib's side.
I propose to add || defined (__arm__) in fcntl.h.
What do you think ?
More information about the Newlib