* [PATCH 1/1] perf build: Fix Python extension build with GCC 16 hardening
@ 2026-05-20 12:56 Jan Polensky
2026-05-20 13:38 ` Thomas Richter
0 siblings, 1 reply; 2+ messages in thread
From: Jan Polensky @ 2026-05-20 12:56 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung
Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
james.clark, tmricht, linux-perf-users, linux-kernel
The Python extension build fails with modern GCC versions (16+) due to
the new hardening feature that prevents dynamic relocations in read-only
segments:
/usr/bin/ld.bfd: error: read-only segment has dynamic relocations
collect2: error: ld returned 1 exit status
This occurs when building the perf Python bindings because the linker
enforces stricter security policies by default.
Add -Wl,-z,notext to LDSHARED to explicitly allow text relocations in
the Python extension shared object. This is necessary for the Python
C extension to link successfully while maintaining compatibility with
the Python build system.
The flag only affects the Python extension build and does not impact
the security of the main perf binary or other components.
Tested on Fedora 44 with GCC 16.1.1 20260501 (Red Hat 16.1.1-1) and
Python 3.14.4 on s390x architecture.
Reported-by: Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
---
tools/perf/Makefile.perf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index bfb37f527241..12af424dd5c1 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -749,7 +749,7 @@ all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS)
$(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python')
$(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py $(PERFLIBS_PY)
- $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \
+ $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared -Wl,-z,notext" \
CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBS_PY)' \
$(PYTHON_WORD) util/setup.py \
--quiet build_ext; \
--
2.51.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] perf build: Fix Python extension build with GCC 16 hardening
2026-05-20 12:56 [PATCH 1/1] perf build: Fix Python extension build with GCC 16 hardening Jan Polensky
@ 2026-05-20 13:38 ` Thomas Richter
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Richter @ 2026-05-20 13:38 UTC (permalink / raw)
To: Jan Polensky, peterz, mingo, acme, namhyung
Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
james.clark, linux-perf-users, linux-kernel
On 5/20/26 14:56, Jan Polensky wrote:
> The Python extension build fails with modern GCC versions (16+) due to
> the new hardening feature that prevents dynamic relocations in read-only
> segments:
>
> /usr/bin/ld.bfd: error: read-only segment has dynamic relocations
> collect2: error: ld returned 1 exit status
>
> This occurs when building the perf Python bindings because the linker
> enforces stricter security policies by default.
>
> Add -Wl,-z,notext to LDSHARED to explicitly allow text relocations in
> the Python extension shared object. This is necessary for the Python
> C extension to link successfully while maintaining compatibility with
> the Python build system.
>
> The flag only affects the Python extension build and does not impact
> the security of the main perf binary or other components.
>
> Tested on Fedora 44 with GCC 16.1.1 20260501 (Red Hat 16.1.1-1) and
> Python 3.14.4 on s390x architecture.
>
> Reported-by: Thomas Richter <tmricht@linux.ibm.com>
> Signed-off-by: Jan Polensky <japo@linux.ibm.com>
> ---
> tools/perf/Makefile.perf | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index bfb37f527241..12af424dd5c1 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -749,7 +749,7 @@ all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS)
> $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python')
>
> $(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py $(PERFLIBS_PY)
> - $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \
> + $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared -Wl,-z,notext" \
> CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBS_PY)' \
> $(PYTHON_WORD) util/setup.py \
> --quiet build_ext; \
Thanks for fixing this.
Reviewed-by: Thomas Richter <tmricht@linux.ibm.com>
Tested-by: Thomas Richter <tmricht@linux.ibm.com>
--
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-20 13:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-20 12:56 [PATCH 1/1] perf build: Fix Python extension build with GCC 16 hardening Jan Polensky
2026-05-20 13:38 ` Thomas Richter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®