[PATCH v2 1/3] Avoid cyclic header dependencies

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH v2 1/3] Avoid cyclic header dependencies

Sebastian Huber-4
RTEMS uses a considerable part of FreeBSD kernel and user space sources.
These sources are compiled with a __FreeBSD__ define.  On 2018-06-26
Gerald Pfeifer changed the GCC provided <stddef.h> so that it includes
<sys/_types.h> if __FreeBSD__ is defined.  The Newlib <sys/_types.h>
included <sys/lock.h> which includes <sys/cdefs.h> on RTEMS which
includes <stddef.h>.  To get rid of this cyclic dependency move the
optional _flock_t definition to <sys/reent.h>.

Signed-off-by: Sebastian Huber <[hidden email]>
---
 newlib/libc/include/sys/_types.h | 5 -----
 newlib/libc/include/sys/reent.h  | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h
index fc10531d5..90383b083 100644
--- a/newlib/libc/include/sys/_types.h
+++ b/newlib/libc/include/sys/_types.h
@@ -22,7 +22,6 @@
 #include <newlib.h>
 #include <sys/config.h>
 #include <machine/_types.h>
-#include <sys/lock.h>
 
 #ifndef __machine_blkcnt_t_defined
 typedef long __blkcnt_t;
@@ -171,10 +170,6 @@ typedef struct
 } _mbstate_t;
 #endif
 
-#ifndef __machine_flock_t_defined
-typedef _LOCK_RECURSIVE_T _flock_t;
-#endif
-
 #ifndef __machine_iconv_t_defined
 /* Iconv descriptor type */
 typedef void *_iconv_t;
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 6e55e1c1f..7f8124deb 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -30,6 +30,11 @@ typedef unsigned __Long __ULong;
 #include <sys/types.h>
 #endif
 
+#ifndef __machine_flock_t_defined
+#include <sys/lock.h>
+typedef _LOCK_RECURSIVE_T _flock_t;
+#endif
+
 #ifndef __Long
 #define __Long __int32_t
 typedef __uint32_t __ULong;
--
2.16.4

Reply | Threaded
Open this post in threaded view
|

[PATCH v2 2/3] Avoid <sys/cdefs.h> dependency in <sys/_types.h>

Sebastian Huber-4
Including <sys/cdefs.h> could result in cyclic header dependencies.

Signed-off-by: Sebastian Huber <[hidden email]>
---
 newlib/libc/include/sys/_types.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h
index 90383b083..0ed56ed44 100644
--- a/newlib/libc/include/sys/_types.h
+++ b/newlib/libc/include/sys/_types.h
@@ -210,10 +210,15 @@ typedef unsigned short __nlink_t;
 typedef long __suseconds_t; /* microseconds (signed) */
 typedef unsigned long __useconds_t; /* microseconds (unsigned) */
 
-#ifdef __GNUCLIKE_BUILTIN_VARARGS
+/*
+ * Must be identical to the __GNUCLIKE_BUILTIN_VAALIST definition in
+ * <sys/cdefs.h>.  The <sys/cdefs.h> must not be included here to avoid cyclic
+ * header dependencies.
+ */
+#if __GNUC_MINOR__ > 95 || __GNUC__ >= 3
 typedef __builtin_va_list __va_list;
 #else
 typedef char * __va_list;
-#endif /* __GNUCLIKE_BUILTIN_VARARGS */
+#endif
 
 #endif /* _SYS__TYPES_H */
--
2.16.4

Reply | Threaded
Open this post in threaded view
|

[PATCH v2 3/3] Fix <sys/_types.h> issues with <stddef.h>

Sebastian Huber-4
In reply to this post by Sebastian Huber-4
A commit from 2016 tried to address this GCC provided <stddef.h> issue

    #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
      || defined(__DragonFly__) \
      || defined(__FreeBSD_kernel__)
    /* __size_t is a typedef on FreeBSD 5, must not trash it. */
    #elif defined (__VMS__)
    /* __size_t is also a typedef on VMS.  */
    #else
    #define __size_t
    #endif

with an include of <stddef.h> before <sys/_types.h> in <sys/types.h>.
Is is not robust enough.  Do the include of <stddef.h> in <sys/_types.h>
directly and request only the necessary types.

Signed-off-by: Sebastian Huber <[hidden email]>
---
 newlib/libc/include/sys/_types.h | 6 +++---
 newlib/libc/include/sys/types.h  | 2 --
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h
index 0ed56ed44..017a0aaf6 100644
--- a/newlib/libc/include/sys/_types.h
+++ b/newlib/libc/include/sys/_types.h
@@ -19,6 +19,9 @@
 #ifndef _SYS__TYPES_H
 #define _SYS__TYPES_H
 
+#define __need_size_t
+#define __need_wint_t
+#include <stddef.h>
 #include <newlib.h>
 #include <sys/config.h>
 #include <machine/_types.h>
@@ -154,9 +157,6 @@ typedef long _ssize_t;
 
 typedef _ssize_t __ssize_t;
 
-#define __need_wint_t
-#include <stddef.h>
-
 #ifndef __machine_mbstate_t_defined
 /* Conversion state information.  */
 typedef struct
diff --git a/newlib/libc/include/sys/types.h b/newlib/libc/include/sys/types.h
index 19e3de689..4613ac81f 100644
--- a/newlib/libc/include/sys/types.h
+++ b/newlib/libc/include/sys/types.h
@@ -42,8 +42,6 @@ typedef __intptr_t register_t;
 #ifndef __need_inttypes
 
 #define _SYS_TYPES_H
-/* <stddef.h> must be before <sys/_types.h> for __size_t considerations */
-#include <stddef.h>
 #include <sys/_types.h>
 #include <sys/_stdint.h>
 
--
2.16.4

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 1/3] Avoid cyclic header dependencies

Corinna Vinschen
In reply to this post by Sebastian Huber-4
On May 16 14:40, Sebastian Huber wrote:

> RTEMS uses a considerable part of FreeBSD kernel and user space sources.
> These sources are compiled with a __FreeBSD__ define.  On 2018-06-26
> Gerald Pfeifer changed the GCC provided <stddef.h> so that it includes
> <sys/_types.h> if __FreeBSD__ is defined.  The Newlib <sys/_types.h>
> included <sys/lock.h> which includes <sys/cdefs.h> on RTEMS which
> includes <stddef.h>.  To get rid of this cyclic dependency move the
> optional _flock_t definition to <sys/reent.h>.
>
> Signed-off-by: Sebastian Huber <[hidden email]>
> ---
>  newlib/libc/include/sys/_types.h | 5 -----
>  newlib/libc/include/sys/reent.h  | 5 +++++
>  2 files changed, 5 insertions(+), 5 deletions(-)
Series pushed.  Can you please add a cover letter when sending a series?
It's kind of awkward to reply to a single patch in the series if the
entire series is affected.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer
Red Hat

signature.asc (849 bytes) Download Attachment