Message ID | 1460713488-18283-1-git-send-email-sebastian.huber@embedded-brains.de |
---|---|
State | New |
Headers | show |
On Fri, Apr 15, 2016 at 11:44 AM, Sebastian Huber <sebastian.huber@embedded-brains.de> wrote: > I work currently on a better FreeBSD compatibility for Newlib. For > RTEMS we use the network, USB, SD/MMC stacks from FreeBSD. It would be > nice to use <sys/types.h>, etc. from Newlib directly to compile FreeBSD > user and kernel space files. > > Various FreeBSD source and header files need a typedef __size_t via > <sys/_types.h>. Unfortunately the GCC provided <stddef.h> uses > > #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 This looks odd - maybe it was meant to be a #undef? OTOH there are a whole lot of other similar cases there which do not make sense to me... Richard. > #endif > > and therefore defines __size_t to nothing on Newlib targets which would > trash a __size_t typedef. There exists no Newlib builtin define which > we could add here. As a workaround I include <stddef.h> before > <sys/_types.h> in <sys/types.h> and undefine __size_t in <sys/_types.h>. > > This works fine so far, but breaks if someone includes <stddef.h> after > <sys/_types.h> the first time. > > This patch would address this issue, but I do not know which other > issues it generates. > > gcc/ChangeLog > 2016-04-15 Sebastian Huber <sebastian.huber@embedded-brains.de> > > * ginclude/stddef.h (__size_t): Define to __SIZE_TYPE__. > --- > gcc/ginclude/stddef.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h > index d711530..8c2e22e 100644 > --- a/gcc/ginclude/stddef.h > +++ b/gcc/ginclude/stddef.h > @@ -207,7 +207,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; > #elif defined (__VMS__) > /* __size_t is also a typedef on VMS. */ > #else > -#define __size_t > +#define __size_t __SIZE_TYPE__ > #endif > #ifndef __SIZE_TYPE__ > #define __SIZE_TYPE__ long unsigned int > -- > 1.8.4.5 >
On 15/04/16 12:23, Richard Biener wrote: > On Fri, Apr 15, 2016 at 11:44 AM, Sebastian Huber > <sebastian.huber@embedded-brains.de> wrote: >> >I work currently on a better FreeBSD compatibility for Newlib. For >> >RTEMS we use the network, USB, SD/MMC stacks from FreeBSD. It would be >> >nice to use <sys/types.h>, etc. from Newlib directly to compile FreeBSD >> >user and kernel space files. >> > >> >Various FreeBSD source and header files need a typedef __size_t via >> ><sys/_types.h>. Unfortunately the GCC provided <stddef.h> uses >> > >> > #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 > This looks odd - maybe it was meant to be a #undef? OTOH there are > a whole lot of other similar cases there which do not make sense to me... No, in case __size_t is defined, then we don't end up in this spot. stddef.h tests for various guard defines and if none of them is defined, then it typedefs size_t and defines all the guard defines to nothing, except for __size_t on some targets.
diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h index d711530..8c2e22e 100644 --- a/gcc/ginclude/stddef.h +++ b/gcc/ginclude/stddef.h @@ -207,7 +207,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; #elif defined (__VMS__) /* __size_t is also a typedef on VMS. */ #else -#define __size_t +#define __size_t __SIZE_TYPE__ #endif #ifndef __SIZE_TYPE__ #define __SIZE_TYPE__ long unsigned int