libgloss/arm/syscalls.c: missing BINARY mode when opening files

Christophe LYON christophe.lyon@st.com
Thu Nov 15 19:49:00 GMT 2007


Hello,

I have been experiencing issues when reading files in the following 
configuration:
- 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:
#ifdef O_BINARY
   if (flags & O_BINARY)
     aflags |= 1;
#endif

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 
unpleasant results.

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 ?

Thanks,

Christophe.



More information about the Newlib mailing list