Skip to contentSkip to conversation

perf: Be compatible with all python versions when fetching ldflags

PATCH Applied [email protected] 5 participants 13 messages Feb 13, 2020 – Apr 4, 2020 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 perf: Be compatible with all python versions when fetching ldflags

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to python-config (GH-13500)"), --embed option must be passed to "python3-config --ldflags --embed" or "python3-config --libs --embed" to get "-lpython3.8".

To make it compatible with all Python versons, according to the suggestion in the commit log, we try with --embed first and then witout it if fails.

---
 tools/perf/Makefile.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.config +1 -1
index 80e55e7..b2eabcf 100644
@@ -229,7 +229,7 @@ strip-libs  = $(filter-out -l%,$(1))
 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
 
 ifdef PYTHON_CONFIG
-  PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
+  PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>/dev/null || $(PYTHON_CONFIG_SQ) --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)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 perf: Normalize gcc parameter when generating arch errno table

From: He Zhe <[email protected]>

The $(CC) passed to arch_errno_names.sh may include a series of parameters along with gcc itself. To avoid overwriting the following parameters of arch_errno_names.sh and break the build like below, we just pick up the first word of the $(CC).

find: unknown predicate `-m64/arch'
x86_64-wrs-linux-gcc: warning: '-x c' after last input file has no effect
x86_64-wrs-linux-gcc: error: unrecognized command line option '-m64/include/uapi/asm-generic/errno.h'
x86_64-wrs-linux-gcc: fatal error: no input files

---
 tools/perf/Makefile.perf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
index 3eda9d4..7114c11 100644
@@ -573,7 +573,7 @@ arch_errno_hdr_dir := $(srctree)/tools
 arch_errno_tbl := $(srctree)/tools/perf/trace/beauty/arch_errno_names.sh
 
 $(arch_errno_name_array): $(arch_errno_tbl)
-	$(Q)$(SHELL) '$(arch_errno_tbl)' $(CC) $(arch_errno_hdr_dir) > $@
+	$(Q)$(SHELL) '$(arch_errno_tbl)' $(firstword $(CC)) $(arch_errno_hdr_dir) > $@
 
 sync_file_range_arrays := $(beauty_outdir)/sync_file_range_arrays.c
 sync_file_range_tbls := $(srctree)/tools/perf/trace/beauty/sync_file_range.sh
Signature · 1 line
2.7.4
author
#2 lore raw

Re: [PATCH 2/2] perf: Normalize gcc parameter when generating arch errno table

Can this be considered for the moment?

Thanks,
Zhe

Quoted 30 lines · On 2/14/20 2:21 AM, [email protected] wrote:

From: He Zhe <[email protected]>

The $(CC) passed to arch_errno_names.sh may include a series of parameters along with gcc itself. To avoid overwriting the following parameters of arch_errno_names.sh and break the build like below, we just pick up the first word of the $(CC).

find: unknown predicate `-m64/arch'
x86_64-wrs-linux-gcc: warning: '-x c' after last input file has no effect
x86_64-wrs-linux-gcc: error: unrecognized command line option '-m64/include/uapi/asm-generic/errno.h'
x86_64-wrs-linux-gcc: fatal error: no input files

---
 tools/perf/Makefile.perf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
index 3eda9d4..7114c11 100644
@@ -573,7 +573,7 @@ arch_errno_hdr_dir := $(srctree)/tools
 arch_errno_tbl := $(srctree)/tools/perf/trace/beauty/arch_errno_names.sh
 
 $(arch_errno_name_array): $(arch_errno_tbl)
-	$(Q)$(SHELL) '$(arch_errno_tbl)' $(CC) $(arch_errno_hdr_dir) > $@
+	$(Q)$(SHELL) '$(arch_errno_tbl)' $(firstword $(CC)) $(arch_errno_hdr_dir) > $@
 
 sync_file_range_arrays := $(beauty_outdir)/sync_file_range_arrays.c
 sync_file_range_tbls := $(srctree)/tools/perf/trace/beauty/sync_file_range.sh
