Divergence from BSD sources, e.g. __GNUC_PREREQ()
Ralf Corsepius
ralf.corsepius@rtems.org
Thu Apr 4 08:49:00 GMT 2013
On 04/04/2013 09:59 AM, Sebastian Huber wrote:
> Hello,
>
> I have some questions about the divergence from BSD sources. The
> background is that <sys/queue.h> is broken in Newlib since __offsetof()
> is undefined. I wanted to update the file in Newlib with the latest
> version from FreeBSD, but now some problems arise.
>
> What is the purpose of <sys/cdefs.h> in Newlib?
Like the bsd version, it's an internal libc header, whose only purpose
is to provide some internal defines and not meant to be used in
applications.
> This file seems to be
> derived from BSD sources, but current BSD versions look quite
> different.
Correct, they were forked long time ago and now have diverged. That
said, though they have common origins, BSD actually isn't of actual
interest here and even less so FreeBSD-compatibility, IMO.
> For example last year the new macro __GNUC_PREREQ() was
> introduced in "libc/include/sys/features.h":
>
> /* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */
> #ifndef __GNUC_PREREQ
> # if defined __GNUC__ && defined __GNUC_MINOR__
> # define __GNUC_PREREQ(maj, min) \
> ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
> # else
> # define __GNUC_PREREQ(maj, min) 0
> # endif
> #endif /* __GNUC_PREREQ */
>
> In FreeBSD we have a similar macro in <sys/cdefs.h>:
>
> http://svnweb.freebsd.org/base/head/sys/sys/cdefs.h?revision=241374
>
> /*
> * Macro to test if we're using a specific version of gcc or later.
> */
> #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
> #define __GNUC_PREREQ__(ma, mi) \
> (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
> #else
> #define __GNUC_PREREQ__(ma, mi) 0
> #endif
>
> Why don't we follow the BSD development more to simplify code re-use?
Please elaborate the bug in newlib this would fix. icc has never been of
interest to newlib, while __GNUC_PREREQ can't be removed without
introducing incompatibilities in newlib.
Also note that newlib's __GNUC_PREREQ and FreeBSD's __GNUC_PREREQ__ are
not interchangable (__GNUC_PREREQ can be used for version comparison,
__GNUC_PREREQ__ is binary).
> The latest version of FreeBSD <sys/queue.h> uses __containerof():
IMO, this is a FreeBSD implementation detail, newlib may or may not
adopt for BSD compatibility.
That said, I am against adopting it, because "FreeBSD sys/queue.h" has a
history FreeBSD changing it ad-lib, which means any attempt to provide
FreeBSD compatibility will fail in longer terms.
Ralf
More information about the Newlib
mailing list