Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH 1/1] perf build: Fix Python extension build with GCC 16 hardening
@ 2026-05-20 12:56 Jan Polensky
  2026-05-20 13:09 ` sashiko-bot
  2026-05-20 13:38 ` Thomas Richter
  0 siblings, 2 replies; 10+ 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 related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-05-27 21:08 UTC | newest]

Thread overview: 10+ 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:09 ` sashiko-bot
2026-05-24  2:49   ` Arnaldo Carvalho de Melo
2026-05-26 10:30     ` Jan Polensky
2026-05-26 15:23       ` Ian Rogers
2026-05-26 16:20         ` Jan Polensky
2026-05-26 16:59           ` Ian Rogers
2026-05-27 18:02             ` Jan Polensky
2026-05-27 21:08             ` Namhyung Kim
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