Commit 8ddb452
committed
Detect availability of PR_SET_VMA at runtime (fixes build with musl libc)
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 argument1 parent ad7d361 commit 8ddb452
File tree
4 files changed
+12
-44
lines changed- Include/internal
4 files changed
+12
-44
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
17 | 23 | | |
18 | 24 | | |
19 | | - | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| 41 | + | |
36 | 42 | | |
| 43 | + | |
37 | 44 | | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5728 | 5728 | | |
5729 | 5729 | | |
5730 | 5730 | | |
5731 | | - | |
5732 | | - | |
5733 | | - | |
5734 | | - | |
5735 | | - | |
5736 | | - | |
5737 | | - | |
5738 | | - | |
5739 | | - | |
5740 | 5731 | | |
5741 | 5732 | | |
5742 | 5733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | 227 | | |
232 | 228 | | |
233 | 229 | | |
| |||
1003 | 999 | | |
1004 | 1000 | | |
1005 | 1001 | | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | 1002 | | |
1010 | 1003 | | |
1011 | 1004 | | |
| |||
0 commit comments