Skip to content

Commit 29196e1

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 c0c5668 commit 29196e1

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
@@ -5090,6 +5090,39 @@ fi
50905090
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
50915091
fi
50925092

5093+
# Defend against clang being used on x86-32 without SSE2 enabled. As current
5094+
# versions of clang do not understand -fexcess-precision=standard, the use of
5095+
# x87 floating point operations leads to problems like isinf possibly returning
5096+
# false for a value that is infinite when converted from the 80bit register to
5097+
# the 8byte memory representation.
5098+
#
5099+
# Only perform the test if the compiler doesn't understand
5100+
# -fexcess-precision=standard, that way a potentially fixed compiler will work
5101+
# automatically.
5102+
if test "$pgac_cv_prog_cc_cflags__fexcess_precision_standard" = no; then
5103+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5104+
/* end confdefs.h. */
5105+
5106+
int
5107+
main ()
5108+
{
5109+
5110+
#if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__)
5111+
choke me
5112+
#endif
5113+
5114+
;
5115+
return 0;
5116+
}
5117+
_ACEOF
5118+
if ac_fn_c_try_compile "$LINENO"; then :
5119+
5120+
else
5121+
as_fn_error $? "Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc." "$LINENO" 5
5122+
fi
5123+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5124+
fi
5125+
50935126
ac_ext=c
50945127
ac_cpp='$CPP $CPPFLAGS'
50955128
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
@@ -526,6 +526,24 @@ choke me
526526
@%:@endif], [], [AC_MSG_ERROR([do not put -ffast-math in CFLAGS])])
527527
fi
528528

529+
# Defend against clang being used on x86-32 without SSE2 enabled. As current
530+
# versions of clang do not understand -fexcess-precision=standard, the use of
531+
# x87 floating point operations leads to problems like isinf possibly returning
532+
# false for a value that is infinite when converted from the 80bit register to
533+
# the 8byte memory representation.
534+
#
535+
# Only perform the test if the compiler doesn't understand
536+
# -fexcess-precision=standard, that way a potentially fixed compiler will work
537+
# automatically.
538+
if test "$pgac_cv_prog_cc_cflags__fexcess_precision_standard" = no; then
539+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
540+
@%:@if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__)
541+
choke me
542+
@%:@endif
543+
])], [],
544+
[AC_MSG_ERROR([Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc.])])
545+
fi
546+
529547
AC_PROG_CPP
530548
AC_SUBST(GCC)
531549

0 commit comments

Comments
 (0)