2020-01-25 14:57:28

by Sam Lunt

[permalink] [raw]
Subject: [PATCH] perf: Support Python 3.8+ in Makefile

Python 3.8 changed the output of 'python-config --ldflags' to no longer
include the '-lpythonX.Y' flag (this apparently fixed an issue loading
modules with a statically linked Python executable). The libpython
feature check in linux/build/feature fails if the Python library is not
included in FEATURE_CHECK_LDFLAGS-libpython variable.

This adds a check in the Makefile to determine if PYTHON_CONFIG accepts
the '--embed' flag and passes that flag alongside '--ldflags' if so.

tools/perf is the only place the libpython feature check is used.

Signed-off-by: Sam Lunt <[email protected]>
---
tools/perf/Makefile.config | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index c90f4146e5a2..ccf99351f058 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -228,8 +228,17 @@ strip-libs = $(filter-out -l%,$(1))

PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))

+# Python 3.8 changed the output of `python-config --ldflags` to not include the
+# '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for
+# libpython fails if that flag is not included in LDFLAGS
+ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null;
echo $$?), 0)
+ PYTHON_CONFIG_LDFLAGS := --ldflags --embed
+else
+ PYTHON_CONFIG_LDFLAGS := --ldflags
+endif
+
ifdef PYTHON_CONFIG
- PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
+ PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ)
$(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)

base-commit: d5d359b0ac3ffc319ca93c46a4cfd87093759ad6
--
2.25.0


2020-01-29 07:56:17

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH] perf: Support Python 3.8+ in Makefile

On Sat, Jan 25, 2020 at 08:56:12AM -0600, Sam Lunt wrote:
> Python 3.8 changed the output of 'python-config --ldflags' to no longer
> include the '-lpythonX.Y' flag (this apparently fixed an issue loading
> modules with a statically linked Python executable). The libpython
> feature check in linux/build/feature fails if the Python library is not
> included in FEATURE_CHECK_LDFLAGS-libpython variable.
>
> This adds a check in the Makefile to determine if PYTHON_CONFIG accepts
> the '--embed' flag and passes that flag alongside '--ldflags' if so.
>
> tools/perf is the only place the libpython feature check is used.

seems ok to me, but your patch came malformed, check below

jirka


>
> Signed-off-by: Sam Lunt <[email protected]>
> ---
> tools/perf/Makefile.config | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index c90f4146e5a2..ccf99351f058 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -228,8 +228,17 @@ strip-libs = $(filter-out -l%,$(1))
>
> PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
>
> +# Python 3.8 changed the output of `python-config --ldflags` to not include the
> +# '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for
> +# libpython fails if that flag is not included in LDFLAGS
> +ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null;
> echo $$?), 0)

patching file tools/perf/Makefile.config
patch: **** malformed patch at line 108: echo $$?), 0)


> + PYTHON_CONFIG_LDFLAGS := --ldflags --embed
> +else
> + PYTHON_CONFIG_LDFLAGS := --ldflags
> +endif
> +
> ifdef PYTHON_CONFIG
> - PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
> + PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ)
> $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)

patching file tools/perf/Makefile.config
patch: **** malformed patch at line 116: $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)

> PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
> PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
> PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
>
> base-commit: d5d359b0ac3ffc319ca93c46a4cfd87093759ad6
> --
> 2.25.0
>

2020-01-31 18:07:43

by Sam Lunt

[permalink] [raw]
Subject: Re: [PATCH] perf: Support Python 3.8+ in Makefile

Sorry about that, Gmail's web client reflowed the text of the patch.
I'll try again with mutt.

On Wed, Jan 29, 2020 at 1:55 AM Jiri Olsa <[email protected]> wrote:
>
> On Sat, Jan 25, 2020 at 08:56:12AM -0600, Sam Lunt wrote:
> > Python 3.8 changed the output of 'python-config --ldflags' to no longer
> > include the '-lpythonX.Y' flag (this apparently fixed an issue loading
> > modules with a statically linked Python executable). The libpython
> > feature check in linux/build/feature fails if the Python library is not
> > included in FEATURE_CHECK_LDFLAGS-libpython variable.
> >
> > This adds a check in the Makefile to determine if PYTHON_CONFIG accepts
> > the '--embed' flag and passes that flag alongside '--ldflags' if so.
> >
> > tools/perf is the only place the libpython feature check is used.
>
> seems ok to me, but your patch came malformed, check below
>
> jirka
>
>
> >
> > Signed-off-by: Sam Lunt <[email protected]>
> > ---
> > tools/perf/Makefile.config | 11 ++++++++++-
> > 1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> > index c90f4146e5a2..ccf99351f058 100644
> > --- a/tools/perf/Makefile.config
> > +++ b/tools/perf/Makefile.config
> > @@ -228,8 +228,17 @@ strip-libs = $(filter-out -l%,$(1))
> >
> > PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
> >
> > +# Python 3.8 changed the output of `python-config --ldflags` to not include the
> > +# '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for
> > +# libpython fails if that flag is not included in LDFLAGS
> > +ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null;
> > echo $$?), 0)
>
> patching file tools/perf/Makefile.config
> patch: **** malformed patch at line 108: echo $$?), 0)
>
>
> > + PYTHON_CONFIG_LDFLAGS := --ldflags --embed
> > +else
> > + PYTHON_CONFIG_LDFLAGS := --ldflags
> > +endif
> > +
> > ifdef PYTHON_CONFIG
> > - PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
> > + PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ)
> > $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
>
> patching file tools/perf/Makefile.config
> patch: **** malformed patch at line 116: $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
>
> > PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
> > PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
> > PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
> >
> > base-commit: d5d359b0ac3ffc319ca93c46a4cfd87093759ad6
> > --
> > 2.25.0
> >
>