From 42a78a1aae19f855b049462d7714cd1f07ca12e4 Mon Sep 17 00:00:00 2001 From: Fafa Kitten Date: Tue, 30 Sep 2025 01:42:57 -0500 Subject: [PATCH] meson: detect `memfd_create()` and `getrandom()` from headers, not system libraries When compiling Mesa on Android targeting Android, under some conditions `memfd_create()` and `getrandom()` are detected as available when they are not, so they should not be assumed to be available unless they are detected by Meson as available in the appropriate header passed in the `prefix` argument to Meson's `has_function()` method. `memfd_create()` is not available unless the target Android API level is 30 (Android 11) or higher and the define `_GNU_SOURCE` (which in turn sets the define `__USE_GNU`) is set, and Mesa does set `_GNU_SOURCE`, so by setting `args: pre_args` in the appropriate call to `has_function()` (which causes `-D_GNU_SOURCE` to be added to the arguments used by Meson to check the header only if it was detected as necessary for `pre_args` in the earlier condition), `memfd_create()` will be correctly detected as available when targeting (only) Android 11 or newer (and other operating systems that support `memfd_create()`) after this PR, and `getrandom()` is not available unless the target Android API level is 28 (Android 9) or higher, so `getrandom()` will be detected as available when targeting (only) Android 9 or newer (and other operating systems that support `getrandom()`) after this PR. Related information: https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/libc/include/sys/mman.h#186 https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/libc/include/sys/random.h#55 https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/libc/include/sys/cdefs.h#182 https://gitlab.freedesktop.org/mesa/mesa/-/blob/927f65caf359a2e0dda87dd5167fe18d153a9a32/meson.build#L1074 https://github.com/mesonbuild/meson/blob/cab3b67cfe04d0e06d4e7c2f50fb4f99cd0dd7eb/docs/markdown/Compiler-properties.md#does-a-function-exist Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13566 Part-of: --- meson.build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 4d0cf1714f2..dab44ad8057 100644 --- a/meson.build +++ b/meson.build @@ -1400,11 +1400,11 @@ endforeach functions_to_detect = { 'strtof': '', 'mkostemp': '', - 'memfd_create': '', + 'memfd_create': '#include ', 'random_r': '', 'flock': '', 'strtok_r': '', - 'getrandom': '', + 'getrandom': '#include ', 'qsort_s': '', 'posix_fallocate': '', 'secure_getenv': '', @@ -1412,7 +1412,7 @@ functions_to_detect = { } foreach f, prefix: functions_to_detect - if cc.has_function(f, prefix: prefix) + if cc.has_function(f, args: pre_args, prefix: prefix) pre_args += '-DHAVE_@0@'.format(f.to_upper()) endif endforeach