[PATCH] meson: fix close_range detection on older glibc

Quan.Sun@windriver.com posted 1 patch 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260522201850.1342167-1-Quan.Sun@windriver.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
meson.build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] meson: fix close_range detection on older glibc
Posted by Quan.Sun@windriver.com 1 week ago
From: Quan Sun <Quan.Sun@windriver.com>

The has_function('close_range') check succeeds at link time on hosts
with kernel >= 5.9 even when glibc does not declare the function
(glibc < 2.34, e.g. AlmaLinux 8 / CentOS 8 with glibc 2.28). This
causes CONFIG_CLOSE_RANGE to be set, but compilation then fails with:

  error: implicit declaration of function 'close_range'

Fix by adding a prefix that includes <unistd.h>, so the meson check
only succeeds when the C library actually declares close_range() in
its headers.

Signed-off-by: Quan Sun <Quan.Sun@windriver.com>
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index eb07491819..e396394f4c 100644
--- a/meson.build
+++ b/meson.build
@@ -2596,7 +2596,7 @@ if host_os == 'windows'
 endif
 
 # has_function
-config_host_data.set('CONFIG_CLOSE_RANGE', cc.has_function('close_range'))
+config_host_data.set('CONFIG_CLOSE_RANGE', cc.has_function('close_range', prefix: '#include <unistd.h>'))
 config_host_data.set('CONFIG_ACCEPT4', cc.has_function('accept4'))
 config_host_data.set('CONFIG_CLOCK_ADJTIME', cc.has_function('clock_adjtime'))
 config_host_data.set('CONFIG_DUP3', cc.has_function('dup3'))
-- 
2.43.0
Re: [PATCH] meson: fix close_range detection on older glibc
Posted by Philippe Mathieu-Daudé 3 days, 2 hours ago
On 22/5/26 22:18, Quan.Sun@windriver.com wrote:
> From: Quan Sun <Quan.Sun@windriver.com>
> 
> The has_function('close_range') check succeeds at link time on hosts
> with kernel >= 5.9 even when glibc does not declare the function
> (glibc < 2.34, e.g. AlmaLinux 8 / CentOS 8 with glibc 2.28). This
> causes CONFIG_CLOSE_RANGE to be set, but compilation then fails with:
> 
>    error: implicit declaration of function 'close_range'
> 
> Fix by adding a prefix that includes <unistd.h>, so the meson check
> only succeeds when the C library actually declares close_range() in
> its headers.
> 
> Signed-off-by: Quan Sun <Quan.Sun@windriver.com>
> ---
>   meson.build | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/meson.build b/meson.build
> index eb07491819..e396394f4c 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2596,7 +2596,7 @@ if host_os == 'windows'
>   endif
>   
>   # has_function
> -config_host_data.set('CONFIG_CLOSE_RANGE', cc.has_function('close_range'))
> +config_host_data.set('CONFIG_CLOSE_RANGE', cc.has_function('close_range', prefix: '#include <unistd.h>'))
>   config_host_data.set('CONFIG_ACCEPT4', cc.has_function('accept4'))
>   config_host_data.set('CONFIG_CLOCK_ADJTIME', cc.has_function('clock_adjtime'))
>   config_host_data.set('CONFIG_DUP3', cc.has_function('dup3'))

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>