Skip to content

Commit bd1463e

Browse files
committed
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.ewk4xcs5dgyzcy45@alap3.anarazel.de Backpatch: 9.3-, all supported versions are affected
1 parent 925673f commit bd1463e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

configure

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7023,6 +7023,39 @@ fi
70237023
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
70247024
fi
70257025

7026+
# Defend against clang being used on x86-32 without SSE2 enabled. As current
7027+
# versions of clang do not understand -fexcess-precision=standard, the use of
7028+
# x87 floating point operations leads to problems like isinf possibly returning
7029+
# false for a value that is infinite when converted from the 80bit register to
7030+
# the 8byte memory representation.
7031+
#
7032+
# Only perform the test if the compiler doesn't understand
7033+
# -fexcess-precision=standard, that way a potentially fixed compiler will work
7034+
# automatically.
7035+
if test "$pgac_cv_prog_CC_cflags__fexcess_precision_standard" = no; then
7036+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7037+
/* end confdefs.h. */
7038+
7039+
int
7040+
main ()
7041+
{
7042+
7043+
#if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__)
7044+
choke me
7045+
#endif
7046+
7047+
;
7048+
return 0;
7049+
}
7050+
_ACEOF
7051+
if ac_fn_c_try_compile "$LINENO"; then :
7052+
7053+
else
7054+
as_fn_error $? "Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc." "$LINENO" 5
7055+
fi
7056+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7057+
fi
7058+
70267059
ac_ext=c
70277060
ac_cpp='$CPP $CPPFLAGS'
70287061
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'

configure.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,24 @@ choke me
624624
@%:@endif])], [], [AC_MSG_ERROR([do not put -ffast-math in CFLAGS])])
625625
fi
626626

627+
# Defend against clang being used on x86-32 without SSE2 enabled. As current
628+
# versions of clang do not understand -fexcess-precision=standard, the use of
629+
# x87 floating point operations leads to problems like isinf possibly returning
630+
# false for a value that is infinite when converted from the 80bit register to
631+
# the 8byte memory representation.
632+
#
633+
# Only perform the test if the compiler doesn't understand
634+
# -fexcess-precision=standard, that way a potentially fixed compiler will work
635+
# automatically.
636+
if test "$pgac_cv_prog_CC_cflags__fexcess_precision_standard" = no; then
637+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
638+
@%:@if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__)
639+
choke me
640+
@%:@endif
641+
])], [],
642+
[AC_MSG_ERROR([Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc.])])
643+
fi
644+
627645
AC_PROG_CPP
628646
AC_SUBST(GCC)
629647

0 commit comments

Comments
 (0)