gh-153400: Resolve newer libc/syscall wrappers at runtime on Linux#153398
Open
daandemeyer wants to merge 1 commit into
Open
gh-153400: Resolve newer libc/syscall wrappers at runtime on Linux#153398daandemeyer wants to merge 1 commit into
daandemeyer wants to merge 1 commit into
Conversation
0fe670a to
9a8baaa
Compare
Member
|
Sorry but this needs an issue. It is a nontrivial change. |
9a8baaa to
4d76954
Compare
picnixz
reviewed
Jul 9, 2026
4d76954 to
b7a07aa
Compare
picnixz
reviewed
Jul 9, 2026
picnixz
left a comment
Member
There was a problem hiding this comment.
A nicer error message should be emitted if we lack the functions I think rather than an unresolvable symbol error
| #elif defined(HAVE_COPY_FILE_RANGE) | ||
| # define _Py_HAVE_COPY_FILE_RANGE | ||
| # define _Py_copy_file_range copy_file_range | ||
| #endif |
Contributor
Author
There was a problem hiding this comment.
Unsure what you meant here, I've added fallbacks if the syscall numbers are not available.
9f3b446 to
4348bb9
Compare
Contributor
Author
We'll get a "function not implemented" OSError if the syscalls are not available, do you expect anything more? |
os functions like copy_file_range() are gated on a configure-time AC_CHECK_FUNCS probe and compiled out when the build libc lacks the symbol. A redistributable built against an old glibc (the python-build-standalone builds target glibc 2.17) therefore never exposes them, even when run on a newer glibc or a capable kernel. Add Modules/posixshims.h, which on Linux always exposes _Py_<func>(), resolves the libc symbol once at load time via dlsym(RTLD_DEFAULT) from a constructor, and falls back to the raw syscall when the running libc lacks the wrapper. Resolving in a constructor keeps dlsym(), which is not async-signal-safe, out of signal handlers and the fork()/exec() window. Off Linux the classic build-time HAVE_* direct calls are kept. Limit the shims to wrappers newer than the glibc 2.17 baseline, since anything at or below it is always present in the build libc: copy_file_range (glibc 2.27) memfd_create (glibc 2.27) pidfd_open (glibc 2.36) pidfd_getfd (glibc 2.36) pidfd_open() and pidfd_getfd() previously issued raw syscalls unconditionally; they now prefer the glibc wrapper when present.
4348bb9 to
566bb9f
Compare
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.
os functions like copy_file_range() are gated on a configure-time AC_CHECK_FUNCS probe and compiled out when the build libc lacks the symbol. A redistributable built against an old glibc (the python-build-standalone builds target glibc 2.17) therefore never exposes them, even when run on a newer glibc or a capable kernel.
Add Modules/posixshims.h, which on Linux always exposes Py(), resolves the libc symbol once at load time via dlsym(RTLD_DEFAULT) from a constructor, and falls back to the raw syscall when the running libc lacks the wrapper. Resolving in a constructor keeps dlsym(), which is not async-signal-safe, out of signal handlers and the fork()/exec() window. Off Linux the classic build-time HAVE_* direct calls are kept.
Limit the shims to wrappers newer than the glibc 2.17 baseline, since anything at or below it is always present in the build libc:
copy_file_range (glibc 2.27)
memfd_create (glibc 2.27)
pidfd_open (glibc 2.36)
pidfd_getfd (glibc 2.36)
pidfd_open() and pidfd_getfd() previously issued raw syscalls unconditionally; they now prefer the glibc wrapper when present.