Linux Perf Users
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Jan Polensky <japo@linux.ibm.com>
Cc: sashiko-reviews@lists.linux.dev, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 1/1] perf build: Fix Python extension build with GCC 16 hardening
Date: Sat, 23 May 2026 23:49:22 -0300	[thread overview]
Message-ID: <ahJnMnOr4i9urrRk@x1> (raw)
In-Reply-To: <20260520130905.9C85D1F000E9@smtp.kernel.org>

On Wed, May 20, 2026 at 01:09:05PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The patch explicitly allows text relocations in the Python extension shared object (`perf.so`) by adding `-Wl,-z,notext`, masking the root cause of missing `-fPIC` flags and breaking W^X (Write XOR Execute) security protections.
> --
> 
> commit f3832fb0ad0d1f9c2e69039b2a5110f77d220d5e
> Author: Jan Polensky <japo@linux.ibm.com>
> 
> perf build: Fix Python extension build with GCC 16 hardening
> 
> This commit addresses a build failure in the Python extension caused by GCC 16
> stricter security policies regarding dynamic relocations in read-only segments.
> It adds the -Wl,-z,notext flag to the linker to explicitly allow text
> relocations in the Python extension shared object.
> 
> > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> > index 76b35ac19acbf..eea170d6576db 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" \
> 
> [Severity: Medium]
> Does adding -Wl,-z,notext mask the root cause of the GCC 16 linker error?
> 
> The error regarding dynamic relocations in a read-only segment usually
> indicates that non-position-independent code from the static libraries
> is being linked into the shared library.
> 
> Using -Wl,-z,notext suppresses this error by allowing text relocations, which
> forces the dynamic linker to map the executable text segment as writable at
> load time. This breaks W^X security protections and weakens the security of
> any Python process loading the extension.
> 
> Should the required object files be compiled with -fPIC instead to properly
> resolve the linker error without compromising security?

So I asked Claude about this and he suggests doing like other parts of
perf and using -fPIC, can you try to do that?

---------------------------------------

● Sashiko is right. -Wl,-z,notext is a band-aid that weakens security —
  it makes the text segment writable at load time, defeating W^X.

  The root cause is that PERFLIBS_PY (the static libraries linked into
  the Python .so) are compiled without -fPIC. When you link non-PIC .a
  archives into a shared library, the linker needs text relocations. GCC
  16 correctly rejects this by default.

  The proper fix is to build the static libraries that go into the
  Python extension with -fPIC. The perf build system already has
  precedent for this — look for how libperf and libsubcmd handle PIC
  builds. The Python extension's dependencies need a parallel -fPIC
  build, or the existing objects need to be compiled with -fPIC when the
  Python binding is enabled.

  The -Wl,-z,notext approach would also cause issues on distros that
  enforce RELRO + BIND_NOW hardening, and some package builders would
  reject the resulting .so outright.

- Arnaldo

  reply	other threads:[~2026-05-24  2:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahJnMnOr4i9urrRk@x1 \
    --to=acme@kernel.org \
    --cc=japo@linux.ibm.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox