PATCH: Check LONG_MAX > INT_MAX for __WORDSIZE
H.J. Lu
hongjiu.lu@intel.com
Fri Apr 13 00:31:00 GMT 2012
Hi,
__LP64__ is defined for 64-bit since GCC 3.3. If a compiler isn't GCC
3.3 or newer, when __x86_64__ is defined and __LP64__ isn't defined, we
don't know if we are compiling for x86-64 or x32. This path includes
<limits.h> and checks LONG_MAX > INT_MAX for this case.
Tested on Linux/x86-64. OK for trunk?
Thanks.
H.J.
---
2012-04-12 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/x86_64/bits/wordsize.h: Include <features.h>.
(__WORDSIZE): Include <limits.h> and check LONG_MAX > INT_MAX
if compiler isn't GCC 3.3 or newer.
diff --git a/sysdeps/x86_64/bits/wordsize.h b/sysdeps/x86_64/bits/wordsize.h
index a40a0d8..b9c5448 100644
--- a/sysdeps/x86_64/bits/wordsize.h
+++ b/sysdeps/x86_64/bits/wordsize.h
@@ -1,8 +1,22 @@
-/* Determine the wordsize from the preprocessor defines. */
+/* Determine the wordsize from the preprocessor defines. __LP64__ is
+ defined for 64-bit since GCC 3.3. For compilers other than GCC 3.3
+ or newer, we check if LONG_MAX > INT_MAX. */
-#if defined __x86_64__
-# define __WORDSIZE 64
-# define __WORDSIZE_COMPAT32 1
+#include <features.h>
+
+#if __GNUC_PREREQ (3, 3)
+# if defined __x86_64__ && defined __LP64__
+# define __WORDSIZE 64
+# define __WORDSIZE_COMPAT32 1
+# else
+# define __WORDSIZE 32
+# endif
#else
-# define __WORDSIZE 32
+#include <limits.h>
+# if defined __x86_64__ && LONG_MAX > INT_MAX
+# define __WORDSIZE 64
+# define __WORDSIZE_COMPAT32 1
+# else
+# define __WORDSIZE 32
+# endif
#endif
More information about the Libc-alpha
mailing list