johannes                                 Tue, 09 Feb 2010 21:58:13 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=294825

Log:
Detect if we can rely on compiler-specific alignment features else use custom
workarounds. Fixes #50753

Bug: http://bugs.php.net/50753 (Assigned) crypt_sha256.c / crypt_sha512.c - Gnu 
specific code, non-Gnu compiler 
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/standard/config.m4
    U   php/php-src/branches/PHP_5_3/ext/standard/crypt_sha256.c
    U   php/php-src/branches/PHP_5_3/ext/standard/crypt_sha512.c
    U   php/php-src/trunk/ext/standard/config.m4
    U   php/php-src/trunk/ext/standard/crypt_sha256.c
    U   php/php-src/trunk/ext/standard/crypt_sha512.c

Modified: php/php-src/branches/PHP_5_3/ext/standard/config.m4
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/config.m4	2010-02-09 21:38:09 UTC (rev 294824)
+++ php/php-src/branches/PHP_5_3/ext/standard/config.m4	2010-02-09 21:58:13 UTC (rev 294825)
@@ -235,6 +235,41 @@
 dnl If one of them is missing, use our own implementation, portable code is then possible
 dnl
 if test "$ac_cv_crypt_blowfish" = "no" || test "$ac_cv_crypt_des" = "no" || test "$ac_cv_crypt_ext_des" = "no" || test "x$php_crypt_r" = "x0"; then
+
+  dnl
+  dnl Check for __alignof__ support in the compiler
+  dnl
+  AC_CACHE_CHECK(whether the compiler supports __alignof__,ac_cv_alignof_exists,[
+  AC_TRY_COMPILE([
+int main() {
+	int align = __alignof__(int);
+	return 0;
+}
+  ],[
+    ac_cv_alignof_exists=yes
+  ],[
+    ac_cv_alignof_exists=no
+  ])])
+  if test "$ac_cv_alignof_exists" = "yes"; then
+    AC_DEFINE([HAVE_ALIGNOF], 1, [whether the compiler supports __alignof__])
+  fi
+
+  dnl
+  dnl Check for __attribute__ ((__aligned__)) support in the compiler
+  dnl
+  AC_CACHE_CHECK(whether the compiler supports aligned attribute,ac_cv_attribute_aligned,[
+  AC_TRY_COMPILE([
+    unsigned char test[32] __attribute__ ((__aligned__ (__alignof__ (int))));
+  ],[
+    ac_cv_attribute_aligned=yes
+  ],[
+    ac_cv_attribute_aligned=no
+  ])])
+  if test "$ac_cv_attribute_aligned" = "yes"; then
+    AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [wheter the compiler supports __attribute__ ((__aligned__))])
+  fi
+
+
   AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 1, [Whether PHP has to use its own crypt_r for blowfish, des, ext des and md5])
   AC_DEFINE_UNQUOTED(PHP_STD_DES_CRYPT, 1, [Whether the system supports standard DES salt])
   AC_DEFINE_UNQUOTED(PHP_BLOWFISH_CRYPT, 1, [Whether the system supports BlowFish salt])

Modified: php/php-src/branches/PHP_5_3/ext/standard/crypt_sha256.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/crypt_sha256.c	2010-02-09 21:38:09 UTC (rev 294824)
+++ php/php-src/branches/PHP_5_3/ext/standard/crypt_sha256.c	2010-02-09 21:58:13 UTC (rev 294825)
@@ -18,6 +18,15 @@
 # elif HAVE_STDINT_H
 #  include <stdint.h>
 # endif
+# ifndef HAVE_ALIGNOF
+#  include <stddef.h>
+#  define __alignof__(type) offsetof (struct { char c; type member;}, member)
+# endif
+# if HAVE_ATTRIBUTE_ALIGNED
+#  define ALIGNED(size) __attribute__ ((__aligned__ (size)))
+# else
+#  define ALIGNED(size)
+# endif
 #endif

 #include <stdio.h>
@@ -342,10 +351,8 @@
 	__declspec(align(32)) unsigned char temp_result[32];
 # endif
 #else
-	unsigned char alt_result[32]
-	__attribute__ ((__aligned__ (__alignof__ (uint32_t))));
-	unsigned char temp_result[32]
-	__attribute__ ((__aligned__ (__alignof__ (uint32_t))));
+	unsigned char alt_result[32] ALIGNED(__alignof__ (uint32_t));
+	unsigned char temp_result[32] ALIGNED(__alignof__ (uint32_t));
 #endif

 	struct sha256_ctx ctx;

Modified: php/php-src/branches/PHP_5_3/ext/standard/crypt_sha512.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/crypt_sha512.c	2010-02-09 21:38:09 UTC (rev 294824)
+++ php/php-src/branches/PHP_5_3/ext/standard/crypt_sha512.c	2010-02-09 21:58:13 UTC (rev 294825)
@@ -17,6 +17,15 @@
 # elif HAVE_STDINT_H
 #  include <stdint.h>
 # endif
+# ifndef HAVE_ALIGNOF
+#  include <stddef.h>
+#  define __alignof__(type) offsetof (struct { char c; type member;}, member)
+# endif
+# if HAVE_ATTRIBUTE_ALIGNED
+#  define ALIGNED(size) __attribute__ ((__aligned__ (size)))
+# else
+#  define ALIGNED(size)
+# endif
 #endif

 #include <stdio.h>
@@ -370,10 +379,8 @@
 	__declspec(align(64)) unsigned char temp_result[64];
 # endif
 #else
