[PATCH v2 1/2] Eliminate use of Newlib-specific <machine/types.h>

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Apr 13 07:29:20 UTC 2016


This change solves a glibc/BSD compatibility problem.

glibc and BSD use double underscore types for internal types.  The Linux
port of Newlib uses some glibc provided internal type definitions which
are not protected by guard defines, e.g. __off_t.  To avoid a conflict
Newlib uses single underscore types for some internal types, e.g.
_off_t.  However, for BSD compatibility we have to define the internal
types with double underscore names in <sys/_types.h>.

The header file <machine/types.h> is Newlib-specific.  It was used
instead of <sys/_types.h> to provide the internal type definitions
_CLOCK_T, _TIME_T_, _CLOCKID_T_, _TIMER_T_, and __suseconds_t.  Move
these definitions to <sys/_types.h> (there exist two instances of this
file, one for Linux and one for all other targets).  This makes the
_HAVE_SYSTYPES configuration define obsolete (could possibly break the
__RDOS__ target).  Use the standard <sys/_types.h> include throughout.

Move __loff_t defintion to default (non-Linux) <sys/_types.h>, since
Cygwin needs this type.

Provide the __off_t definition via default (non-Linux) <sys/_types.h>
based on _off_t.  This prevents a potential __off_t and _off_t
incompatibility.

Provide the __pid_t definition via default (non-Linux) <sys/_types.h>.
This prevents a potential __pid_t and pid_t incompatibility.  Add BSD
guard defines for pid_t.

Signed-off-by: Sebastian Huber <sebastian.huber at embedded-brains.de>
---
 newlib/libc/include/machine/types.h            | 27 +++-----------------------
 newlib/libc/include/reent.h                    |  1 -
 newlib/libc/include/sys/_timespec.h            |  2 +-
 newlib/libc/include/sys/_timeval.h             |  2 +-
 newlib/libc/include/sys/_types.h               | 21 ++++++++++++++++++++
 newlib/libc/include/sys/config.h               |  1 -
 newlib/libc/include/sys/timeb.h                |  2 +-
 newlib/libc/include/sys/times.h                |  2 +-
 newlib/libc/include/sys/types.h                |  8 +++-----
 newlib/libc/sys/linux/sys/_types.h             |  7 +++++++
 newlib/libc/sys/linux/sys/types.h              |  1 -
 newlib/libc/sys/rtems/include/machine/_types.h |  3 ---
 newlib/libc/sys/sparc64/sys/_timeval.h         |  2 +-
 13 files changed, 39 insertions(+), 40 deletions(-)

diff --git a/newlib/libc/include/machine/types.h b/newlib/libc/include/machine/types.h
index 4250ee3..669242b 100644
--- a/newlib/libc/include/machine/types.h
+++ b/newlib/libc/include/machine/types.h
@@ -2,31 +2,10 @@
 #define	_MACHTYPES_H_
 
 /*
- *  The following section is RTEMS specific and is needed to more
- *  closely match the types defined in the BSD machine/types.h.
- *  This is needed to let the RTEMS/BSD TCP/IP stack compile.
+ * This file is provided for backward compatibility.  It is no longer used in
+ * Newlib.  Do not add new things to it.
  */
-#if defined(__rtems__)
-#include <machine/_types.h>
-#endif
 
-#define	_CLOCK_T_	unsigned long		/* clock() */
-#define	_TIME_T_	long			/* time() */
-#define _CLOCKID_T_ 	unsigned long
-#define _TIMER_T_   	unsigned long
-
-#ifndef _HAVE_SYSTYPES
-typedef long int __off_t;
-typedef int __pid_t;
-#ifdef __GNUC__
-__extension__ typedef long long int __loff_t;
-#else
-typedef long int __loff_t;
-#endif
-#endif
-
-typedef	long		__suseconds_t;	/* microseconds (signed) */
+#include <sys/_types.h>
 
 #endif	/* _MACHTYPES_H_ */
