[PATCH] perf s390: Fix TEXTREL in Python extension by compiling as PIC
From: Jens Remus
Date: Wed Jun 10 2026 - 07:28:04 EST
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.
Reported-by: Thomas Richter <tmricht@xxxxxxxxxxxxx>
Signed-off-by: Jens Remus <jremus@xxxxxxxxxxxxx>
---
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/ahV2XGx_6h7upuc3@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/T/
tools/perf/Makefile.config | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 333ddd0e4bd8..33f90968c8a9 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -109,6 +109,7 @@ endif
ifeq ($(ARCH),s390)
CFLAGS += -fPIC
+ CXXFLAGS += -fPIC
endif
ifeq ($(ARCH),mips)
--
2.53.0