Skip to contentSkip to conversation

perf s390: Fix TEXTREL in Python extension by compiling as PIC

PATCH Applied Jens Remus 4 participants 4 messages Jun 10

Subsystems (2)
lore
Share & tools
lore

Jens Remus

author
#0 lore raw

PATCH 1/1 perf s390: Fix TEXTREL in Python extension by compiling as PIC

On s390 the Python extension build fails as follows when using a linker that is configured to treat text relocations (TEXTREL) in shared libraries as error by default:

GEN python/perf.cpython-314-s390x-linux-gnu.so
/usr/bin/ld.bfd: error: read-only segment has dynamic relocations

This occurrs because util/llvm-c-helpers.o is erroneously built from util/llvm-c-helpers.cpp without compiler option -fPIC but linked into the shared library (via libperf-util.a(perf-util-in.o)).

On s390, object files must be compiled as position-indepedent code (PIC) in order to be linked into shared libraries. Commit a9a3f1d18a6c ("perf
s390: Always build with -fPIC") added compiler option -fPIC to CFLAGS for s390, which is used in C compiles. Add -fPIC to CXXFLAGS for s390 as well, so that it is also used in C++ compiles.

---

Notes (jremus):
This patch applies on top of the perf-tools-next tree:

git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git master

Note that this resolves the issue discussed in thread "[PATCH 1/1] perf
build: Fix Python extension build with GCC 16 hardening":
https://lore.kernel.org/all/[email protected]/T/

 tools/perf/Makefile.config | 1 +
 1 file changed, 1 insertion(+)
tools/perf/Makefile.config +1 -0
index 333ddd0e4bd8..33f90968c8a9 100644
@@ -109,6 +109,7 @@ endif
 
 ifeq ($(ARCH),s390)
   CFLAGS += -fPIC
+  CXXFLAGS += -fPIC
 endif
 
 ifeq ($(ARCH),mips)
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 38 lines · Jens Remus

On s390 the Python extension build fails as follows when using a linker that is configured to treat text relocations (TEXTREL) in shared libraries as error by default:

   GEN     python/perf.cpython-314-s390x-linux-gnu.so

/usr/bin/ld.bfd: error: read-only segment has dynamic relocations

This occurrs because util/llvm-c-helpers.o is erroneously built from util/llvm-c-helpers.cpp without compiler option -fPIC but linked into the shared library (via libperf-util.a(perf-util-in.o)).

On s390, object files must be compiled as position-indepedent code (PIC) in order to be linked into shared libraries. Commit a9a3f1d18a6c ("perf
s390: Always build with -fPIC") added compiler option -fPIC to CFLAGS for s390, which is used in C compiles. Add -fPIC to CXXFLAGS for s390 as well, so that it is also used in C++ compiles.

---

Notes (jremus):
This patch applies on top of the perf-tools-next tree:

git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git master

Note that this resolves the issue discussed in thread "[PATCH 1/1] perf
build: Fix Python extension build with GCC 16 hardening":
https://lore.kernel.org/all/[email protected]/T/

  tools/perf/Makefile.config | 1 +
  1 file changed, 1 insertion(+)
tools/perf/Makefile.config +0 -0
index 333ddd0e4bd8..33f90968c8a9 100644

tools/perf/Makefile.config endif · line 115

Quoted 7 lines
tools/perf/Makefile.config +1 -0
@@ -109,6 +109,7 @@ endif
 
  ifeq ($(ARCH),s390)
    CFLAGS += -fPIC
+  CXXFLAGS += -fPIC
  endif
 
  ifeq ($(ARCH),mips)
reviewer Reviewed-by
#2 lore raw
Quoted 15 lines · James Clark
Quoted 11 lines · Jens Remus

On s390 the Python extension build fails as follows when using a linker that is configured to treat text relocations (TEXTREL) in shared libraries as error by default:

   GEN     python/perf.cpython-314-s390x-linux-gnu.so

/usr/bin/ld.bfd: error: read-only segment has dynamic relocations

This occurrs because util/llvm-c-helpers.o is erroneously built from util/llvm-c-helpers.cpp without compiler option -fPIC but linked into the shared library (via libperf-util.a(perf-util-in.o)).

Quoted 8 lines
Quoted 8 lines

On s390, object files must be compiled as position-indepedent code (PIC) in order to be linked into shared libraries. Commit a9a3f1d18a6c ("perf
s390: Always build with -fPIC") added compiler option -fPIC to CFLAGS for s390, which is used in C compiles. Add -fPIC to CXXFLAGS for s390 as well, so that it is also used in C++ compiles.

Great! Perhaps we should add a fixes tag for backports. Perhaps:

Fixes a9a3f1d18a6c ("perf s390: Always build with -fPIC")

Thanks,
Ian

Quoted 29 lines
Quoted 19 lines

---

Notes (jremus):
This patch applies on top of the perf-tools-next tree:

git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git master

Note that this resolves the issue discussed in thread "[PATCH 1/1] perf
build: Fix Python extension build with GCC 16 hardening":
https://lore.kernel.org/all/[email protected]/T/

  tools/perf/Makefile.config | 1 +
  1 file changed, 1 insertion(+)
tools/perf/Makefile.config +0 -0
index 333ddd0e4bd8..33f90968c8a9 100644

tools/perf/Makefile.config endif · line 115

Quoted 7 lines
tools/perf/Makefile.config +1 -0
@@ -109,6 +109,7 @@ endif
 
  ifeq ($(ARCH),s390)
    CFLAGS += -fPIC
+  CXXFLAGS += -fPIC
  endif
 
  ifeq ($(ARCH),mips)
maintainer Applied
#3 lore raw
In reply to James Clark
Quoted 10 lines · James Clark

tools/perf/Makefile.config endif · line 113

Quoted 7 lines · Jens Remus

+++ b/tools/perf/Makefile.config

tools/perf/Makefile.config +1 -0
@@ -109,6 +109,7 @@ endif
  ifeq ($(ARCH),s390)
    CFLAGS += -fPIC
+  CXXFLAGS += -fPIC
  endif
  ifeq ($(ARCH),mips)

Thanks, applied to perf-tools-next, for v7.2.

- Arnaldo