sunflower-embedded-system-emulator icon indicating copy to clipboard operation
sunflower-embedded-system-emulator copied to clipboard

Inconsistency in file manipulation flag values between newlib (cross-compilation) and glibc (native)

Open btsouts opened this issue 5 years ago • 0 comments

Describe the bug Common file manipulation flags such as O_CREAT have different values in newlib and native libc implementation (definitely in Linux). There operations such as creation of a file fail. Related also to issue 164.

Example:

newlib-2.5.0.20170922/newlib/libc/include/sys/_default_fcntl.h:

#define _FOPEN (-1) /* from sys/file.h, kernel use only / #define _FREAD 0x0001 / read enabled / #define _FWRITE 0x0002 / write enabled / #define _FAPPEND 0x0008 / append (writes guaranteed at the end) / #define _FMARK 0x0010 / internal; mark during gc() / #define _FDEFER 0x0020 / internal; defer for next gc pass / #define _FASYNC 0x0040 / signal pgrp when data ready / #define _FSHLOCK 0x0080 / BSD flock() shared lock present / #define _FEXLOCK 0x0100 / BSD flock() exclusive lock present / #define _FCREAT 0x0200 / open with file create / #define _FTRUNC 0x0400 / open with truncation */

For Ubuntu GLIBC 2.27-3ubuntu1, in /usr/include/bits/fcntl-linux.h:

#define O_ACCMODE 0003 #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #ifndef O_CREAT #define O_CREAT 0100 /* Not fcntl. / #endif #ifndef O_EXCL #define O_EXCL 0200 / Not fcntl. / #endif #ifndef O_NOCTTY #define O_NOCTTY 0400 / Not fcntl. / #endif #ifndef O_TRUNC #define O_TRUNC 01000 / Not fcntl. */

To Reproduce Steps to reproduce the behavior:

  1. Create an program that creates a new file for writing with fopen, i.e. fopen(filename, "w")
  2. Compile for sunflower RISC-V and execute.
  3. The target file should not exist.

Host OS (please complete the following information):

  • OS: Ubuntu 18.04.4 LTS
  • Kernel: 5.3.0-42-generic #34~18.04.1-Ubuntu
  • Libc version: Ubuntu GLIBC 2.27-3ubuntu1
  • CC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

btsouts avatar Apr 01 '20 22:04 btsouts