This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: _NEWLIB_VERSION exposure through sys/cdefs.h


----- Original Message -----
> From: "Jonathan Roelofs" <jonathan@codesourcery.com>
> To: "Craig Howland" <howland@LGSInnovations.com>, "Jeff Johnston" <jjohnstn@redhat.com>
> Cc: newlib@sourceware.org, "Corinna Vinschen" <vinschen@redhat.com>, "Dan Albert" <danalbert@google.com>, "JF
> Bastien" <jfb@chromium.org>
> Sent: Wednesday, September 17, 2014 5:58:53 PM
> Subject: Re: _NEWLIB_VERSION exposure through sys/cdefs.h
> 
> 
> 
> On 9/17/14 3:51 PM, Craig Howland wrote:
> >
> > On 09/17/2014 05:47 PM, Jeff Johnston wrote:
> >> ----- Original Message -----
> >>> From: "Jonathan Roelofs" <jonathan@codesourcery.com>
> >>> To: newlib@sourceware.org, "Corinna Vinschen" <vinschen@redhat.com>
> >>> Cc: "Dan Albert" <danalbert@google.com>, "JF Bastien" <jfb@chromium.org>
> >>> Sent: Wednesday, September 17, 2014 5:09:32 PM
> >>> Subject: _NEWLIB_VERSION exposure through sys/cdefs.h
> >>>
> >>> Corinna,
> >>>
> >>> In libc++, we'd like to be able to tell when the underlying libc is
> >>> Newlib.
> >>> At
> >>> the moment, that requires us to do things like this:
> >>>
> >>> #if defined(__has_include) && __has_include(<newlib.h>)
> >>> #include <newlib.h>
> >>> #endif
> >>> #if defined(_NEWLIB_VERSION)
> >>> ...
> >>> #endif
> >>>
> >>> The problem with that strategy is that it does not work when using gcc,
> >>> as it
> >>> doesn't have __has_include support yet.  It came up in discussion that
> >>> sys/cdefs.h might be the right place for that, as that's where glibc puts
> >>> __GLIBC__.
> >>>
> >>> Would there be an objection to #include <newlib.h> from sys/cdefs.h?  Is
> >>> there a
> >>> better way to detect Newlib that I've overlooked?
> >>>
> >> Hi Jonathan,
> >>
> >> Corinna is on vacation until Oct 8th.
> >>
> >> My version of glibc has __GLIBC__ defined in features.h which in glibc is
> >> included by sys/cdefs.h.
> >>
> >> I wouldn't have a problem with simply adding a __NEWLIB__ macro in
> >> newlib's
> >> features.h.  I also wouldn't have a real problem with including newlib.h
> >> from
> >> sys/cdefs.h
> >> though I notice one of the newlib.h macros is missing an underscore and
> >> needs
> >> to be fixed.
> >>
> >> A way of solving your problem now would be to look for:
> >>
> >> #ifdef _MACHINE__DEFAULT_TYPES_H
> >>
> >> that is set by <machine/_default_types.h> which is a newlib-specific
> >> header
> >> that is included by sys/cdefs.h.  I don't see any platform overriding
> >> sys/cdefs.h
> >> except for x86-linux and it eventually includes <machine/_default_types.h>
> >> as
> >> well.
> >>
> >> Regards,
> >>
> >> -- Jeff J.
> > newlib.h gets included for almost every (and maybe even all) of the include
> > files, as _ansi.h includes it.  So you should be able to include just about
> > anything that you cared to and check for _NEWLIB_VERSION.  So, for example,
> > #include <stdio.h>
> > #if defined(_NEWLIB_VERSION)
> >    ...
> > #endif

Yes, it is in all the ANSI headers, but not in features.h or sys/cdefs.h.  So, if one had code
that included features.h and checked for various libraries (e.g. __GLIBC__, etc..)
it wouldn't work for newlib.

I had assumed that was what Jonathan was attempting to do.

> > works.  (This is more clear than _MACHINE_DEFAULT_TYPE_H and saves needing
> > to
> > add __NEWLIB__ as Jeff suggests.  Although the latter is not a bad idea.)

> Ah, good point. I do agree that __NEWLIB__ would be nice to have in either
> features.h or sys/cdefs.h though.
> 

I agree.  I think I will make the change regardless.

> 
> Thanks,
> 
> Jon
> >
> > Craig
> >>
> >>> Cheers,
> >>>
> >>> Jon
> >>>
> >>> --
> >>> Jon Roelofs
> >>> jonathan@codesourcery.com
> >>> CodeSourcery / Mentor Embedded
> >>>
> >
> 
> --
> Jon Roelofs
> jonathan@codesourcery.com
> CodeSourcery / Mentor Embedded
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]