physical-computation / sunflower-embedded-system-emulator

Sunflower Full-System Hardware Emulator and Physical System Simulator for Sensor-Driven Systems. Built-in architecture modeling of Hitachi SH (j-core), RISC-V, and more.
http://sflr.org
BSD 3-Clause "New" or "Revised" License
23 stars 215 forks source link

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

Open btsouts opened 4 years ago

btsouts commented 4 years ago

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):