-
-
diff --git a/newlib/libc/include/reent.h b/newlib/libc/include/reent.h
index 861be71..b7664b0 100644
--- a/newlib/libc/include/reent.h
+++ b/newlib/libc/include/reent.h
@@ -92,7 +92,6 @@ extern "C" {
 
 #include <sys/reent.h>
 #include <sys/_types.h>
-#include <machine/types.h>
 
 #define __need_size_t
 #define __need_ptrdiff_t
diff --git a/newlib/libc/include/sys/_timespec.h b/newlib/libc/include/sys/_timespec.h
index bd66dfc..4a7aabc 100644
--- a/newlib/libc/include/sys/_timespec.h
+++ b/newlib/libc/include/sys/_timespec.h
@@ -34,7 +34,7 @@
 #ifndef _SYS__TIMESPEC_H_
 #define	_SYS__TIMESPEC_H_
 
-#include <machine/types.h>
+#include <sys/_types.h>
 
 #ifndef __time_t_defined
 typedef	_TIME_T_	time_t;
diff --git a/newlib/libc/include/sys/_timeval.h b/newlib/libc/include/sys/_timeval.h
index 0a4c539..d813d1f 100644
--- a/newlib/libc/include/sys/_timeval.h
+++ b/newlib/libc/include/sys/_timeval.h
@@ -29,7 +29,7 @@
 #ifndef _SYS__TIMEVAL_H_
 #define _SYS__TIMEVAL_H_
 
-#include <machine/types.h>
+#include <sys/_types.h>
 
 #ifndef _SUSECONDS_T_DECLARED
 typedef	__suseconds_t	suseconds_t;
diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h
index 07bc276..5280b26 100644
--- a/newlib/libc/include/sys/_types.h
+++ b/newlib/libc/include/sys/_types.h
@@ -15,6 +15,13 @@
 #ifndef __off_t_defined
 typedef long _off_t;
 #endif
+typedef _off_t __off_t; /* BSD compatibility */
+
+#if defined(__XMK__)
+typedef signed char __pid_t;
+#else
+typedef int __pid_t;
+#endif
 
 #ifndef __dev_t_defined
 typedef short __dev_t;
@@ -31,6 +38,13 @@ typedef unsigned short __gid_t;
 __extension__ typedef long long _off64_t;
 #endif
 
+/* Probably only used by Cygwin */
+#ifdef __GNUC__
+__extension__ typedef long long int __loff_t;
+#else
+typedef long int __loff_t;
+#endif
+
 /*
  * We need fpos_t for the following, but it doesn't have a leading "_",
  * so we use _fpos_t instead.
@@ -88,4 +102,11 @@ typedef _LOCK_RECURSIVE_T _flock_t;
 typedef void *_iconv_t;
 #endif
 
+#define	_CLOCK_T_	unsigned long		/* clock() */
+#define	_TIME_T_	long			/* time() */
+#define _CLOCKID_T_ 	unsigned long
+#define _TIMER_T_   	unsigned long
+
+typedef	long		__suseconds_t;	/* microseconds (signed) */
+
 #endif	/* _SYS__TYPES_H */
diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index c536698..555239f 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -92,7 +92,6 @@
 /* we want the reentrancy structure to be returned by a function */
 #define __DYNAMIC_REENT__
 #define HAVE_GETDATE
-#define _HAVE_SYSTYPES
 #define _READ_WRITE_RETURN_TYPE _ssize_t
 #define __LARGE64_FILES 1
 /* we use some glibc header files so turn on glibc large file feature */
diff --git a/newlib/libc/include/sys/timeb.h b/newlib/libc/include/sys/timeb.h
index 0a2c3de..2647830 100644
--- a/newlib/libc/include/sys/timeb.h
+++ b/newlib/libc/include/sys/timeb.h
@@ -15,7 +15,7 @@ extern "C" {
 #define _SYS_TIMEB_H
 
 #include <_ansi.h>
-#include <machine/types.h>
+#include <sys/_types.h>
 
 #ifndef __time_t_defined
 typedef _TIME_T_ time_t;
diff --git a/newlib/libc/include/sys/times.h b/newlib/libc/include/sys/times.h
index 927812c..dc072f4 100644
--- a/newlib/libc/include/sys/times.h
+++ b/newlib/libc/include/sys/times.h
@@ -5,7 +5,7 @@ extern "C" {
 #define	_SYS_TIMES_H
 
 #include <_ansi.h>
-#include <machine/types.h>
+#include <sys/_types.h>
 
 #ifndef __clock_t_defined
 typedef _CLOCK_T_ clock_t;
diff --git a/newlib/libc/include/sys/types.h b/newlib/libc/include/sys/types.h
index f880830..c0b5796 100644
--- a/newlib/libc/include/sys/types.h
+++ b/newlib/libc/include/sys/types.h
@@ -66,7 +66,6 @@ typedef	quad_t *	qaddr_t;
 #endif
 
 # include <stddef.h>
-# include <machine/types.h>
 
 /* To ensure the stat struct's layout doesn't change when sizeof(int), etc.
    changes, we assume sizeof short and long never change and have all types
@@ -175,10 +174,9 @@ typedef __uid_t uid_t;
 typedef __gid_t gid_t;
 #endif
 
-#if defined(__XMK__)
-typedef signed char pid_t;
-#else
-typedef int pid_t;
+#ifndef _PID_T_DECLARED
+typedef	__pid_t		pid_t;		/* process id */
+#define	_PID_T_DECLARED
 #endif
 
 #if defined(__rtems__)
diff --git a/newlib/libc/sys/linux/sys/_types.h b/newlib/libc/sys/linux/sys/_types.h
index 1ad429d..2fd1405 100644
--- a/newlib/libc/sys/linux/sys/_types.h
+++ b/newlib/libc/sys/linux/sys/_types.h
@@ -51,4 +51,11 @@ typedef struct
 
 typedef struct { __flock_mutex_t mutex; } _flock_t;
 
+#define	_CLOCK_T_	unsigned long		/* clock() */
+#define	_TIME_T_	long			/* time() */
+#define _CLOCKID_T_ 	unsigned long
+#define _TIMER_T_   	unsigned long
+
+typedef	long		__suseconds_t;	/* microseconds (signed) */
+
 #endif	/* _SYS__TYPES_H */
diff --git a/newlib/libc/sys/linux/sys/types.h b/newlib/libc/sys/linux/sys/types.h
index 8e674ef..20dab2f 100644
--- a/newlib/libc/sys/linux/sys/types.h
+++ b/newlib/libc/sys/linux/sys/types.h
@@ -54,7 +54,6 @@
 #include <stddef.h>
 #include <sys/config.h>
 #include <features.h>
-#include <machine/types.h>
 #include <sys/_types.h>
 
 #if !defined(__time_t_defined) && !defined(_TIME_T)
diff --git a/newlib/libc/sys/rtems/include/machine/_types.h b/newlib/libc/sys/rtems/include/machine/_types.h
index 1711c7a..e0d93f7 100644
--- a/newlib/libc/sys/rtems/include/machine/_types.h
+++ b/newlib/libc/sys/rtems/include/machine/_types.h
@@ -5,9 +5,6 @@
 #ifndef _MACHINE__TYPES_H
 #define _MACHINE__TYPES_H
 
-/* This disables some conflicting type definitions in <machine/types.h> */
-#define _HAVE_SYSTYPES
-
 #include <machine/_default_types.h>
 
 typedef __int32_t blksize_t;
diff --git a/newlib/libc/sys/sparc64/sys/_timeval.h b/newlib/libc/sys/sparc64/sys/_timeval.h
index 84ee717..fbe9ce6 100644
--- a/newlib/libc/sys/sparc64/sys/_timeval.h
+++ b/newlib/libc/sys/sparc64/sys/_timeval.h
@@ -1,7 +1,7 @@
 #ifndef _SYS_TIME_H
 #define _SYS_TIME_H
 
-#include <machine/types.h>
+#include <sys/_types.h>
 
 #ifndef __time_t_defined
 typedef _TIME_T_        time_t;
-- 
1.8.4.5



More information about the devel mailing list