diff -r ea91991c7db5 Include/pyport.h --- a/Include/pyport.h Mon Sep 28 15:37:57 2015 +0300 +++ b/Include/pyport.h Tue Oct 06 15:21:53 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 Makefile.pre.in --- a/Makefile.pre.in Mon Sep 28 15:37:57 2015 +0300 +++ b/Makefile.pre.in Tue Oct 06 15:21:53 2015 +0300 @@ -84,10 +84,14 @@ CCSHARED= @CCSHARED@ LINKFORSHARED= @LINKFORSHARED@ ARFLAGS= @ARFLAGS@ +# Use it when a compiler flag should _not_ be part of the distutils CFLAGS +# once Python is installed +CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@ +CONFIGURE_LDFLAGS_NODIST=@LDFLAGS_NODIST@ # Extra C flags added for building the interpreter object files. CFLAGSFORSHARED=@CFLAGSFORSHARED@ # C flags used for building the interpreter object files -PY_CFLAGS= $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE +PY_CFLAGS= $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) $(CONFIGURE_CFLAGS_NODIST) -DPy_BUILD_CORE # Machine-dependent subdirectories @@ -122,8 +126,8 @@ # Symbols used for using shared libraries SO= @SO@ -LDSHARED= @LDSHARED@ $(LDFLAGS) -BLDSHARED= @BLDSHARED@ $(LDFLAGS) +LDSHARED= @LDSHARED@ $(LDFLAGS) $(CONFIGURE_LDFLAGS_NODIST) +BLDSHARED= @BLDSHARED@ $(LDFLAGS) $(CONFIGURE_LDFLAGS_NODIST) LDCXXSHARED= @LDCXXSHARED@ DESTSHARED= $(BINLIBDEST)/lib-dynload @@ -445,7 +449,7 @@ $(MAKE) profile-removal build_all_generate_profile: - $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)" + $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(CONFIGURE_LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)" run_profile_task: : # FIXME: can't run for a cross build @@ -465,7 +469,7 @@ # Build the interpreter $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) - $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \ + $(LINKCC) $(LDFLAGS) $(CONFIGURE_LDFLAGS_NODIST) $(LINKFORSHARED) -o $@ \ Modules/python.o \ $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) @@ -522,7 +526,7 @@ fi libpython$(VERSION).dylib: $(LIBRARY_OBJS) - $(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ + $(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) $(CONFIGURE_LDFLAGS_NODIST) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ libpython$(VERSION).sl: $(LIBRARY_OBJS) @@ -547,7 +551,7 @@ $(LIBRARY) \ $(RESSRCDIR)/Info.plist $(INSTALL) -d -m $(DIRMODE) $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION) - $(CC) -o $(LDLIBRARY) $(LDFLAGS) -dynamiclib \ + $(CC) -o $(LDLIBRARY) $(LDFLAGS) $(CONFIGURE_LDFLAGS_NODIST) -dynamiclib \ -all_load $(LIBRARY) -Wl,-single_module \ -install_name $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK) \ -compatibility_version $(VERSION) \ @@ -642,7 +646,7 @@ touch $(GRAMMAR_C) $(PGEN): $(PGENOBJS) - $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN) + $(CC) $(OPT) $(LDFLAGS) $(CONFIGURE_LDFLAGS_NODIST) $(PGENOBJS) $(LIBS) -o $(PGEN) Parser/grammar.o: $(srcdir)/Parser/grammar.c \ $(srcdir)/Include/token.h \ diff -r ea91991c7db5 Modules/mathmodule.c --- a/Modules/mathmodule.c Mon Sep 28 15:37:57 2015 +0300 +++ b/Modules/mathmodule.c Tue Oct 06 15:21:53 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 Tue Oct 06 15:21:53 2015 +0300 @@ -670,6 +670,8 @@ UNIVERSAL_ARCH_FLAGS BASECFLAGS OPT +LDFLAGS_NODIST +CFLAGS_NODIST LN MKDIR_P INSTALL_DATA @@ -794,6 +796,7 @@ enable_shared enable_profiling with_pydebug +with_mpx enable_toolbox_glue with_libs with_system_expat @@ -1474,6 +1477,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 +5940,50 @@ 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_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 + + # 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 Tue Oct 06 15:21:53 2015 +0300 @@ -1034,6 +1034,44 @@ fi], [AC_MSG_RESULT(no)]) +# Check for --with-mpx +AC_SUBST(CFLAGS_NODIST) +AC_SUBST(LDFLAGS_NODIST) +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_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)]) + # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be # merged with this chunk of code?