From: "Jan Beulich" Subject: Re: [PATCH] tools: work around collision of -O0 and -D_FORTIFY_SOURCE Date: Fri, 06 Feb 2015 08:22:52 +0000 Message-ID: <54D487EC020000780005D98A@mail.emea.novell.com> References: <20150205154753.GF3823@citrix.com> <1423154167-22453-1-git-send-email-ian.jackson@eu.citrix.com> <54D3ADDF020000780005D7A1@mail.emea.novell.com> <21715.41154.597589.665860@mariner.uk.xensource.com> <54D4870F020000780005D97D@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part5D68D0CC.2__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YJeBh-0004GD-LV for xen-devel@lists.xenproject.org; Fri, 06 Feb 2015 08:22:53 +0000 In-Reply-To: <54D4870F020000780005D97D@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: Wei Liu , Ian Campbell , Stefano Stabellini , Don Slutz , Euan Harris , xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part5D68D0CC.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> On 06.02.15 at 09:19, wrote: > Attached the patch I used for testing. This time for real. Jan --=__Part5D68D0CC.2__= Content-Type: text/plain; name="tools-Python-fortify.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="tools-Python-fortify.patch" tools: work around collision of -O0 and -D_FORTIFY_SOURCE=0A=0ASome = systems have python-config include -D_FORTIFY_SOURCE in the=0ACFLAGS. But = -D_FORTIFY_SOURCE does not (currently) work with -O0, and=0A-O0 is enabled = in debug builds (since 1166ecf781). As a result, on=0Athose systems, = debug builds fail.=0A=0AWork around this problem as follows:=0A * In = configure, detect -D_FORTIFY_SOURCE in $(python-config --cflags)=0A * If = detected, set the new autoconf substitution and make variable=0A = PY_NOOPT_CFLAGS to -O1.=0A * In tools/Rules.mk, where we add -O0, also add = PY_NOOPT_CFLAGS=0A (which will override the -O0 with -O1 if required).=0A= =0AOverriding the -O0 is better than disabling Fortify because the=0Alatter= might have an adverse security impact. A user who wants to=0Adisable = optimisation completely even for Python and also disable=0AFortify can set = the environment variable=0A EXTRA_CFLAGS_XEN_TOOLS=3D'-U_FORTIFY_SOURCE = -O0'=0A=0ASigned-off-by: Ian Jackson =0AReported= -by: Jan Beulich =0A=0ALimit no-optimization override = to Python interface code.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/config/Tools.mk.in=0A+++ b/config/Tools.mk.in=0A@@ -13,6 = +13,7 @@ BISON :=3D @BISON@=0A FLEX :=3D = @FLEX@=0A PYTHON :=3D @PYTHON@=0A PYTHON_PATH :=3D = @PYTHONPATH@=0A+PY_NOOPT_CFLAGS :=3D @PY_NOOPT_CFLAGS@=0A PERL = :=3D @PERL@=0A CURL_CONFIG :=3D @CURL@=0A XML2_CONFIG = :=3D @XML@=0A--- /dev/null=0A+++ b/m4/python_fortify_noopt.m4=0A@@ -0,0 = +1,29 @@=0A+dnl Defines PY_NOOPT_CFLAGS to either '' or -O1=0A+dnl=0A+=0A+d= nl This is necessary because on some systems setup.py includes=0A+dnl = -D_FORTIFY_SOURCE but have a -D_FORTIFY_SOURCE which breaks=0A+dnl with = -O0. On those systems we arrange to use -O1 for debug=0A+dnl builds = instead.=0A+=0A+AC_DEFUN([AX_CHECK_PYTHON_FORTIFY_NOOPT], [=0A+ = AC_CACHE_CHECK([whether Python setup.py brokenly enables -D_FORTIFY_SOURCE]= ,=0A+ [ax_cv_python_fortify],[=0A+ ax_cv_python_fo= rtify=3Dno=0A+ for arg in $($PYTHON-config --cflags); do=0A+ = case "$arg" in=0A+ -D_FORTIFY_SOURCE=3D0) ax_cv_python_forti= fy=3Dno ;;=0A+ -D_FORTIFY_SOURCE=3D*) ax_cv_python_fortify=3Dyes= ;;=0A+ *) ;;=0A+ esac=0A+ done=0A+ = ])=0A+=0A+ AS_IF([test x$ax_cv_python_fortify =3D xyes],[=0A+ = PY_NOOPT_CFLAGS=3D-O1=0A+ ], [=0A+ PY_NOOPT_CFLAGS=3D''=0A+ = ])=0A+=0A+ AC_SUBST(PY_NOOPT_CFLAGS)=0A+])=0A--- a/tools/Rules.mk=0A+++ = b/tools/Rules.mk=0A@@ -57,6 +57,8 @@ SHLIB_libxenvchan =3D -Wl,-rpath-link= =3D$(X=0A ifeq ($(debug),y)=0A # Disable optimizations and enable = debugging information for macros=0A CFLAGS +=3D -O0 -g3=0A+# But allow an = override to -O0 in case Python enforces -D_FORTIFY_SOURCE=3D.=0A+PY_CFLA= GS +=3D $(PY_NOOPT_CFLAGS)=0A endif=0A =0A LIBXL_BLKTAP ?=3D $(CONFIG_BLKTA= P2)=0A--- a/tools/configure=0A+++ b/tools/configure=0A@@ -652,6 +652,7 @@ = PKG_CONFIG_LIBDIR=0A PKG_CONFIG_PATH=0A PKG_CONFIG=0A CURSES_LIBS=0A+PY_NOO= PT_CFLAGS=0A EGREP=0A GREP=0A CPP=0A@@ -7043,6 +7044,38 @@ CPPFLAGS=3D$ac_p= revious_cppflags=0A LDLFAGS=3D$ac_previous_ldflags=0A =0A =0A+ { = $as_echo "$as_me:${as_lineno-$LINENO}: checking whether Python setup.py = brokenly enables -D_FORTIFY_SOURCE" >&5=0A+$as_echo_n "checking whether = Python setup.py brokenly enables -D_FORTIFY_SOURCE... " >&6; }=0A+if = ${ax_cv_python_fortify+:} false; then :=0A+ $as_echo_n "(cached) " = >&6=0A+else=0A+=0A+ ax_cv_python_fortify=3Dno=0A+ for arg in = $($PYTHON-config --cflags); do=0A+ case "$arg" in=0A+ = -D_FORTIFY_SOURCE=3D0) ax_cv_python_fortify=3Dno ;;=0A+ = -D_FORTIFY_SOURCE=3D*) ax_cv_python_fortify=3Dyes ;;=0A+ *) = ;;=0A+ esac=0A+ done=0A+=0A+fi=0A+{ $as_echo "$as_me:${as= _lineno-$LINENO}: result: $ax_cv_python_fortify" >&5=0A+$as_echo "$ax_cv_py= thon_fortify" >&6; }=0A+=0A+ if test x$ax_cv_python_fortify =3D xyes; = then :=0A+=0A+ PY_NOOPT_CFLAGS=3D-O1=0A+=0A+else=0A+=0A+ = PY_NOOPT_CFLAGS=3D''=0A+=0A+fi=0A+=0A+=0A+=0A+=0A fi=0A =0A if ! $rump; = then=0A--- a/tools/configure.ac=0A+++ b/tools/configure.ac=0A@@ -58,6 = +58,7 @@ m4_include([../m4/checkpolicy.m4])=0A m4_include([../m4/set_cflags= _ldflags.m4])=0A m4_include([../m4/python_version.m4])=0A m4_include([../m4= /python_devel.m4])=0A+m4_include([../m4/python_fortify_noopt.m4])=0A = m4_include([../m4/ocaml.m4])=0A m4_include([../m4/uuid.m4])=0A m4_include([= ../m4/pkg.m4])=0A@@ -295,6 +296,7 @@ AX_CHECK_PYTHON_VERSION([2], [3])=0A = =0A AS_IF([test "$cross_compiling" !=3D yes], [=0A AX_CHECK_PYTHON_DEVE= L()=0A+ AX_CHECK_PYTHON_FORTIFY_NOOPT()=0A ])=0A =0A if ! $rump; = then=0A--- a/tools/pygrub/Makefile=0A+++ b/tools/pygrub/Makefile=0A@@ = -2,15 +2,17 @@=0A XEN_ROOT =3D $(CURDIR)/../..=0A include $(XEN_ROOT)/tools= /Rules.mk=0A =0A+PY_CFLAGS =3D $(CFLAGS) $(PY_NOOPT_CFLAGS) $(APPEND_LDFLAG= S)=0A+=0A .PHONY: all=0A all: build=0A .PHONY: build=0A build:=0A- = CC=3D"$(CC)" CFLAGS=3D"$(CFLAGS) $(APPEND_LDFLAGS)" $(PYTHON) setup.py = build=0A+ CC=3D"$(CC)" CFLAGS=3D"$(PY_CFLAGS)" $(PYTHON) setup.py = build=0A =0A .PHONY: install=0A install: all=0A- CC=3D"$(CC)" = CFLAGS=3D"$(CFLAGS) $(APPEND_LDFLAGS)" $(PYTHON) setup.py install \=0A+ = CC=3D"$(CC)" CFLAGS=3D"$(PY_CFLAGS)" $(PYTHON) setup.py install \=0A = $(PYTHON_PREFIX_ARG) --root=3D"$(DESTDIR)" \=0A --install-s= cripts=3D$(LIBEXEC_BIN) --force=0A set -e; if [ $(BINDIR) !=3D = $(LIBEXEC_BIN) -a \=0A--- a/tools/python/Makefile=0A+++ b/tools/python/Make= file=0A@@ -4,6 +4,8 @@ include $(XEN_ROOT)/tools/Rules.mk=0A .PHONY: = all=0A all: build=0A =0A+PY_CFLAGS =3D $(CFLAGS) $(PY_NOOPT_CFLAGS) = $(LDFLAGS) $(APPEND_LDFLAGS)=0A+=0A .PHONY: build=0A build: genwrap.py = $(XEN_ROOT)/tools/libxl/libxl_types.idl \=0A $(XEN_ROOT)/tools/l= ibxl/idl.py=0A@@ -11,11 +13,11 @@ build: genwrap.py $(XEN_ROOT)/tools/libx= =0A $(XEN_ROOT)/tools/libxl/libxl_types.idl \=0A = xen/lowlevel/xl/_pyxl_types.h \=0A xen/lowlevel/xl/_pyxl_types= .c=0A- CC=3D"$(CC)" CFLAGS=3D"$(CFLAGS) $(LDFLAGS) $(APPEND_LDFLAGS)" = $(PYTHON) setup.py build=0A+ CC=3D"$(CC)" CFLAGS=3D"$(PY_CFLAGS)" = $(PYTHON) setup.py build=0A =0A .PHONY: install=0A install:=0A- CC=3D"$(CC)= " CFLAGS=3D"$(CFLAGS) $(LDFLAGS) $(APPEND_LDFLAGS)" $(PYTHON) setup.py = install \=0A+ CC=3D"$(CC)" CFLAGS=3D"$(PY_CFLAGS)" $(PYTHON) setup.py = install \=0A $(PYTHON_PREFIX_ARG) --root=3D"$(DESTDIR)" = --force=0A =0A .PHONY: test=0A --=__Part5D68D0CC.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part5D68D0CC.2__=--