-	unsigned char alt_result[64]
-		__attribute__ ((__aligned__ (__alignof__ (uint64_t))));
-	unsigned char temp_result[64]
-		__attribute__ ((__aligned__ (__alignof__ (uint64_t))));
+	unsigned char alt_result[64] ALIGNED(__alignof__ (uint64_t));
+	unsigned char temp_result[64] ALIGNED(__alignof__ (uint64_t));
 #endif
 	struct sha512_ctx ctx;
 	struct sha512_ctx alt_ctx;

Modified: php/php-src/trunk/ext/standard/config.m4
===================================================================
--- php/php-src/trunk/ext/standard/config.m4	2010-02-09 21:38:09 UTC (rev 294824)
+++ php/php-src/trunk/ext/standard/config.m4	2010-02-09 21:58:13 UTC (rev 294825)
@@ -236,6 +236,41 @@
 dnl If one of them is missing, use our own implementation, portable code is then possible
 dnl
 if test "$ac_cv_crypt_blowfish" = "no" || test "$ac_cv_crypt_des" = "no" || test "$ac_cv_crypt_ext_des" = "no" || test "x$php_crypt_r" = "x0"; then
+
+  dnl
+  dnl Check for __alignof__ support in the compiler
+  dnl
+  AC_CACHE_CHECK(whether the compiler supports __alignof__,ac_cv_alignof_exists,[
+  AC_TRY_COMPILE([
+int main() {
+	int align = __alignof__(int);
+	return 0;
+}
+  ],[
+    ac_cv_alignof_exists=yes
+  ],[
+    ac_cv_alignof_exists=no
+  ])])
+  if test "$ac_cv_alignof_exists" = "yes"; then
+    AC_DEFINE([HAVE_ALIGNOF], 1, [whether the compiler supports __alignof__])
+  fi
+
+  dnl
+  dnl Check for __attribute__ ((__aligned__)) support in the compiler
+  dnl
+  AC_CACHE_CHECK(whether the compiler supports aligned attribute,ac_cv_attribute_aligned,[
+  AC_TRY_COMPILE([
+    unsigned char test[32] __attribute__ ((__aligned__ (__alignof__ (int))));
+  ],[
+    ac_cv_attribute_aligned=yes
+  ],[
+    ac_cv_attribute_aligned=no
+  ])])
+  if test "$ac_cv_attribute_aligned" = "yes"; then
+    AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [wheter the compiler supports __attribute__ ((__aligned__))])
+  fi
+
+
   AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 1, [Whether PHP has to use its own crypt_r for blowfish, des, ext des and md5])
   AC_DEFINE_UNQUOTED(PHP_STD_DES_CRYPT, 1, [Whether the system supports standard DES salt])
   AC_DEFINE_UNQUOTED(PHP_BLOWFISH_CRYPT, 1, [Whether the system supports BlowFish salt])

Modified: php/php-src/trunk/ext/standard/crypt_sha256.c
===================================================================
--- php/php-src/trunk/ext/standard/crypt_sha256.c	2010-02-09 21:38:09 UTC (rev 294824)
+++ php/php-src/trunk/ext/standard/crypt_sha256.c	2010-02-09 21:58:13 UTC (rev 294825)
@@ -18,6 +18,15 @@
 # elif HAVE_STDINT_H
 #  include <stdint.h>
 # endif
+# ifndef HAVE_ALIGNOF
+#  include <stddef.h>
+#  define __alignof__(type) offsetof (struct { char c; type member;}, member)
+# endif
+# if HAVE_ATTRIBUTE_ALIGNED
+#  define ALIGNED(size) __attribute__ ((__aligned__ (size)))
+# else
+#  define ALIGNED(size)
+# endif
 #endif

 #include <stdio.h>
@@ -335,10 +344,8 @@
 	__declspec(align(32)) unsigned char alt_result[32];
 	__declspec(align(32)) unsigned char temp_result[32];
 #else
-	unsigned char alt_result[32]
-	__attribute__ ((__aligned__ (__alignof__ (uint32_t))));
-	unsigned char temp_result[32]
-	__attribute__ ((__aligned__ (__alignof__ (uint32_t))));
+	unsigned char alt_result[32] ALIGNED(__alignof__ (uint32_t));
+	unsigned char temp_result[32] ALIGNED(__alignof__ (uint32_t));
 #endif

 	struct sha256_ctx ctx;

Modified: php/php-src/trunk/ext/standard/crypt_sha512.c
===================================================================
--- php/php-src/trunk/ext/standard/crypt_sha512.c	2010-02-09 21:38:09 UTC (rev 294824)
+++ php/php-src/trunk/ext/standard/crypt_sha512.c	2010-02-09 21:58:13 UTC (rev 294825)
@@ -17,6 +17,15 @@
 # elif HAVE_STDINT_H
 #  include <stdint.h>
 # endif
+# ifndef HAVE_ALIGNOF
+#  include <stddef.h>
+#  define __alignof__(type) offsetof (struct { char c; type member;}, member)
+# endif
+# if HAVE_ATTRIBUTE_ALIGNED
+#  define ALIGNED(size) __attribute__ ((__aligned__ (size)))
+# else
+#  define ALIGNED(size)
+# endif
 #endif

 #include <stdio.h>
@@ -363,10 +372,8 @@
 	__declspec(align(64)) unsigned char alt_result[64];
 	__declspec(align(64)) unsigned char temp_result[64];
 #else
-	unsigned char alt_result[64]
-		__attribute__ ((__aligned__ (__alignof__ (uint64_t))));
-	unsigned char temp_result[64]
-		__attribute__ ((__aligned__ (__alignof__ (uint64_t))));
+	unsigned char alt_result[64] ALIGNED(__alignof__ (uint64_t));
+	unsigned char temp_result[64] ALIGNED(__alignof__ (uint64_t));
 #endif
 	struct sha512_ctx ctx;
 	struct sha512_ctx alt_ctx;
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to