Skip to content

Commit 1b8f09d

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 ba20d39 commit 1b8f09d

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
@@ -5224,6 +5224,39 @@ fi
52245224
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
52255225
fi
52265226

5227+
# Defend against clang being used on x86-32 without SSE2 enabled. As current
5228+
# versions of clang do not understand -fexcess-precision=standard, the use of
5229+
# x87 floating point operations leads to problems like isinf possibly returning
5230+
# false for a value that is infinite when converted from the 80bit register to
5231+
# the 8byte memory representation.
5232+
#
5233+
# Only perform the test if the compiler doesn't understand
5234+
# -fexcess-precision=standard, that way a potentially fixed compiler will work
5235+
# automatically.
5236+
if test "$pgac_cv_prog_cc_cflags__fexcess_precision_standard" = no; then
5237+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5238+
/* end confdefs.h. */
5239+
5240+
int
5241+
main ()
5242+
{
5243+
5244+
#if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__)
5245+
choke me
5246+
#endif
5247+
5248+
;
5249+
return 0;
5250+
}
5251+
_ACEOF
5252+
if ac_fn_c_try_compile "$LINENO"; then :
5253+
5254+
else
5255+
as_fn_error $? "Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc." "$LINENO" 5
5256+
fi
5257+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5258+
fi
5259+
52275260
ac_ext=c
52285261
ac_cpp='$CPP $CPPFLAGS'
52295262
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
@@ -551,6 +551,24 @@ choke me
551551
@%:@endif])], [], [AC_MSG_ERROR([do not put -ffast-math in CFLAGS])])
552552
fi
553553

554+
# Defend against clang being used on x86-32 without SSE2 enabled. As current
555+
# versions of clang do not understand -fexcess-precision=standard, the use of
556+
# x87 floating point operations leads to problems like isinf possibly returning
557+
# false for a value that is infinite when converted from the 80bit register to
558+
# the 8byte memory representation.
559+
#
560+
# Only perform the test if the compiler doesn't understand
561+
# -fexcess-precision=standard, that way a potentially fixed compiler will work
562+
# automatically.
563+
if test "$pgac_cv_prog_cc_cflags__fexcess_precision_standard" = no; then
564+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
565+
@%:@if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__)
566+
choke me
567+
@%:@endif
568+
])], [],
569+
[AC_MSG_ERROR([Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc.])])
570+
fi
571+
554572
AC_PROG_CPP
555573
AC_SUBST(GCC)
556574

0 commit comments

Comments
 (0)