Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e553997

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 de4fe83 commit e553997

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
@@ -5135,6 +5135,39 @@ fi
51355135
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
51365136
fi
51375137

5138+
# Defend against clang being used on x86-32 without SSE2 enabled. As current
5139+
# versions of clang do not understand -fexcess-precision=standard, the use of
5140+
# x87 floating point operations leads to problems like isinf possibly returning
5141+
# false for a value that is infinite when converted from the 80bit register to
5142+
# the 8byte memory representation.
5143+
#
5144+
# Only perform the test if the compiler doesn't understand
5145+
# -fexcess-precision=standard, that way a potentially fixed compiler will work
5146+
# automatically.
5147+
if test "$pgac_cv_prog_cc_cflags__fexcess_precision_standard" = no; then
5148+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5149+
/* end confdefs.h. */
5150+
5151+
int
5152+
main ()
5153+
{
5154+
5155+
#if defined(__clang__) && defined(__i386__) && !defined(__SSE2_MATH__)
5156+
choke me
5157+
#endif
5158+
5159+
;
5160+
return 0;
5161+
}
5162+
_ACEOF
5163+
if ac_fn_c_try_compile "$LINENO"; then :
5164+
5165+
else
5166+
as_fn_error $? "Compiling PostgreSQL with clang, on 32bit x86, requires SSE2 support. Use -msse2 or use gcc." "$LINENO" 5
5167+
fi
5168+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5169+
fi
5170+
51385171
ac_ext=c
51395172
ac_cpp='$CPP $CPPFLAGS'
51405173
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
@@ -542,6 +542,24 @@ choke me
542542
@%:@endif])], [], [AC_MSG_ERROR([do not put -ffast-math in CFLAGS])])
543543
fi
544544

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

0 commit comments

Comments
 (0)