Solaris and endian.h

Norm Jacobs norm.jacobs at oracle.com
Sun Sep 15 23:39:54 PDT 2013


A couple of days ago, I filed bug "17243 - not everybody has endian.h" 
and supplied a patch in the bug report.  I was made aware that I should 
send my patch here.

The short version of the problem is that Solaris doesn't have an 
'endian.h' to include, so when building 3.3, it fails in the first file 
that includes llvm/Support/Host.h.  The patch I am including below adds 
auto* tests for endian.h, machine/endian.h, and sys/isa_defs.h.  It also 
fixes the header to use the results of the tests.  I added cmake changes 
as well, but did not try building under cmake.

     -Norm

diff -r c048ce8b108b autoconf/configure.ac
--- a/autoconf/configure.ac	Mon Sep 16 00:37:54 2013 -0500
+++ b/autoconf/configure.ac	Mon Sep 16 00:40:45 2013 -0500
@@ -448,6 +448,7 @@
  
  dnl Check for the endianness of the target
  AC_C_BIGENDIAN(AC_SUBST([ENDIAN],[big]),AC_SUBST([ENDIAN],[little]))
+AC_CHECK_HEADERS([endian.h machine/endian.h sys/isa_defs.h])
  
  dnl Check for build platform executable suffix if we're cross-compiling
  if test "$cross_compiling" = yes; then
diff -r c048ce8b108b cmake/config-ix.cmake
--- a/cmake/config-ix.cmake	Mon Sep 16 00:37:54 2013 -0500
+++ b/cmake/config-ix.cmake	Mon Sep 16 00:40:45 2013 -0500
@@ -53,6 +53,9 @@
  check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
  check_include_file(memory.h HAVE_MEMORY_H)
  check_include_file(ndir.h HAVE_NDIR_H)
+check_include_file(endian.h HAVE_ENDIAN_H)
+check_include_file(machine/endian.h HAVE_MACHINE_ENDIAN_H)
+check_include_file(sys/isa_defs.h HAVE_SYS_ISA_DEFS_H)
  if( NOT PURE_WINDOWS )
    check_include_file(pthread.h HAVE_PTHREAD_H)
  endif()
diff -r c048ce8b108b include/llvm/Config/config.h.cmake
--- a/include/llvm/Config/config.h.cmake	Mon Sep 16 00:37:54 2013 -0500
+++ b/include/llvm/Config/config.h.cmake	Mon Sep 16 00:40:45 2013 -0500
@@ -116,6 +116,9 @@
  /* Define if you have the _dyld_func_lookup function. */
  #undef HAVE_DYLD
  
+/* Define to 1 if you have the <endian.h> header file. */
+#cmakedefine HAVE_ENDIAN_H ${HAVE_ENDIAN_H}
+
  /* Define to 1 if you have the <errno.h> header file. */
  #cmakedefine HAVE_ERRNO_H ${HAVE_ERRNO_H}
  
@@ -270,6 +273,9 @@
  /* Define to 1 if you have the `malloc_zone_statistics' function. */
  #cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS}
  
+/* Define to 1 if you have the <machine/endian.h> header file. */
+#cmakedefine HAVE_MACHINE_ENDIAN_H ${HAVE_MACHINE_ENDIAN_H}
+
  /* Define to 1 if you have the `memcpy' function. */
  #cmakedefine HAVE_MEMCPY ${HAVE_MEMCPY}
  
@@ -446,6 +452,9 @@
  /* Define to 1 if you have the <sys/ioctl.h> header file. */
  #cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H}
  
+/* Define to 1 if you have the <sys/isa_defs.h> header file. */
+#cmakedefine HAVE_SYS_ISA_DEFS_H ${HAVE_SYS_ISA_DEFS_H}
+
  /* Define to 1 if you have the <sys/mman.h> header file. */
  #cmakedefine HAVE_SYS_MMAN_H ${}
  
diff -r c048ce8b108b include/llvm/Config/config.h.in
--- a/include/llvm/Config/config.h.in	Mon Sep 16 00:37:54 2013 -0500
+++ b/include/llvm/Config/config.h.in	Mon Sep 16 00:40:45 2013 -0500
@@ -127,6 +127,9 @@
  /* Define if you have the _dyld_func_lookup function. */
  #undef HAVE_DYLD
  
+/* Define to 1 if you have the <endian.h> header file. */
+#undef HAVE_ENDIAN_H
+
  /* Define to 1 if you have the <errno.h> header file. */
  #undef HAVE_ERRNO_H
  
@@ -260,6 +263,9 @@
  /* Define to 1 if you have the `longjmp' function. */
  #undef HAVE_LONGJMP
  
+/* Define to 1 if you have the <machine/endian.h> header file. */
+#undef HAVE_MACHINE_ENDIAN_H
+
  /* Define to 1 if you have the <mach/mach.h> header file. */
  #undef HAVE_MACH_MACH_H
  
@@ -454,6 +460,9 @@
  /* Define to 1 if you have the <sys/ioctl.h> header file. */
  #undef HAVE_SYS_IOCTL_H
  
+/* Define to 1 if you have the <sys/isa_defs.h> header file. */
+#undef HAVE_SYS_ISA_DEFS_H
+
  /* Define to 1 if you have the <sys/mman.h> header file. */
  #undef HAVE_SYS_MMAN_H
  
diff -r c048ce8b108b include/llvm/Support/Host.h
--- a/include/llvm/Support/Host.h	Mon Sep 16 00:37:54 2013 -0500
+++ b/include/llvm/Support/Host.h	Mon Sep 16 00:40:45 2013 -0500
@@ -16,12 +16,25 @@
  
  #include "llvm/ADT/StringMap.h"
  
-#if defined(__linux__)
+#if defined(HAVE_ENDIAN_H)
  #include <endian.h>
-#else
-#ifndef LLVM_ON_WIN32
+#elif !defined(LLVM_ON_WIN32) && defined(HAVE_MACHINE_ENDIAN_H)
  #include <machine/endian.h>
+#elif !defined(HAVE_SYS_ISA_DEFS_H)
+
+#define __LITTLE_ENDIAN 1234
+#define __BIG_ENDIAN  4321
+
+#if defined(_LITTLE_ENDIAN)
+#define LITTLE_ENDIAN __LITTLE_ENDIAN
+#define BYTE_ORDER  LITTLE_ENDIAN
+#define BYTEORDER LITTLE_ENDIAN
+#elif defined(_BIG_ENDIAN)
+#define BIG_ENDIAN  __BIG_ENDIAN
+#define BYTE_ORDER  BIG_ENDIAN
+#define BYTEORDER BIG_ENDIAN
  #endif
+
  #endif
  
  #include <string>




More information about the llvm-commits mailing list