Commit b2a343ffc68f1af5368281e063c0ca5571c611cc

H.J. Lu 2017-10-25T04:36:49

Don't include WIN64/EFI64 for x32 Since x32 doesn't support WIN64/EFI64, don't include it for x32. Also x32 has sizeof size_t == 4. But TARGET should be X86_64.

diff --git a/configure.host b/configure.host
index b5e1ec7..34e83f7 100644
--- a/configure.host
+++ b/configure.host
@@ -106,10 +106,18 @@ case "${host}" in
 	if test $ac_cv_sizeof_size_t = 4; then
 	  case "$host" in
 	    x86_64-*x32|x86_64-x32-*)
+	      TARGET_X32=yes
 	      TARGET=X86_64
 	      ;;
 	    *)
-	      TARGET=X86
+	      echo 'int foo (void) { return __x86_64__; }' > conftest.c
+	      if $CC $CFLAGS -Werror -S conftest.c -o conftest.s > /dev/null 2>&1; then
+		TARGET_X32=yes
+		TARGET=X86_64
+	      else
+		TARGET=X86;
+	      fi
+	      rm -f conftest.*
 	      ;;
           esac
 	else
@@ -255,7 +263,11 @@ case "${TARGET}" in
 	SOURCES="ffi.c sysv.S"
 	;;
   X86_64)
-	SOURCES="ffi64.c unix64.S ffiw64.c win64.S"
+	if test x"$TARGET_X32" = xyes; then
+		SOURCES="ffi64.c unix64.S"
+	else
+		SOURCES="ffi64.c unix64.S ffiw64.c win64.S"
+	fi
 	;;
   X86_WIN64)
 	if test "$MSVC" = 1; then
diff --git a/testsuite/lib/libffi.exp b/testsuite/lib/libffi.exp
index 37e4cf6..7c65f81 100644
--- a/testsuite/lib/libffi.exp
+++ b/testsuite/lib/libffi.exp
@@ -324,7 +324,8 @@ proc run-many-tests { testcases extra_flags } {
                 "-DABI_NUM=FFI_THISCALL -DABI_ATTR=__THISCALL__"
                 "-DABI_NUM=FFI_FASTCALL -DABI_ATTR=__FASTCALL__"
             }
-        } elseif [istarget "x86_64-*-*"] {
+        } elseif { [istarget "x86_64-*-*"] \
+		   && [libffi_feature_test "#ifndef __ILP32__"] } {
             set targetabis {
                 ""
                 "-DABI_NUM=FFI_WIN64 -DABI_ATTR=__MSABI__"