diff -r e48ec5f5b82b Include/pyport.h --- a/Include/pyport.h Mon Sep 28 15:04:11 2015 +0200 +++ b/Include/pyport.h Fri Oct 09 15:36:59 2015 +0300 @@ -897,4 +897,16 @@ #endif /* _MSC_VER >= 1900 */ #endif /* Py_BUILD_CORE */ +/* + * 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 e48ec5f5b82b Makefile.pre.in --- a/Makefile.pre.in Mon Sep 28 15:04:11 2015 +0200 +++ b/Makefile.pre.in Fri Oct 09 15:36:59 2015 +0300 @@ -80,6 +80,7 @@ # Use it when a compiler flag should _not_ be part of the distutils CFLAGS # once Python is installed (Issue #21121). CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@ +CONFIGURE_LDFLAGS_NODIST=@LDFLAGS_NODIST@ CONFIGURE_CPPFLAGS= @CPPFLAGS@ CONFIGURE_LDFLAGS= @LDFLAGS@ # Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the @@ -91,7 +92,7 @@ # be able to build extension modules using the directories specified in the # environment variables PY_CPPFLAGS= $(BASECPPFLAGS) -I. -IInclude -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS) -PY_LDFLAGS= $(CONFIGURE_LDFLAGS) $(LDFLAGS) +PY_LDFLAGS= $(CONFIGURE_LDFLAGS) $(LDFLAGS) $(CONFIGURE_LDFLAGS_NODIST) NO_AS_NEEDED= @NO_AS_NEEDED@ LDLAST= @LDLAST@ SGI_ABI= @SGI_ABI@ diff -r e48ec5f5b82b Modules/mathmodule.c --- a/Modules/mathmodule.c Mon Sep 28 15:04:11 2015 +0200 +++ b/Modules/mathmodule.c Fri Oct 09 15:36:59 2015 +0300 @@ -863,7 +863,7 @@ OverflowError. */ -static PyObject * +Py_BND_LEGACY static PyObject * math_1(PyObject *arg, double (*func) (double), int can_overflow) { return math_1_to_whatever(arg, func, PyFloat_FromDouble, can_overflow); @@ -875,7 +875,7 @@ return math_1_to_whatever(arg, func, PyLong_FromDouble, can_overflow); } -static PyObject * +Py_BND_LEGACY static PyObject * math_2(PyObject *args, double (*func) (double, double), char *funcname) { PyObject *ox, *oy; diff -r e48ec5f5b82b Objects/obmalloc.c --- a/Objects/obmalloc.c Mon Sep 28 15:04:11 2015 +0200 +++ b/Objects/obmalloc.c Fri Oct 09 15:36:59 2015 +0300 @@ -1208,6 +1208,9 @@ UNLOCK(); if (use_calloc) memset(bp, 0, nbytes); +#ifdef Py_INTEL_MPX + bp = __bnd_set_ptr_bounds(bp, nbytes); +#endif return (void *)bp; } /* @@ -1222,6 +1225,9 @@ UNLOCK(); if (use_calloc) memset(bp, 0, nbytes); +#ifdef Py_INTEL_MPX + bp = __bnd_set_ptr_bounds(bp, nbytes); +#endif return (void *)bp; } /* Pool is full, unlink from used pools. */ @@ -1232,6 +1238,9 @@ UNLOCK(); if (use_calloc) memset(bp, 0, nbytes); +#ifdef Py_INTEL_MPX + bp = __bnd_set_ptr_bounds(bp, nbytes); +#endif return (void *)bp; } @@ -1313,6 +1322,9 @@ UNLOCK(); if (use_calloc) memset(bp, 0, nbytes); +#ifdef Py_INTEL_MPX + bp = __bnd_set_ptr_bounds(bp, nbytes); +#endif return (void *)bp; } /* @@ -1330,6 +1342,9 @@ UNLOCK(); if (use_calloc) memset(bp, 0, nbytes); +#ifdef Py_INTEL_MPX + bp = __bnd_set_ptr_bounds(bp, nbytes); +#endif return (void *)bp; } diff -r e48ec5f5b82b configure --- a/configure Mon Sep 28 15:04:11 2015 +0200 +++ b/configure Fri Oct 09 15:36:59 2015 +0300 @@ -664,6 +664,7 @@ LIBTOOL_CRUFT OTHER_LIBTOOL_OPT UNIVERSAL_ARCH_FLAGS +LDFLAGS_NODIST CFLAGS_NODIST BASECFLAGS OPT @@ -806,6 +807,7 @@ enable_shared enable_profiling with_pydebug +with_mpx with_hash_algorithm with_address_sanitizer with_libs @@ -1485,6 +1487,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-hash-algorithm=[fnv|siphash24] select hash algorithm --with-address-sanitizer @@ -6437,6 +6441,51 @@ 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 "#define Py_INTEL_MPX 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; }; + CFLAGS_NODIST="$CFLAGS_NODIST -fcheck-pointer-bounds -mmpx" + LDFLAGS_NODIST="$LDFLAGS_NODIST -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 + + # Enable PGO flags. # Extract the first word of "llvm-profdata", so it can be a program name with args. set dummy llvm-profdata; ac_word=$2 @@ -6578,6 +6627,7 @@ + # The -arch flags for universal builds on OSX UNIVERSAL_ARCH_FLAGS= diff -r e48ec5f5b82b configure.ac --- a/configure.ac Mon Sep 28 15:04:11 2015 +0200 +++ b/configure.ac Fri Oct 09 15:36:59 2015 +0300 @@ -1218,6 +1218,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_DEFINE(Py_INTEL_MPX, 1, [Define if you want to build an MPX instrumented interpreter.]) + AC_MSG_RESULT(yes); + CFLAGS_NODIST="$CFLAGS_NODIST -fcheck-pointer-bounds -mmpx" + LDFLAGS_NODIST="$LDFLAGS_NODIST -fcheck-pointer-bounds -mmpx" + fi +else AC_MSG_RESULT(no) +fi], +[AC_MSG_RESULT(no)]) + # Enable PGO flags. AC_SUBST(PGO_PROF_GEN_FLAG) AC_SUBST(PGO_PROF_USE_FLAG) @@ -1327,6 +1363,7 @@ AC_SUBST(BASECFLAGS) AC_SUBST(CFLAGS_NODIST) +AC_SUBST(LDFLAGS_NODIST) # The -arch flags for universal builds on OSX UNIVERSAL_ARCH_FLAGS= diff -r e48ec5f5b82b pyconfig.h.in --- a/pyconfig.h.in Mon Sep 28 15:04:11 2015 +0200 +++ b/pyconfig.h.in Fri Oct 09 15:36:59 2015 +0300 @@ -1239,6 +1239,9 @@ externally defined: 0 */ #undef Py_HASH_ALGORITHM +/* Define if you want to build an MPX instrumented interpreter. */ +#undef Py_INTEL_MPX + /* assume C89 semantics that RETSIGTYPE is always void */ #undef RETSIGTYPE