{{ message }}
gh-153400: Add syscall fallbacks for copy_file_range/memfd_create - #155520
Merged
Merged
Conversation
daandemeyer
force-pushed
the
push-rwtvzrusrnyp
branch
from
August 10, 2026 20:36
10bc047 to
fe87313
Compare
vstinner
reviewed
Aug 10, 2026
daandemeyer
force-pushed
the
push-rwtvzrusrnyp
branch
from
August 11, 2026 06:43
fe87313 to
0dc17c3
Compare
Contributor
Author
|
@vstinner Addressed comments, no other changes |
Contributor
Member
|
I merged my PR gh-155518 which replace syscall() calls with glibc function calls. Oh, it created some conflicts in generated files. Would you mind to update your branch ( |
glibc only grew copy_file_range() and memfd_create() in 2.27, and we compile the os functions out when the libc we build against doesn't have them. That loses them for good in a redistributable built against an older glibc, such as the python-build-standalone builds targeting glibc 2.17, even when the kernel it runs on implements the syscalls. Keep calling the libc wrappers when they are available, so we don't lose their symbol versioning and _FORTIFY_SOURCE checks, and issue the syscall directly when they aren't. If the syscall number is missing as well, the functions are still left out. pidfd_open() and pidfd_getfd() already use raw syscalls, so nothing changes for them. Include <sys/syscall.h> whenever it exists rather than only when the getrandom() syscall was detected, since __NR_* is now needed for more than getrandom(). Signed-off-by: Daan De Meyer <daan@amutable.com>
daandemeyer
force-pushed
the
push-rwtvzrusrnyp
branch
from
August 13, 2026 12:06
0dc17c3 to
96a7a84
Compare
Contributor
Author
vstinner
approved these changes
Aug 13, 2026
vstinner
left a comment
Member
There was a problem hiding this comment.
LGTM.
In general, I would prefer to only support an os function if it has a glibc (wrapper) function. But well, in practice, glibc takes time to add a new function. And getting the right {Python, glibc and kernel} combo can be complicated. So I'm fine with adding syscall() implementation for copy_file_range() and memfd_create().
vstinner
enabled auto-merge (squash)
August 13, 2026 12:12
zanieb
pushed a commit
to astral-sh/python-build-standalone
that referenced
this pull request
Aug 13, 2026
glibc only grew the copy_file_range() and memfd_create() wrappers in 2.27, and CPython compiles os.copy_file_range() and os.memfd_create() out when the libc it is built against lacks them. We worked around that by forcing the configure checks on and weak linking the wrappers, which kept the functions out of the os module whenever the runtime glibc was older than 2.27, even on kernels implementing the syscalls. Backport python/cpython#155520 instead, which calls the wrappers when they exist and issues the raw syscalls when they don't, so both functions work on any sufficiently new kernel regardless of the glibc in use. The UAPI header overlay already provides the __NR_ constants and the MFD_ flags for all glibc targets. A single patch covers 3.10 through 3.15, so the weak linking patches and the 3.10 specific configure patch go away. The distribution tests now assert that both functions are always present on Linux GNU targets instead of tying their availability to the runtime libc. Signed-off-by: Daan De Meyer <daan@amutable.com>
This was referenced Aug 13, 2026
Closed
Closed
mbeijen
pushed a commit
to mbeijen/cpython
that referenced
this pull request
Aug 14, 2026
…te (python#155520) glibc only grew copy_file_range() and memfd_create() in 2.27, and we compile the os functions out when the libc we build against doesn't have them. That loses them for good in a redistributable built against an older glibc, such as the python-build-standalone builds targeting glibc 2.17, even when the kernel it runs on implements the syscalls. Keep calling the libc wrappers when they are available, so we don't lose their symbol versioning and _FORTIFY_SOURCE checks, and issue the syscall directly when they aren't. If the syscall number is missing as well, the functions are still left out. pidfd_open() and pidfd_getfd() already use raw syscalls, so nothing changes for them. Include <sys/syscall.h> whenever it exists rather than only when the getrandom() syscall was detected, since __NR_* is now needed for more than getrandom(). Signed-off-by: Daan De Meyer <daan@amutable.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

glibc only grew copy_file_range() and memfd_create() in 2.27, and we compile the os functions out when the libc we build against doesn't have them. That loses them for good in a redistributable built against an older glibc, such as the python-build-standalone builds targeting glibc 2.17, even when the kernel it runs on implements the syscalls.
Keep calling the libc wrappers when they are available, so we don't lose their symbol versioning and _FORTIFY_SOURCE checks, and issue the syscall directly when they aren't. If the syscall number is missing as well, the functions are still left out. pidfd_open() and pidfd_getfd() already use raw syscalls, so nothing changes for them.
Include <sys/syscall.h> whenever it exists rather than only when the getrandom() syscall was detected, since _NR* is now needed for more than getrandom().