merge bot Applied
#3 lore raw

[tip: perf/urgent] perf: Normalize gcc parameter when generating arch errno table

In reply to [email protected]
The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     e4ffd066ff440a57097e9140fa9e16ceef905de8
Gitweb:        https://git.kernel.org/tip/e4ffd066ff440a57097e9140fa9e16ceef905de8
Author:        He Zhe <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 02:21:06 +08:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Thu, 26 Mar 2020 11:04:01 -03:00

perf: Normalize gcc parameter when generating arch errno table

The $(CC) passed to arch_errno_names.sh may include a series of parameters along with gcc itself. To avoid overwriting the following parameters of arch_errno_names.sh and break the build like below, we just pick up the first word of the $(CC).

find: unknown predicate `-m64/arch'
x86_64-wrs-linux-gcc: warning: '-x c' after last input file has no effect
x86_64-wrs-linux-gcc: error: unrecognized command line option '-m64/include/uapi/asm-generic/errno.h'
x86_64-wrs-linux-gcc: fatal error: no input files

---
 tools/perf/Makefile.perf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
index a02aca9..d15a311 100644
@@ -574,7 +574,7 @@ arch_errno_hdr_dir := $(srctree)/tools
 arch_errno_tbl := $(srctree)/tools/perf/trace/beauty/arch_errno_names.sh
 
 $(arch_errno_name_array): $(arch_errno_tbl)
-	$(Q)$(SHELL) '$(arch_errno_tbl)' $(CC) $(arch_errno_hdr_dir) > $@
+	$(Q)$(SHELL) '$(arch_errno_tbl)' $(firstword $(CC)) $(arch_errno_hdr_dir) > $@
 
 sync_file_range_arrays := $(beauty_outdir)/sync_file_range_arrays.c
 sync_file_range_tbls := $(srctree)/tools/perf/trace/beauty/sync_file_range.sh
#4 lore raw
In reply to [email protected]
Quoted 4 lines · On Fri, Feb 14, 2020 at 02:21:05AM +0800, [email protected] wrote:

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to python-config (GH-13500)"),

we got similar change recently.. might have not been picked up yet

https://lore.kernel.org/lkml/[email protected]/

jirka

Quoted 27 lines

--embed option must be passed to "python3-config --ldflags --embed" or "python3-config --libs --embed" to get "-lpython3.8".

To make it compatible with all Python versons, according to the suggestion in the commit log, we try with --embed first and then witout it if fails.

---
 tools/perf/Makefile.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.config +1 -1
index 80e55e7..b2eabcf 100644
@@ -229,7 +229,7 @@ strip-libs  = $(filter-out -l%,$(1))
 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
 
 ifdef PYTHON_CONFIG
-  PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
+  PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>/dev/null || $(PYTHON_CONFIG_SQ) --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)
Signature · 1 line
2.7.4
author
#5 lore raw
Quoted 8 lines · Jiri Olsa
Quoted 4 lines · On Fri, Feb 14, 2020 at 02:21:05AM +0800, [email protected] wrote:

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to python-config (GH-13500)"),

we got similar change recently.. might have not been picked up yet

https://lore.kernel.org/lkml/[email protected]/

Thanks for pointing out.

Zhe

Quoted 30 lines

jirka

Quoted 27 lines

--embed option must be passed to "python3-config --ldflags --embed" or "python3-config --libs --embed" to get "-lpython3.8".

To make it compatible with all Python versons, according to the suggestion in the commit log, we try with --embed first and then witout it if fails.

---
 tools/perf/Makefile.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.config +1 -1
index 80e55e7..b2eabcf 100644
@@ -229,7 +229,7 @@ strip-libs  = $(filter-out -l%,$(1))
 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
 
 ifdef PYTHON_CONFIG
-  PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
+  PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>/dev/null || $(PYTHON_CONFIG_SQ) --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)
Signature · 1 line
2.7.4
#6 lore raw

Em Mon, Feb 17, 2020 at 10:24:27AM +0800, He Zhe escreveu:

Quoted 13 lines · Jiri Olsa
Quoted 8 lines · On Fri, Feb 14, 2020 at 02:21:05AM +0800, [email protected] wrote:
Quoted 4 lines

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to python-config (GH-13500)"),

we got similar change recently.. might have not been picked up yet

https://lore.kernel.org/lkml/[email protected]/

Thanks for pointing out.

So, just with your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@five perf]$ make PYTHON=python3 -C tools/perf O=/tmp/build/perf install-bin |& grep python
... libpython: [ OFF ]
Makefile.config:750: No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev
CC /tmp/build/perf/tests/python-use.o
[acme@five perf]$

[acme@five perf]$ rpm -q python2-devel python3-devel python-devel package python2-devel is not installed python3-devel-3.7.6-2.fc31.x86_64
package python-devel is not installed
[acme@five perf]$

[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython.make.output /bin/sh: --configdir: command not found
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython
test-libpython.make.output test-libpython-version.make.output
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython-version.make.output /bin/sh: --configdir: command not found
[acme@five perf]$

Without your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@five perf]$ make PYTHON=python3 -C tools/perf O=/tmp/build/perf install-bin |& grep python
... libpython: [ on ]

  GEN      /tmp/build/perf/python/perf.so
  MKDIR    /tmp/build/perf/scripts/python/Perf-Trace-Util/
  CC       /tmp/build/perf/scripts/python/Perf-Trace-Util/Context.o
  LD       /tmp/build/perf/scripts/python/Perf-Trace-Util/perf-in.o
  CC       /tmp/build/perf/tests/python-use.o
  CC       /tmp/build/perf/util/scripting-engines/trace-event-python.o
  INSTALL  python-scripts

[acme@five perf]$

[acme@five perf]$ ldd /tmp/build/perf/perf |& grep python

	libpython3.7m.so.1.0 => /lib64/libpython3.7m.so.1.0 (0x00007f11dd1ee000)

[acme@five perf]$ perf -vv |& grep -i python
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
[acme@five perf]$

What am I missing?

[acme@five perf]$ cat /etc/redhat-release
Fedora release 31 (Thirty One)
[acme@five perf]$

- Arnaldo

#7 lore raw
Quoted 54 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 17, 2020 at 10:24:27AM +0800, He Zhe escreveu:

Quoted 13 lines · Jiri Olsa
Quoted 8 lines · On Fri, Feb 14, 2020 at 02:21:05AM +0800, [email protected] wrote:
Quoted 4 lines

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to python-config (GH-13500)"),

we got similar change recently.. might have not been picked up yet

https://lore.kernel.org/lkml/[email protected]/

Thanks for pointing out.

So, just with your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@five perf]$ make PYTHON=python3 -C tools/perf O=/tmp/build/perf install-bin |& grep python
... libpython: [ OFF ]
Makefile.config:750: No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev
CC /tmp/build/perf/tests/python-use.o
[acme@five perf]$

[acme@five perf]$ rpm -q python2-devel python3-devel python-devel package python2-devel is not installed python3-devel-3.7.6-2.fc31.x86_64
package python-devel is not installed
[acme@five perf]$

[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython.make.output /bin/sh: --configdir: command not found
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython
test-libpython.make.output test-libpython-version.make.output
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython-version.make.output /bin/sh: --configdir: command not found
[acme@five perf]$

Without your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@five perf]$ make PYTHON=python3 -C tools/perf O=/tmp/build/perf install-bin |& grep python
... libpython: [ on ]

  GEN      /tmp/build/perf/python/perf.so
  MKDIR    /tmp/build/perf/scripts/python/Perf-Trace-Util/
  CC       /tmp/build/perf/scripts/python/Perf-Trace-Util/Context.o
  LD       /tmp/build/perf/scripts/python/Perf-Trace-Util/perf-in.o
  CC       /tmp/build/perf/tests/python-use.o
  CC       /tmp/build/perf/util/scripting-engines/trace-event-python.o
  INSTALL  python-scripts

[acme@five perf]$

Quoted 7 lines

[acme@five perf]$ ldd /tmp/build/perf/perf |& grep python

        libpython3.7m.so.1.0 => /lib64/libpython3.7m.so.1.0 (0x00007f11dd1ee000)

[acme@five perf]$ perf -vv |& grep -i python
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
[acme@five perf]$

What am I missing?

It looks like you are using python3.7, but the change in behavior for python-config happened in version 3.8

Quoted 5 lines

[acme@five perf]$ cat /etc/redhat-release
Fedora release 31 (Thirty One)
[acme@five perf]$

- Arnaldo

#8 lore raw

Em Wed, Mar 25, 2020 at 09:40:34AM -0500, Sam Lunt escreveu:

Quoted 62 lines
Quoted 60 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 17, 2020 at 10:24:27AM +0800, He Zhe escreveu:

Quoted 13 lines · Jiri Olsa
Quoted 8 lines · On Fri, Feb 14, 2020 at 02:21:05AM +0800, [email protected] wrote:
Quoted 4 lines

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to python-config (GH-13500)"),

we got similar change recently.. might have not been picked up yet

https://lore.kernel.org/lkml/[email protected]/

Thanks for pointing out.

So, just with your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@five perf]$ make PYTHON=python3 -C tools/perf O=/tmp/build/perf install-bin |& grep python
... libpython: [ OFF ]
Makefile.config:750: No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev
CC /tmp/build/perf/tests/python-use.o
[acme@five perf]$

[acme@five perf]$ rpm -q python2-devel python3-devel python-devel package python2-devel is not installed python3-devel-3.7.6-2.fc31.x86_64
package python-devel is not installed
[acme@five perf]$

[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython.make.output /bin/sh: --configdir: command not found
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython
test-libpython.make.output test-libpython-version.make.output
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython-version.make.output /bin/sh: --configdir: command not found
[acme@five perf]$

Without your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@five perf]$ make PYTHON=python3 -C tools/perf O=/tmp/build/perf install-bin |& grep python
... libpython: [ on ]

  GEN      /tmp/build/perf/python/perf.so
  MKDIR    /tmp/build/perf/scripts/python/Perf-Trace-Util/
  CC       /tmp/build/perf/scripts/python/Perf-Trace-Util/Context.o
  LD       /tmp/build/perf/scripts/python/Perf-Trace-Util/perf-in.o
  CC       /tmp/build/perf/tests/python-use.o
  CC       /tmp/build/perf/util/scripting-engines/trace-event-python.o
  INSTALL  python-scripts

[acme@five perf]$

[acme@five perf]$ ldd /tmp/build/perf/perf |& grep python

        libpython3.7m.so.1.0 => /lib64/libpython3.7m.so.1.0 (0x00007f11dd1ee000)

[acme@five perf]$ perf -vv |& grep -i python
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
[acme@five perf]$

Quoted 4 lines
Quoted 1 line

What am I missing?

It looks like you are using python3.7, but the change in behavior for python-config happened in version 3.8

Humm, but shouldn't this continue to work with python3.7?

- Arnaldo

Quoted 5 lines
Quoted 5 lines

[acme@five perf]$ cat /etc/redhat-release
Fedora release 31 (Thirty One)
[acme@five perf]$

- Arnaldo

Signature · 1 line
- Arnaldo
#9 lore raw
Quoted 64 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 25, 2020 at 09:40:34AM -0500, Sam Lunt escreveu:

Quoted 62 lines
Quoted 60 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 17, 2020 at 10:24:27AM +0800, He Zhe escreveu:

Quoted 13 lines · Jiri Olsa
Quoted 8 lines · On Fri, Feb 14, 2020 at 02:21:05AM +0800, [email protected] wrote:
Quoted 4 lines

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to python-config (GH-13500)"),

we got similar change recently.. might have not been picked up yet

https://lore.kernel.org/lkml/[email protected]/

Thanks for pointing out.

So, just with your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@five perf]$ make PYTHON=python3 -C tools/perf O=/tmp/build/perf install-bin |& grep python
... libpython: [ OFF ]
Makefile.config:750: No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev
CC /tmp/build/perf/tests/python-use.o
[acme@five perf]$

[acme@five perf]$ rpm -q python2-devel python3-devel python-devel package python2-devel is not installed python3-devel-3.7.6-2.fc31.x86_64
package python-devel is not installed
[acme@five perf]$

[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython.make.output /bin/sh: --configdir: command not found
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython
test-libpython.make.output test-libpython-version.make.output
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython-version.make.output /bin/sh: --configdir: command not found
[acme@five perf]$

Without your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf
[acme@five perf]$ make PYTHON=python3 -C tools/perf O=/tmp/build/perf install-bin |& grep python
... libpython: [ on ]

  GEN      /tmp/build/perf/python/perf.so
  MKDIR    /tmp/build/perf/scripts/python/Perf-Trace-Util/
  CC       /tmp/build/perf/scripts/python/Perf-Trace-Util/Context.o
  LD       /tmp/build/perf/scripts/python/Perf-Trace-Util/perf-in.o
  CC       /tmp/build/perf/tests/python-use.o
  CC       /tmp/build/perf/util/scripting-engines/trace-event-python.o
  INSTALL  python-scripts

[acme@five perf]$

[acme@five perf]$ ldd /tmp/build/perf/perf |& grep python

        libpython3.7m.so.1.0 => /lib64/libpython3.7m.so.1.0 (0x00007f11dd1ee000)

[acme@five perf]$ perf -vv |& grep -i python
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
[acme@five perf]$

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

What am I missing?

It looks like you are using python3.7, but the change in behavior for python-config happened in version 3.8

Humm, but shouldn't this continue to work with python3.7?

Oh, my mistake, I didn't read the output carefully. It should obviously still work with old versions, yes. I actually submitted a similar patch, and it seemed to work when I used python 3.7. I wonder if the issue is the "||" operator in the subshell.

https://lore.kernel.org/lkml/[email protected]/

Quoted 11 lines

- Arnaldo

Quoted 5 lines
Quoted 5 lines

[acme@five perf]$ cat /etc/redhat-release
Fedora release 31 (Thirty One)
[acme@five perf]$

- Arnaldo

--

- Arnaldo

#10 lore raw
Quoted 88 lines · Sam Lunt
Quoted 10 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 25, 2020 at 09:40:34AM -0500, Sam Lunt escreveu:

Quoted 8 lines
Quoted 6 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 17, 2020 at 10:24:27AM +0800, He Zhe escreveu:

Quoted 4 lines · Jiri Olsa
Quoted 1 line

On Fri, Feb 14, 2020 at 02:21:05AM +0800,

Quoted 4 lines · [email protected] wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to

python-config (GH-13500)"),

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

we got similar change recently.. might have not been picked

up yet

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

https://lore.kernel.org/lkml/[email protected]/

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Thanks for pointing out.

So, just with your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p

/tmp/build/perf

Quoted 1 line
Quoted 1 line
Quoted 1 line

[acme@five perf]$ make PYTHON=python3 -C tools/perf

O=/tmp/build/perf install-bin |& grep python

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

... libpython: [ OFF ]
Makefile.config:750: No 'Python.h' (for Python 2.x support) was

found: disables Python support - please install python-devel/python-dev

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

CC /tmp/build/perf/tests/python-use.o
[acme@five perf]$

[acme@five perf]$ rpm -q python2-devel python3-devel python-devel package python2-devel is not installed python3-devel-3.7.6-2.fc31.x86_64
package python-devel is not installed
[acme@five perf]$

[acme@five perf]$ cat

/tmp/build/perf/feature/test-libpython.make.output

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

/bin/sh: --configdir: command not found
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython test-libpython.make.output

test-libpython-version.make.output

Quoted 1 line
Quoted 1 line
Quoted 1 line

[acme@five perf]$ cat

/tmp/build/perf/feature/test-libpython-version.make.output

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

/bin/sh: --configdir: command not found
[acme@five perf]$

Without your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p

/tmp/build/perf

Quoted 1 line
Quoted 1 line
Quoted 1 line

[acme@five perf]$ make PYTHON=python3 -C tools/perf

O=/tmp/build/perf install-bin |& grep python

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

... libpython: [ on ]
GEN /tmp/build/perf/python/perf.so
MKDIR /tmp/build/perf/scripts/python/Perf-Trace-Util/
CC

/tmp/build/perf/scripts/python/Perf-Trace-Util/Context.o

Quoted 1 line
Quoted 1 line
Quoted 1 line

LD

/tmp/build/perf/scripts/python/Perf-Trace-Util/perf-in.o

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CC /tmp/build/perf/tests/python-use.o
CC

/tmp/build/perf/util/scripting-engines/trace-event-python.o

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

INSTALL python-scripts
[acme@five perf]$

[acme@five perf]$ ldd /tmp/build/perf/perf |& grep python

        libpython3.7m.so.1.0 => /lib64/libpython3.7m.so.1.0

(0x00007f11dd1ee000)

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

[acme@five perf]$ perf -vv |& grep -i python
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
[acme@five perf]$

What am I missing?

It looks like you are using python3.7, but the change in behavior

for

Quoted 2 lines
Quoted 1 line

python-config happened in version 3.8

Quoted 8 lines
Quoted 1 line

Humm, but shouldn't this continue to work with python3.7?

Oh, my mistake, I didn't read the output carefully. It should obviously still work with old versions, yes. I actually submitted a similar patch, and it seemed to work when I used python 3.7. I wonder if the issue is the "||" operator in the subshell.

https://lore.kernel.org/lkml/[email protected]/

I'm aware of your path, even for confused by your comment here, will it try it tomorrow

Quoted 13 lines
Quoted 13 lines

- Arnaldo

Quoted 5 lines
Quoted 5 lines

[acme@five perf]$ cat /etc/redhat-release
Fedora release 31 (Thirty One)
[acme@five perf]$

- Arnaldo

--

- Arnaldo

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
author
#11 lore raw
Quoted 83 lines · Arnaldo Melo
Quoted 81 lines · Sam Lunt
Quoted 7 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 25, 2020 at 09:40:34AM -0500, Sam Lunt escreveu:

Quoted 6 lines
Quoted 4 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 17, 2020 at 10:24:27AM +0800, He Zhe escreveu:

Quoted 3 lines · Jiri Olsa
Quoted 1 line

On Fri, Feb 14, 2020 at 02:21:05AM +0800,

Quoted 4 lines · [email protected] wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

From: He Zhe <[email protected]>

Since Python v3.8.0, with the following commit
0a8e57248b91 ("bpo-36721: Add --embed option to

python-config (GH-13500)"),

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

we got similar change recently.. might have not been picked

up yet

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

https://lore.kernel.org/lkml/[email protected]/

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Thanks for pointing out.

So, just with your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p

/tmp/build/perf

Quoted 1 line
Quoted 1 line
Quoted 1 line

[acme@five perf]$ make PYTHON=python3 -C tools/perf

O=/tmp/build/perf install-bin |& grep python

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

... libpython: [ OFF ]
Makefile.config:750: No 'Python.h' (for Python 2.x support) was

found: disables Python support - please install python-devel/python-dev

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

CC /tmp/build/perf/tests/python-use.o
[acme@five perf]$

[acme@five perf]$ rpm -q python2-devel python3-devel python-devel package python2-devel is not installed python3-devel-3.7.6-2.fc31.x86_64
package python-devel is not installed
[acme@five perf]$

[acme@five perf]$ cat

/tmp/build/perf/feature/test-libpython.make.output

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

/bin/sh: --configdir: command not found
[acme@five perf]$ cat /tmp/build/perf/feature/test-libpython test-libpython.make.output

test-libpython-version.make.output

Quoted 1 line
Quoted 1 line
Quoted 1 line

[acme@five perf]$ cat

/tmp/build/perf/feature/test-libpython-version.make.output

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

/bin/sh: --configdir: command not found
[acme@five perf]$

Without your patch:

[acme@five perf]$ rm -rf /tmp/build/perf ; mkdir -p

/tmp/build/perf

Quoted 1 line
Quoted 1 line
Quoted 1 line

[acme@five perf]$ make PYTHON=python3 -C tools/perf

O=/tmp/build/perf install-bin |& grep python

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

... libpython: [ on ]
GEN /tmp/build/perf/python/perf.so
MKDIR /tmp/build/perf/scripts/python/Perf-Trace-Util/
CC

/tmp/build/perf/scripts/python/Perf-Trace-Util/Context.o

Quoted 1 line
Quoted 1 line
Quoted 1 line

LD

/tmp/build/perf/scripts/python/Perf-Trace-Util/perf-in.o

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CC /tmp/build/perf/tests/python-use.o
CC

/tmp/build/perf/util/scripting-engines/trace-event-python.o

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

INSTALL python-scripts
[acme@five perf]$

[acme@five perf]$ ldd /tmp/build/perf/perf |& grep python

        libpython3.7m.so.1.0 => /lib64/libpython3.7m.so.1.0

(0x00007f11dd1ee000)

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

[acme@five perf]$ perf -vv |& grep -i python
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
[acme@five perf]$

What am I missing?

It looks like you are using python3.7, but the change in behavior

for

Quoted 2 lines
Quoted 1 line

python-config happened in version 3.8

Humm, but shouldn't this continue to work with python3.7?

Quoted 8 lines
Quoted 6 lines

Oh, my mistake, I didn't read the output carefully. It should obviously still work with old versions, yes. I actually submitted a similar patch, and it seemed to work when I used python 3.7. I wonder if the issue is the "||" operator in the subshell.

https://lore.kernel.org/lkml/[email protected]/

I'm aware of your path, even for confused by your comment here, will it try it tomorrow

Sorry for inconvenience.

Yes, it is due to that the command before "||" prints some usage on failure and thus messes up the whole string.

And I've tested Sam's patch. It works.

BTW, my [2/2] may still make sense.

Thanks,
Zhe

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

- Arnaldo

Quoted 5 lines
Quoted 5 lines

[acme@five perf]$ cat /etc/redhat-release
Fedora release 31 (Thirty One)
[acme@five perf]$

- Arnaldo

--

- Arnaldo

merge bot Applied
#12 lore raw

[tip: perf/urgent] perf tools: Support Python 3.8+ in Makefile

The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     b9c9ce4e598e012ca7c1813fae2f4d02395807de
Gitweb:        https://git.kernel.org/tip/b9c9ce4e598e012ca7c1813fae2f4d02395807de
Author:        Sam Lunt <[email protected]>
AuthorDate:    Fri, 31 Jan 2020 12:11:23 -06:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Fri, 03 Apr 2020 10:03:44 -03:00

perf tools: 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.

---
 tools/perf/Makefile.config | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/perf/Makefile.config +10 -1
index eb95c0c..12a8204 100644
@@ -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)