GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-143632: Detect availability of `PR_SET_VMA` at runtime (fixes build with musl libc) by sideeffect42 · Pull Request #148771 · python/cpython

Conversation

@sideeffect42

@sideeffect42 sideeffect42 commented Apr 19, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Building latest Python 3.15.0a8+ on musl-based Linux fails with the following error:

gcc -c -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Objects/obmalloc.o Objects/obmalloc.c
In file included from ./Include/internal/pycore_mmap.h:16,
                 from Objects/obmalloc.c:5:
/usr/include/sys/prctl.h:88:8: error: redefinition of 'struct prctl_mm_map'
   88 | struct prctl_mm_map {
      |        ^~~~~~~~~~~~
In file included from ./Include/internal/pycore_mmap.h:15:
/usr/include/linux/prctl.h:134:8: note: originally defined here
  134 | struct prctl_mm_map {
      |        ^~~~~~~~~~~~
make: *** [Makefile:3388: Objects/obmalloc.o] Error 1

This is due to Python including both <linux/prctl.h> and <sys/prctl.h> (which on glibc imports the definitions from <linux/prctl.h> and on musl includes all the definitions itself).
Given that Python is not the Linux kernel, <sys/prctl.h> should be included.

Another issue of the previous implementation and the configure check was that the _PyAnnotateMemoryMap() function would only be enabled if the linux-headers on the build host are recent enough to contain the PR_SET_VMA_ANON_NAME macro.

However the resulting binaries might be run on older kernels lacking the functionality or be built on older systems but run on newer kernels.

With this patch, the function is always enabled and the magic numbers are included with Python, so that the prctl() is always executed and feature detection is essentially done at runtime.

When run on a kernel too old to support PR_SET_VMA_ANON_NAME, mmap.mmap.set_name() will silently do nothing.
When the kernel is new enough but CONFIG_ANON_VMA_NAME is not enabled, mmap.mmap.set_name() will raise an OSError, e.g.:

>>> mm.set_name("hello")
Traceback (most recent call last):
  File "<python-input-5>", line 1, in <module>
    mm.set_name("hello")
    ~~~~~~~~~~~^^^^^^^^^
OSError: [Errno 22] Invalid argument
  • Issue: failure building Python 3.15.0a3 through 3.15.0 release on Alpine #143632

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tucumcari reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@sideeffect42
sideeffect42 requested review from AA-Turner, corona10, emmatyping and erlend-aasland as code owners April 19, 2026 19:43
@bedevere-app bedevere-app Bot added the awaiting review label Apr 19, 2026
@python-cla-bot

python-cla-bot Bot commented Apr 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Apr 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request Apr 19, 2026
failure building Python 3.15.0a3 through 3.15.0 release on Alpine #143632
Open
@sideeffect42
sideeffect42 force-pushed the fix/musl-prctl branch from 248dbf9 to 4dcdecf Compare April 19, 2026 19:45
@bedevere-app

bedevere-app Bot commented Apr 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sideeffect42
sideeffect42 force-pushed the fix/musl-prctl branch from 4dcdecf to 8ddb452 Compare April 19, 2026 19:47
@bedevere-app

bedevere-app Bot commented Apr 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@corona10 corona10 self-assigned this Apr 20, 2026
corona10
corona10 reviewed Apr 20, 2026
View reviewed changes
Comment thread Include/internal/pycore_mmap.h Outdated

#include "pycore_pystate.h"

#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__)

@corona10 corona10 Apr 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you should fix the detecting logic of HAVE_PR_SET_VMA_ANON_NAME not code itself.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@corona10 corona10 Apr 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here:

cpython/configure.ac

Lines 5731 to 5740 in bfe6f9f

# musl libc redefines struct prctl_mm_map and conflicts with linux/prctl.h
AS_IF([test "$ac_cv_libc" != musl], [
AC_CHECK_DECLS([PR_SET_VMA_ANON_NAME],
[AC_DEFINE([HAVE_PR_SET_VMA_ANON_NAME], [1],
[Define if you have the 'PR_SET_VMA_ANON_NAME' constant.])],
[],
[@%:@include <linux/prctl.h>
@%:@include <sys/prctl.h>])
])
# check for openpty, login_tty, and forkpty

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sideeffect42 sideeffect42 Apr 20, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would I fix the detection logic to address a compile-time error in the actual implementation?

When you think about what this configure step actually does, you may notice that what we are detecting there has no real connection to reality.
The set of macro definitions in the two header files is either whatever the libc has copied from a random kernel version (<sys/prctl.h>) or whatever the version of the system's linux-headers package contains (<linux/prctl.h>).

Both of which don't have to match the kernel which will then actually run the interpreter in the future.

Say, the interpreter is compiled as part of the build chain of some distro which is then used as the base image for a Linux container.
The kernel on which this container may be run does not have to have anything in common with the kernel the distro in the base image usually ships.
What does this configure check tell us?

Further, the mere presence of #define HAVE_PR_SET_VMA_ANON_NAME in <linux/prctl.h> says nothing about whether the kernel has CONFIG_ANON_VMA_NAME enabled.
So Python could call prctl() on a kernel which does not support this feature.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rofl0r reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@NagendraRK NagendraRK Apr 21, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am with @sideeffect42. This has nothing to do with compile time error. It has to do with the implementation. The value it emits in <sys/kernal_info.h> needs to chnage in a future PR. Thoughts ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rofl0r rofl0r Jun 28, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides, including the linux header on glibc isn't needed either.

#include <sys/prctl.h>
int test() {return PR_SET_VMA_ANON_NAME; }

compiles fine on debian trixie. so there's no need for "musl libc detected" workarounds.
obviously, the code using PR_SET_VMA_ANON_NAME can only be compiled if the macro is defined, but OP is correct that the macro can be defined even if the functionality isn't compiled into the kernel.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app

bedevere-app Bot commented Apr 25, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sideeffect42
sideeffect42 force-pushed the fix/musl-prctl branch from 6c751d0 to 6805c48 Compare April 25, 2026 09:50
@bedevere-app

bedevere-app Bot commented Apr 25, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sideeffect42
sideeffect42 requested a review from corona10 June 6, 2026 18:18
@github-actions

github-actions Bot commented Sep 29, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 29, 2026
@sideeffect42
sideeffect42 force-pushed the fix/musl-prctl branch from 6805c48 to 3804915 Compare October 4, 2026 15:08
@sideeffect42
sideeffect42 requested a review from itamaro as a code owner October 4, 2026 15:08
@bedevere-app

bedevere-app Bot commented Oct 4, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sideeffect42

sideeffect42 commented Oct 4, 2026

Copy link
Copy Markdown
Author

The compile-time error with musl libc still persists in 3.15.0rc3.

It would be great if this bug could be fixed before 3.15 is released.
Please let me know if there is anything to be improved with this PR to get it merged.

yosifkit reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sideeffect42 Dennis Camera
Detect availability of PR_SET_VMA at runtime (fixes build with musl l…
ad7b55a
…ibc)

The build would fail on musl-based systems with the following error:

    gcc -c -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -DPy_BUILD_CORE -o Objects/obmalloc.o Objects/obmalloc.c
    In file included from ./Include/internal/pycore_mmap.h:16,
                     from Objects/obmalloc.c:5:
    /usr/include/sys/prctl.h:88:8: error: redefinition of 'struct prctl_mm_map'
       88 | struct prctl_mm_map {
          |        ^~~~~~~~~~~~
    In file included from ./Include/internal/pycore_mmap.h:15:
    /usr/include/linux/prctl.h:134:8: note: originally defined here
      134 | struct prctl_mm_map {
          |        ^~~~~~~~~~~~
    make: *** [Makefile:3388: Objects/obmalloc.o] Error 1

This is due to Python including both <linux/prctl.h> and <sys/prctl.h> (which on
glibc imports the definitions from <linux/prctl.h> and on musl includes all the
definitions itself).
Given that Python is not the Linux kernel, <sys/prctl.h> should be included.

Another issue of the previous implementation and the configure check was that
the `_PyAnnotateMemoryMap()` function would only be enabled if the linux-headers
on the build host are recent enough to contain the `PR_SET_VMA_ANON_NAME` macro.

However the resulting binaries might be run on older kernels lacking the
functionality or be built on older systems but run on newer kernels.

With this patch, the function is always enabled and the magic numbers are
included with Python, so that the `prctl()` is always executed and
feature detection is essentially done at runtime.

When run on a kernel too old to support `PR_SET_VMA_ANON_NAME`,
`mmap.mmap.set_name()` will silently do nothing.
When the kernel is new enough but `CONFIG_ANON_VMA_NAME` is not enabled,
`mmap.mmap.set_name()` will raise an `OSError`, e.g.:

    >>> mm.set_name("hello")
    Traceback (most recent call last):
      File "<python-input-5>", line 1, in <module>
        mm.set_name("hello")
        ~~~~~~~~~~~^^^^^^^^^
    OSError: [Errno 22] Invalid argument
@sideeffect42
sideeffect42 force-pushed the fix/musl-prctl branch from 3804915 to ad7b55a Compare October 4, 2026 15:13
@bedevere-app

bedevere-app Bot commented Oct 4, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@emmatyping emmatyping Awaiting requested review from emmatyping emmatyping is a code owner
@corona10 corona10 Awaiting requested review from corona10 corona10 is a code owner
@itamaro itamaro Awaiting requested review from itamaro itamaro is a code owner
2 more reviewers
@rofl0r rofl0r rofl0r left review comments
@NagendraRK NagendraRK NagendraRK left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@corona10 corona10

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@sideeffect42 @rofl0r @corona10 @NagendraRK
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.