diff -r ea91991c7db5 Include/pyport.h --- a/Include/pyport.h Mon Sep 28 15:37:57 2015 +0300 +++ b/Include/pyport.h Mon Oct 05 11:38:16 2015 +0300 @@ -938,4 +938,16 @@ #define Py_ULL(x) Py_LL(x##U) #endif +/* + * Check for MPX support. GCC 5.1 or higher is needed for the MPX bnd_legacy + * attribute to be supported. + */ + +#if defined(__GNUC__) && ((__GNUC__ >= 6) || \ + (__GNUC__ == 5) && (__GNUC_MINOR__ >= 1)) +#define Py_BND_LEGACY __attribute__((bnd_legacy)) +#else +#define Py_BND_LEGACY +#endif + #endif /* Py_PYPORT_H */ diff -r ea91991c7db5 Modules/mathmodule.c --- a/Modules/mathmodule.c Mon Sep 28 15:37:57 2015 +0300 +++ b/Modules/mathmodule.c Mon Oct 05 11:38:16 2015 +0300 @@ -679,7 +679,7 @@ care about right now. */ -static PyObject * +Py_BND_LEGACY static PyObject * math_1(PyObject *arg, double (*func) (double), int can_overflow) { double x, r; @@ -755,7 +755,7 @@ OverflowError. */ -static PyObject * +Py_BND_LEGACY static PyObject * math_2(PyObject *args, double (*func) (double, double), char *funcname) { PyObject *ox, *oy; @@ -1272,7 +1272,7 @@ However, intermediate overflow is possible for a long if the number of bits in that long is larger than PY_SSIZE_T_MAX. */ -static PyObject* +Py_BND_LEGACY static PyObject* loghelper(PyObject* arg, double (*func)(double), char *funcname) { /* If it is long, do it ourselves. */ @@ -1310,7 +1310,7 @@ return math_1(arg, func, 0); } -static PyObject * +Py_BND_LEGACY static PyObject * math_log(PyObject *self, PyObject *args) { PyObject *arg; @@ -1342,7 +1342,7 @@ Return the logarithm of x to the given base.\n\ If the base not specified, returns the natural logarithm (base e) of x."); -static PyObject * +Py_BND_LEGACY static PyObject * math_log10(PyObject *self, PyObject *arg) { return loghelper(arg, m_log10, "log10"); diff -r ea91991c7db5 configure --- a/configure Mon Sep 28 15:37:57 2015 +0300 +++ b/configure Mon Oct 05 11:38:16 2015 +0300 @@ -794,6 +794,7 @@ enable_shared enable_profiling with_pydebug +with_mpx enable_toolbox_glue with_libs with_system_expat @@ -1474,6 +1475,8 @@ compiler --with-suffix=.exe set executable suffix --with-pydebug build with Py_DEBUG defined + --with-mpx Enable Intel MPX (Memory Protection Extensions) + feature. Disabled by default. --with-libs='lib1 ...' link against additional libs --with-system-expat build pyexpat module using an installed expat library @@ -5935,6 +5938,48 @@ fi +# Check for --with-mpx +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-mpx" >&5 +$as_echo_n "checking for --with-mpx... " >&6; } + +# Check whether --with-mpx was given. +if test "${with_mpx+set}" = set; then : + withval=$with_mpx; +if test "$withval" != no +then + mpx_compatible=false + if [ "$CC" = "gcc" ] + then + CC_MAJOR_VERSION=$(gcc -dumpversion | cut -f1 -d.) + CC_MINOR_VERSION=$(gcc -dumpversion | cut -f2 -d.) + if [ "$CC_MAJOR_VERSION" -ge "5" ] + then + mpx_compatible=true + if [ "$CC_MAJOR_VERSION" -eq "5" ] && [ "$CC_MINOR_VERSION" -lt "1" ] + then + mpx_compatible=false + fi + fi + fi + + if [ "$mpx_compatible" = "false" ] + then + as_fn_error $? "MPX feature can only be used with gcc 5.1 and higher" "$LINENO" 5 + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; }; + CFLAGS="$CFLAGS -fcheck-pointer-bounds -mmpx" + LDFLAGS="$LDFLAGS -fcheck-pointer-bounds -mmpx" + fi +else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be # merged with this chunk of code? diff -r ea91991c7db5 configure.ac --- a/configure.ac Mon Sep 28 15:37:57 2015 +0300 +++ b/configure.ac Mon Oct 05 11:38:16 2015 +0300 @@ -1034,6 +1034,42 @@ fi], [AC_MSG_RESULT(no)]) +# Check for --with-mpx +AC_MSG_CHECKING(for --with-mpx) +AC_ARG_WITH(mpx, + AS_HELP_STRING([--with-mpx], [Enable Intel MPX (Memory Protection + Extensions) feature. Disabled by + default.]), +[ +if test "$withval" != no +then + mpx_compatible=false + if [[ "$CC" = "gcc" ]] + then + CC_MAJOR_VERSION=$(gcc -dumpversion | cut -f1 -d.) + CC_MINOR_VERSION=$(gcc -dumpversion | cut -f2 -d.) + if [[ "$CC_MAJOR_VERSION" -ge "5" ]] + then + mpx_compatible=true + if [[ "$CC_MAJOR_VERSION" -eq "5" ]] && [[ "$CC_MINOR_VERSION" -lt "1" ]] + then + mpx_compatible=false + fi + fi + fi + + if [[ "$mpx_compatible" = "false" ]] + then + AC_MSG_ERROR([MPX feature can only be used with gcc 5.1 and higher]) + else + AC_MSG_RESULT(yes); + CFLAGS="$CFLAGS -fcheck-pointer-bounds -mmpx" + LDFLAGS="$LDFLAGS -fcheck-pointer-bounds -mmpx" + fi +else AC_MSG_RESULT(no) +fi], +[AC_MSG_RESULT(no)]) + # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be # merged with this chunk of code?