Bug 2407

Summary: platform.h fails to detect endianess on Mac OS X 10.6
Product: Busybox Reporter: Joe Roback <openwrt>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: minor CC: busybox-cvs
Priority: P5    
Version: 1.17.x   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS   
Host: Target:
Build:
Attachments: compilation fix for Mac OS X with endianess detection in platform.h

Description Joe Roback 2010-08-16 00:57:04 UTC
Recently, from 1.16.2 to 1.17.1 include/platform.h changed its endianess detection and it broke compilation on Mac OS X. It seems this broke OpenBSD as well:

http://lists.busybox.net/pipermail/busybox/2010-August/073031.html

I would suspect it probably breaks NetBSD also. The patch provided in the mailing list does not work for Mac OS X. If __APPLE__ is treated like __FreeBSD__ everything compiles fine. For example,


--- a/include/platform.h	2010-07-05 20:25:54.000000000 -0600
+++ b/include/platform.h	2010-08-15 18:21:44.000000000 -0600
@@ -154,14 +154,14 @@
 # include <sex.h>
 # define __BIG_ENDIAN__ (BYTE_ORDER == BIG_ENDIAN)
 # define __BYTE_ORDER BYTE_ORDER
-#elif defined __FreeBSD__
+#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
 # include <sys/resource.h>	/* rlimit */
 # include <machine/endian.h>
 # define bswap_64 __bswap64
 # define bswap_32 __bswap32
 # define bswap_16 __bswap16
 # define __BIG_ENDIAN__ (_BYTE_ORDER == _BIG_ENDIAN)
-#elif !defined __APPLE__
+#else
 # include <byteswap.h>
 # include <endian.h>
 #endif

This worked for me for Mac OS X and OpenBSD.. I'd suspect it fixes NetBSD also, but its untested.
Comment 1 Denys Vlasenko 2010-08-16 01:11:44 UTC
Can you provide a patch, against 1.17.1, which has a standalone #elif __APPLE__ block, without merging it with other OSes?
Comment 2 Joe Roback 2010-08-16 01:18:48 UTC
Sure, no problem. I attached it as well.

--- a/include/platform.h	2010-07-05 20:25:54.000000000 -0600
+++ b/include/platform.h	2010-08-15 19:17:00.000000000 -0600
@@ -161,7 +161,14 @@
 # define bswap_32 __bswap32
 # define bswap_16 __bswap16
 # define __BIG_ENDIAN__ (_BYTE_ORDER == _BIG_ENDIAN)
-#elif !defined __APPLE__
+#elif defined(__APPLE__)
+# include <sys/resource.h>	/* rlimit */
+# include <machine/endian.h>
+# define bswap_64 __bswap64
+# define bswap_32 __bswap32
+# define bswap_16 __bswap16
+# define __BIG_ENDIAN__ (_BYTE_ORDER == _BIG_ENDIAN)
+#else
 # include <byteswap.h>
 # include <endian.h>
 #endif
Comment 3 Joe Roback 2010-08-16 01:19:32 UTC
Created attachment 2347 [details]
compilation fix for Mac OS X with endianess detection in platform.h
Comment 4 Denys Vlasenko 2010-10-28 22:28:53 UTC
forgot to close this bug... fixed in git sometime ago, will be in 1.18.x