]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
This patch fixes a problem with detecting the target that gcc compiles for when
authorSebastian Pop <s.pop@samsung.com>
Wed, 16 Jan 2019 16:24:37 +0000 (10:24 -0600)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 24 Jan 2019 11:29:57 +0000 (12:29 +0100)
using -m32.  The error is in the way we detect GCC_ARCH in configure:

GCC_ARCH=`$CC $CFLAGS -dumpmachine | sed 's/-.*//g'`

Here is the output of gcc and clang:

$ gcc  -m32 -std=c99 -dumpmachine
x86_64-linux-gnu

$ clang  -m32 -std=c99 -dumpmachine
i386-pc-linux-gnu

It looks like it is a known problem:
https://gcc.gnu.org/ml/gcc-help/2018-05/msg00053.html This patch checks whether
the compiler has the flag -print-multiarch in which case it uses it instead of
-dumpmachine to print the compiler target:

$ gcc -print-multiarch
x86_64-linux-gnu
$ gcc -print-multiarch -m32
i386-linux-gnu
$ clang -print-multiarch
clang: error: unknown argument: '-print-multiarch'

There were a few places that used an explicit test for i686 that are now also
checking for i386 as this is the value set in ARCH for gcc and clang when
configuring zlib-ng with --32.

configure

index 24cfa98786f436231ea2e92ecdc13cf5bac1c415..fc7611228ec1443a0df19f218c4eeb066461a1f0 100755 (executable)
--- a/configure
+++ b/configure
@@ -266,20 +266,25 @@ if test "$gcc" -eq 1 && ($cc $CFLAGS -c $test.c) >> configure.log 2>&1; then
   echo ... using gcc >> configure.log
   CC="$cc"
   CFLAGS="${CFLAGS} -std=c99"
-  # Re-check arch if gcc is a cross-compiler
-  GCC_ARCH=`$CC $CFLAGS -dumpmachine | sed 's/-.*//g'`
-  case $GCC_ARCH in
+
+  # Re-check ARCH if the compiler is a cross-compiler.
+  if $CC -print-multiarch 1> /dev/null 2>&1; then
+      CC_ARCH=`$CC $CFLAGS -print-multiarch | sed 's/-.*//g'`
+  else
+      CC_ARCH=`$CC $CFLAGS -dumpmachine | sed 's/-.*//g'`
+  fi
+  case $CC_ARCH in
     i386 | i486 | i586 | i686)
       # Honor user choice if gcc is multilib and 64-bit is requested
       if test $build64 -eq 1; then
         ARCH=x86_64
       else
-        ARCH=$GCC_ARCH
+        ARCH=$CC_ARCH
       fi ;;
     x86_64)
       # Honor user choice if gcc is multilib and 32-bit is requested
       if test $build32 -ne 1; then
-        ARCH=$GCC_ARCH
+        ARCH=$CC_ARCH
       fi ;;
     arm | armeb)
       if test $native -eq 0; then
@@ -859,7 +864,7 @@ else
 fi
 
 # Check for SSE2 intrinsics
-if test "${ARCH}" = "i686"; then
+if test "${ARCH}" = "i386" -o "${ARCH}" = "i686"; then
 cat > $test.c << EOF
 #include <immintrin.h>
 int main(void) {
@@ -879,7 +884,7 @@ fi
 fi
 
 # Check for SSE4.2 CRC intrinsics
-if test "${ARCH}" = "i686" || test "${ARCH}" = "x86_64"; then
+if test "${ARCH}" = "i386" -o "${ARCH}" = "i686" -o "${ARCH}" = "x86_64"; then
 cat > $test.c << EOF
 int main(void) {
     unsigned crc = 0;
@@ -900,7 +905,7 @@ fi
 fi
 
 # Check for PCLMULQDQ intrinsics
-if test "${ARCH}" = "i686" || test "${ARCH}" = "x86_64"; then
+if test "${ARCH}" = "i386" -o "${ARCH}" = "i686" -o "${ARCH}" = "x86_64"; then
 cat > $test.c << EOF
 #include <immintrin.h>
 #include <wmmintrin.h>