Including machine/endian.h

Greg Lewis glewis at
Wed Feb 4 22:25:43 PST 2009

G'day Michael,

On Wed, Feb 04, 2009 at 08:37:03PM -0500, Michael Franz wrote:
> I have been working on compiling the bsd-port repo on linux and ran into the
> following issue.  fdlibm.h includes machine/endian.h, this does not work on
> linux, there is no such file.  I removed the include and it works find on OS
> X.  Based on the limited research I did, including machine/endian.h should
> not be done.  sys/types.h should be used instead.
> I have included the patch to remove the un-necessary include.  Can this
> someone test this on the other BSDs?

It will work, but it basically works by accident.  Which is what it does
now anyway.  We did have more extensive patches to this file in an earlier
port that made it work correctly, I'll see if I can dig them out.

If you look at what the code does, it basically checks for _LITTLE_ENDIAN
being defined as an indicator that this is a little endian platform.  This
is incorrect on BSD (except for maybe OS X) since both _LITTLE_ENDIAN and
_BIG_ENDIAN are defined on all architectures and to determine the
endianness the correct thing to do is to check on BYTE_ORDER.  It happens
to work right now because there are no supported big endian platforms that
Java has been ported to for BSD.

I'm not sure how this works on OS X either before or after your change
since machine/endian.h on OS X (or rather i386/endian.h) doesn't appear
to define _LITTLE_ENDIAN (but rather __DARWIN_LITTLE_ENDIAN).

I think the right thing probably looks something like

#include <machine/endian.h>
#elif __linux__
#include <endian.h>

And then where it currently does '#ifdef _LITTLE_ENDIAN' instead do

#if (defined(__solaris__) && defined(_LITTLE_ENDIAN)) || \

but I haven't tried that or dug out our previous changes.

> --- a/src/share/native/java/lang/fdlibm/include/fdlibm.h    Tue Oct 28
> 20:35:48 2008 -0400
> +++ b/src/share/native/java/lang/fdlibm/include/fdlibm.h    Wed Feb 04
> 20:32:35 2009 -0500
> @@ -27,7 +27,6 @@
>  #ifdef __OpenBSD__
>  #include <sys/types.h>
>  #endif
> -#include <machine/endian.h>
>  #include "jfdlibm.h"


Greg Lewis                          Email   : glewis at
Eyes Beyond                         Web     :
Information Technology              FreeBSD : glewis at

More information about the bsd-port-dev mailing list