[PATCH] Fix constant division for AMD64 assembly on Solaris/x86

Jussi Kivilinna jussi.kivilinna at iki.fi
Sun Jan 5 17:43:05 CET 2014


* configure.ac (gcry_cv_gcc_as_const_division_ok): Add new check for
constant division in assembly and test for "-Wa,--divide" workaround.
(gcry_cv_gcc_amd64_platform_as_ok): Check for also constant division.
--

Appearantly on Solaris/x86 '/' character is treated as begining of line
comment. This causes problems when compiling SHA-1 SSSE3 implementation:

On 02.01.2014 16:26, Richard PALO wrote:
>> COLLECT_GCC_OPTIONS='-D' 'HAVE_CONFIG_H' '-I' '.' '-I' '..' '-I' '../src' '-I' '/var/tmp/pkgsrc/security/libgcrypt/work/.buildlink/include' '-I' '/var/tmp/pkgsrc/security/libgcrypt/work/.buildlink/include/gettext' '-D' '_REENTRANT' '-O2' '-MT' 'sha1-ssse3-amd64.lo' '-MD' '-MP' '-MF' '.deps/sha1-ssse3-amd64.Tpo' '-c' '-fPIC' '-D' 'PIC' '-o' '.libs/sha1-ssse3-amd64.o' '-v' '-mtune=generic' '-march=x86-64'
>>  /usr/gnu/bin/as -v -I . -I .. -I ../src -I /var/tmp/pkgsrc/security/libgcrypt/work/.buildlink/include -I /var/tmp/pkgsrc/security/libgcrypt/work/.buildlink/include/gettext -V -Qy -s --64 -o .libs/sha1-ssse3-amd64.o /var/tmp//ccAxWPXX.s
>> GNU assembler version 2.23.1 (i386-pc-solaris2.11) using BFD version (GNU Binutils) 2.23.1
>> /var/tmp//ccAxWPXX.s: Assembler messages:
>> /var/tmp//ccAxWPXX.s:34: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:38: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:42: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:46: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:54: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:58: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:62: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:66: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:70: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:74: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:78: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:82: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:86: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:90: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:94: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:98: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:102: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:106: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:110: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:114: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:119: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:123: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:127: Error: unbalanced parenthesis in operand 1.
>> /var/tmp//ccAxWPXX.s:132: Error: unbalanced parenthesis in operand 1.
>
>
> apparently the paddd code, such as
>     `paddd (.LK_XMM + ((i)/20)*16) RIP, tmp0;`
> isn't digested well, appended is the generated assembler code.

On 02.01.2014 17:41, Richard PALO wrote:
> Hi again, after finding the following:
> https://sourceware.org/bugzilla/show_bug.cgi?id=4572
>
> I tried using '-Wa,--divide' and that seemed to workaround the problem...
>
> perhaps the code, or at least the Makefile could be adapted accordingly?

Patch adds detection of this feature and attempts to workaround issue with by
adding "-Wa,--divide" to CFLAGS. If workaround does not work (old GAS on
Solaris/x86), we'll disable AMD64 assembly.

Reported-by: Richard PALO <richard.palo at free.fr>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 configure.ac |   38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index e98fa4e..cdd82f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1077,11 +1077,42 @@ fi
 
 
 #
+# Check whether GCC assembler needs "-Wa,--divide" to correctly handle
+# constant division
+#
+if test $amd64_as_feature_detection = yes; then
+  AC_CACHE_CHECK([whether GCC assembler handles division correctly],
+       [gcry_cv_gcc_as_const_division_ok],
+       [gcry_cv_gcc_as_const_division_ok=no
+        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+          [[__asm__("xorl \$(123456789/12345678), %ebp;\n\t");]])],
+          [gcry_cv_gcc_as_const_division_ok=yes])])
+  if test "$gcry_cv_gcc_as_const_division_ok" = "no" ; then
+    #
+    # Add '-Wa,--divide' to CFLAGS and try check again.
+    #
+    _gcc_cflags_save="$CFLAGS"
+    CFLAGS="$CFLAGS -Wa,--divide"
+    AC_CACHE_CHECK([whether GCC assembler handles division correctly with "-Wa,--divide"],
+         [gcry_cv_gcc_as_const_division_with_wadivide_ok],
+         [gcry_cv_gcc_as_const_division_with_wadivide_ok=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+            [[__asm__("xorl \$(123456789/12345678), %ebp;\n\t");]])],
+            [gcry_cv_gcc_as_const_division_with_wadivide_ok=yes])])
+    CFLAGS="$_gcc_cflags_save"
+    if test "$gcry_cv_gcc_as_const_division_ok" = "yes" ; then
+      CFLAGS="$CFLAGS -Wa,--divide"
+    fi
+  fi
+fi
+
+
+#
 # Check whether GCC assembler supports features needed for our amd64
 # implementations
 #
 if test $amd64_as_feature_detection = yes; then
-    AC_CACHE_CHECK([whether GCC assembler is compatible for amd64 assembly implementations],
+  AC_CACHE_CHECK([whether GCC assembler is compatible for amd64 assembly implementations],
        [gcry_cv_gcc_amd64_platform_as_ok],
        [gcry_cv_gcc_amd64_platform_as_ok=no
         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
@@ -1094,6 +1125,11 @@ if test $amd64_as_feature_detection = yes; then
 		"asmfunc:\n\t"
                 ".size asmfunc,.-asmfunc;\n\t"
                 ".type asmfunc, at function;\n\t"
+		/* Test if assembler allows use of '/' for constant division
+		 * (Solaris/x86 issue). If previous constant division check
+		 * and "-Wa,--divide" workaround failed, this causes assembly
+		 * to be disable on this machine. */
+		"xorl \$(123456789/12345678), %ebp;\n\t"
             );]])],
           [gcry_cv_gcc_amd64_platform_as_ok=yes])])
   if test "$gcry_cv_gcc_amd64_platform_as_ok" = "yes" ; then




More information about the Gcrypt-devel mailing list