On 2018-09-04 17:51:30 -0700, Andres Freund wrote: > My current proposal is thus to do add a check that does > #if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__) > something-that-fails > #endif > in an autoconf test, and have configure complain if that > fails. Something roughly along the lines of > "Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use > -msse2 or use gcc."
Here's a patch along those lines. Greetings, Andres Freund
>From 4a457a5b907d1390c133097e9081ecf6fb1d30ef Mon Sep 17 00:00:00 2001 From: Andres Freund <and...@anarazel.de> Date: Thu, 13 Sep 2018 14:18:43 -0700 Subject: [PATCH] Error out for clang on x86-32 without SSE2 support, no -fexcess-precision. As clang currently doesn't support -fexcess-precision=standard, compiling x86-32 code with SSE2 disabled, can lead to problems with floating point overflow checks and the like. This issue was noticed because clang, on at least some BSDs, defaults to i386 compatibility, whereas it defaults to pentium4 on Linux. Our forced usage of __builtin_isinf() lead to some overflow checks not triggering when compiling for i386, e.g. when the result of the calculation didn't overflow in 80bit registers, but did so in 64bit. While we could just fall back to a non-builtin isinf, it seems likely that the use of 80bit registers leads to other problems (which is why we force the flag for GCC already). Therefore error out when detecting clang in that situation. Reported-By: Victor Wagner Analyzed-By: Andrew Gierth and Andres Freund Author: Andres Freund Discussion: https://postgr.es/m/20180905005130.ewk4xcs5dgyzc...@alap3.anarazel.de Backpatch: 9.3-, all supported versions are affected --- configure | 33 +++++++++++++++++++++++++++++++++ configure.in | 18 ++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/configure b/configure index c6a44a9078a..9b304023d3d 100755 --- a/configure +++ b/configure @@ -7023,6 +7023,39 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi +# Defend against clang being used on x86-32 without SSE2 enabled. As current +# versions of clang do not understand -fexcess-precision=standard, the use of +# x87 floating point operations leads to problems like isinf possibly returning +# false for a value that is infinite when converted from the 80bit register to +# the 8byte memory representation. +# +# Only perform the test if the compiler doesn't understand +# -fexcess-precision=standard, that way a potentially fixed compiler will work +# automatically. +if test "$pgac_cv_prog_CC_cflags__fexcess_precision_standard" = no; then +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + +#if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__) +choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + as_fn_error $? "Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc." "$LINENO" 5 +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' diff --git a/configure.in b/configure.in index 3ada48b5f95..2e60a89502c 100644 --- a/configure.in +++ b/configure.in @@ -624,6 +624,24 @@ choke me @%:@endif])], [], [AC_MSG_ERROR([do not put -ffast-math in CFLAGS])]) fi +# Defend against clang being used on x86-32 without SSE2 enabled. As current +# versions of clang do not understand -fexcess-precision=standard, the use of +# x87 floating point operations leads to problems like isinf possibly returning +# false for a value that is infinite when converted from the 80bit register to +# the 8byte memory representation. +# +# Only perform the test if the compiler doesn't understand +# -fexcess-precision=standard, that way a potentially fixed compiler will work +# automatically. +if test "$pgac_cv_prog_CC_cflags__fexcess_precision_standard" = no; then +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [ +@%:@if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__) +choke me +@%:@endif +])], [], +[AC_MSG_ERROR([Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc.])]) +fi + AC_PROG_CPP AC_SUBST(GCC) -- 2.18.0.rc2.dirty