meson: Use osdep_prefix for strchrnul()
cover meson: Use osdep_prefix for strchrnul()
macOS SDK may have the symbol of strchrnul(), but it is actually available only on macOS 15.4 or later and that fact is codified in string.h. Include the header file using osdep_prefix to check if the function is available on the deployment target.
---
Akihiko Odaki (4):
meson: Use has_header_symbol() to check getcpu()
meson: Remove CONFIG_STATX and CONFIG_STATX_MNT_ID
meson: Share common C source prefixes
meson: Use osdep_prefix for strchrnul()
meson.build | 80 ++++++++++++++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 46 deletions(-)
---
base-commit: 1da8f3a3c53b604edfe0d55e475102640490549e
change-id: 20250423-buildsys-84d2feefca6b
Best regards,
Signature · 1 line
Akihiko Odaki <[email protected]>
PATCH 1/4 meson: Use has_header_symbol() to check getcpu()
The use of gnu_source_prefix in the detection of getcpu() was ineffective because the header file that declares getcpu() when _GNU_SOURCE is defined was not included. Pass sched.h to has_header_symbol() so that the existence of the declaration will be properly checked.
--- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
meson.build +2 -1
@@ -2635,7 +2635,6 @@ config_host_data.set('CONFIG_CLOCK_ADJTIME', cc.has_function('clock_adjtime')) config_host_data.set('CONFIG_DUP3', cc.has_function('dup3')) config_host_data.set('CONFIG_FALLOCATE', cc.has_function('fallocate')) config_host_data.set('CONFIG_POSIX_FALLOCATE', cc.has_function('posix_fallocate')) -config_host_data.set('CONFIG_GETCPU', cc.has_function('getcpu', prefix: gnu_source_prefix)) config_host_data.set('CONFIG_SCHED_GETCPU', cc.has_function('sched_getcpu', prefix: '#include <sched.h>')) # Note that we need to specify prefix: here to avoid incorrectly # thinking that Windows has posix_memalign()
@@ -2713,6 +2712,8 @@ config_host_data.set('CONFIG_FALLOCATE_ZERO_RANGE', config_host_data.set('CONFIG_FIEMAP', cc.has_header('linux/fiemap.h') and cc.has_header_symbol('linux/fs.h', 'FS_IOC_FIEMAP')) +config_host_data.set('CONFIG_GETCPU', + cc.has_header_symbol('sched.h', 'getcpu', prefix: gnu_source_prefix)) config_host_data.set('CONFIG_GETRANDOM', cc.has_function('getrandom') and cc.has_header_symbol('sys/random.h', 'GRND_NONBLOCK'))
Signature · 1 line
2.49.0
Re: [PATCH 1/4] meson: Use has_header_symbol() to check getcpu()
Quoted 10 lines · Akihiko Odaki
The use of
gnu_source_prefixin the detection ofgetcpu()was ineffective because the header file that declaresgetcpu()when_GNU_SOURCEis defined was not included. Passsched.htohas_header_symbol()so that the existence of the declaration will be properly checked.Signed-off-by Akihiko Odaki <[email protected]>--- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH 2/4 meson: Remove CONFIG_STATX and CONFIG_STATX_MNT_ID
In reply to Akihiko OdakiCONFIG_STATX and CONFIG_STATX_MNT_ID are not used since commit 8ab5e8a503b5 ("virtiofsd: Remove build and docs glue").
--- meson.build | 10 ---------- 1 file changed, 10 deletions(-)
meson.build +0 -10
@@ -2191,14 +2191,6 @@ gnu_source_prefix = ''' #endif ''' -# Check whether the glibc provides STATX_BASIC_STATS - -has_statx = cc.has_header_symbol('sys/stat.h', 'STATX_BASIC_STATS', prefix: gnu_source_prefix) - -# Check whether statx() provides mount ID information - -has_statx_mnt_id = cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', prefix: gnu_source_prefix) - have_vhost_user_blk_server = get_option('vhost_user_blk_server') \ .require(host_os == 'linux', error_message: 'vhost_user_blk_server requires linux') \
@@ -2560,8 +2552,6 @@ config_host_data.set('CONFIG_CRYPTO_SM3', crypto_sm3.found()) config_host_data.set('CONFIG_HOGWEED', hogweed.found()) config_host_data.set('CONFIG_QEMU_PRIVATE_XTS', xts == 'private') config_host_data.set('CONFIG_MALLOC_TRIM', has_malloc_trim) -config_host_data.set('CONFIG_STATX', has_statx) -config_host_data.set('CONFIG_STATX_MNT_ID', has_statx_mnt_id) config_host_data.set('CONFIG_ZSTD', zstd.found()) config_host_data.set('CONFIG_QPL', qpl.found()) config_host_data.set('CONFIG_UADK', uadk.found())
Signature · 1 line
2.49.0
Re: [PATCH 2/4] meson: Remove CONFIG_STATX and CONFIG_STATX_MNT_ID
Quoted 2 lines · Akihiko Odaki
CONFIG_STATXandCONFIG_STATX_MNT_IDare not used since commit8ab5e8a503b5("virtiofsd: Remove build and docs glue").
since commit e0dc2631ec4 ("virtiofsd: Remove source"), otherwise:
Quoted 4 lines
Signed-off-by Akihiko Odaki <[email protected]>--- meson.build | 10 ---------- 1 file changed, 10 deletions(-)
PATCH 3/4 meson: Share common C source prefixes
In reply to Akihiko Odakignu_source_prefix defines _GNU_SOURCE for compiler object functions. The definition is universally available in the code base.
docs/devel/style.rst also says that the "qemu/osdep.h" header is always included, so files included in the file is also universally available in the code base.
Rename gnu_source_prefix to osdep_prefix, and add #include directives that are referred by the users of gnu_source_prefix and contained in qemu/osdep.h to safely de-duplicate #include directives.
--- meson.build | 68 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 36 deletions(-)
meson.build +32 -36
@@ -2185,10 +2185,21 @@ if not has_malloc_trim and get_option('malloc_trim').enabled() endif endif -gnu_source_prefix = ''' +osdep_prefix = ''' #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif + + #include <stddef.h> + #include <sys/types.h> + + #include <limits.h> + /* Put unistd.h before time.h as that triggers localtime_r/gmtime_r + * function availability on recentish Mingw-w64 platforms. */ + #include <unistd.h> + #include <time.h> + #include <errno.h> + #include <fcntl.h> ''' have_vhost_user_blk_server = get_option('vhost_user_blk_server') \
@@ -2703,7 +2714,7 @@ config_host_data.set('CONFIG_FIEMAP', cc.has_header('linux/fiemap.h') and cc.has_header_symbol('linux/fs.h', 'FS_IOC_FIEMAP')) config_host_data.set('CONFIG_GETCPU', - cc.has_header_symbol('sched.h', 'getcpu', prefix: gnu_source_prefix)) + cc.has_header_symbol('sched.h', 'getcpu', prefix: osdep_prefix)) config_host_data.set('CONFIG_GETRANDOM', cc.has_function('getrandom') and cc.has_header_symbol('sys/random.h', 'GRND_NONBLOCK'))
@@ -2748,8 +2759,7 @@ config_host_data.set('HAVE_UTMPX', config_host_data.set('CONFIG_EVENTFD', cc.links(''' #include <sys/eventfd.h> int main(void) { return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); }''')) -config_host_data.set('CONFIG_FDATASYNC', cc.links(gnu_source_prefix + ''' - #include <unistd.h> +config_host_data.set('CONFIG_FDATASYNC', cc.links(osdep_prefix + ''' int main(void) { #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 return fdatasync(0);
@@ -2758,10 +2768,8 @@ config_host_data.set('CONFIG_FDATASYNC', cc.links(gnu_source_prefix + ''' #endif }''')) -has_madvise = cc.links(gnu_source_prefix + ''' - #include <sys/types.h> +has_madvise = cc.links(osdep_prefix + ''' #include <sys/mman.h> - #include <stddef.h> int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }''') missing_madvise_proto = false if has_madvise
@@ -2771,21 +2779,18 @@ if has_madvise # missing-prototype case, we try again with a definitely-bogus prototype. # This will only compile if the system headers don't provide the prototype; # otherwise the conflicting prototypes will cause a compiler error. - missing_madvise_proto = cc.links(gnu_source_prefix + ''' - #include <sys/types.h> + missing_madvise_proto = cc.links(osdep_prefix + '''> #include <sys/mman.h> - #include <stddef.h> extern int madvise(int); int main(void) { return madvise(0); }''') endif config_host_data.set('CONFIG_MADVISE', has_madvise) config_host_data.set('HAVE_MADVISE_WITHOUT_PROTOTYPE', missing_madvise_proto) -config_host_data.set('CONFIG_MEMFD', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_MEMFD', cc.links(osdep_prefix + ''' #include <sys/mman.h> int main(void) { return memfd_create("foo", MFD_ALLOW_SEALING); }''')) -config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(gnu_source_prefix + ''' - #include <fcntl.h> +config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(osdep_prefix + ''' #if !defined(AT_EMPTY_PATH) # error missing definition #else
@@ -2796,13 +2801,12 @@ config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(gnu_source_prefix + ''' # i.e. errno is set and -1 is returned. That's not really how POSIX defines the # function. On the flip side, it has madvise() which is preferred anyways. if host_os != 'darwin' - config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(gnu_source_prefix + ''' + config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(osdep_prefix + ''' #include <sys/mman.h> - #include <stddef.h> int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }''')) endif -config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(osdep_prefix + ''' #include <pthread.h> static void *f(void *p) { return NULL; }
@@ -2813,7 +2817,7 @@ config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(gnu_source_pref pthread_setname_np(thread, "QEMU"); return 0; }''', dependencies: threads)) -config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links(osdep_prefix + ''' #include <pthread.h> static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
@@ -2823,7 +2827,7 @@ config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links(gnu_source_pre pthread_create(&thread, 0, f, 0); return 0; }''', dependencies: threads)) -config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', cc.links(osdep_prefix + ''' #include <pthread.h> #include <pthread_np.h>
@@ -2835,9 +2839,8 @@ config_host_data.set('CONFIG_PTHREAD_SET_NAME_NP', cc.links(gnu_source_prefix + pthread_set_name_np(thread, "QEMU"); return 0; }''', dependencies: threads)) -config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(osdep_prefix + ''' #include <pthread.h> - #include <time.h> int main(void) {
@@ -2846,7 +2849,7 @@ config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(gnu_source_pre pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); return 0; }''', dependencies: threads)) -config_host_data.set('CONFIG_PTHREAD_AFFINITY_NP', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_PTHREAD_AFFINITY_NP', cc.links(osdep_prefix + ''' #include <pthread.h> static void *f(void *p) { return NULL; }
@@ -2863,15 +2866,10 @@ config_host_data.set('CONFIG_PTHREAD_AFFINITY_NP', cc.links(gnu_source_prefix + CPU_FREE(cpuset); return 0; }''', dependencies: threads)) -config_host_data.set('CONFIG_SIGNALFD', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_SIGNALFD', cc.links(osdep_prefix + ''' #include <sys/signalfd.h> - #include <stddef.h> int main(void) { return signalfd(-1, NULL, SFD_CLOEXEC); }''')) -config_host_data.set('CONFIG_SPLICE', cc.links(gnu_source_prefix + ''' - #include <unistd.h> - #include <fcntl.h> - #include <limits.h> - +config_host_data.set('CONFIG_SPLICE', cc.links(osdep_prefix + ''' int main(void) { int len, fd = 0;
@@ -2880,13 +2878,13 @@ config_host_data.set('CONFIG_SPLICE', cc.links(gnu_source_prefix + ''' return 0; }''')) -config_host_data.set('HAVE_MLOCKALL', cc.links(gnu_source_prefix + ''' +config_host_data.set('HAVE_MLOCKALL', cc.links(osdep_prefix + ''' #include <sys/mman.h> int main(void) { return mlockall(MCL_FUTURE); }''')) -config_host_data.set('HAVE_MLOCK_ONFAULT', cc.links(gnu_source_prefix + ''' +config_host_data.set('HAVE_MLOCK_ONFAULT', cc.links(osdep_prefix + ''' #include <sys/mman.h> int main(void) { return mlockall(MCL_FUTURE | MCL_ONFAULT);
@@ -2895,7 +2893,7 @@ config_host_data.set('HAVE_MLOCK_ONFAULT', cc.links(gnu_source_prefix + ''' have_l2tpv3 = false if get_option('l2tpv3').allowed() and have_system have_l2tpv3 = cc.has_type('struct mmsghdr', - prefix: gnu_source_prefix + ''' + prefix: osdep_prefix + ''' #include <sys/socket.h> #include <linux/ip.h>''') endif
@@ -3011,13 +3009,13 @@ if has_int128_type endif endif -config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_GETAUXVAL', cc.links(osdep_prefix + ''' #include <sys/auxv.h> int main(void) { return getauxval(AT_HWCAP) == 0; }''')) -config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(gnu_source_prefix + ''' +config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(osdep_prefix + ''' #include <sys/auxv.h> int main(void) { unsigned long hwcap = 0;
@@ -3130,9 +3128,7 @@ config_host_data.set('CONFIG_MEMBARRIER', get_option('membarrier') \ .allowed()) have_afalg = get_option('crypto_afalg') \ - .require(cc.compiles(gnu_source_prefix + ''' - #include <errno.h> - #include <sys/types.h> + .require(cc.compiles(osdep_prefix + ''' #include <sys/socket.h> #include <linux/if_alg.h> int main(void) {
Signature · 1 line
2.49.0
Re: [PATCH 3/4] meson: Share common C source prefixes
Quoted 7 lines · Akihiko Odaki
gnu_source_prefixdefines_GNU_SOURCEfor compiler object functions. The definition is universally available in the code base.
docs/devel/style.rstalso says that the "qemu/osdep.h" header is always included, so files included in the file is also universally available in the code base.
Quoted 8 lines
Rename
gnu_source_prefixtoosdep_prefix, and add #include directives that are referred by the users ofgnu_source_prefixand contained inqemu/osdep.hto safely de-duplicate #include directives.Signed-off-by Akihiko Odaki <[email protected]>--- meson.build | 68 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 36 deletions(-)
PATCH 4/4 meson: Use osdep_prefix for strchrnul()
In reply to Akihiko OdakimacOS SDK may have the symbol of strchrnul(), but it is actually available only on macOS 15.4 or later and that fact is codified in string.h. Include the header file using osdep_prefix to check if the function is available on the deployment target.
--- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
meson.build +2 -1
@@ -2193,6 +2193,7 @@ osdep_prefix = ''' #include <stddef.h> #include <sys/types.h> + #include <string.h> #include <limits.h> /* Put unistd.h before time.h as that triggers localtime_r/gmtime_r * function availability on recentish Mingw-w64 platforms. */
@@ -2657,7 +2658,7 @@ config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs')) config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice) config_host_data.set('HAVE_GLIB_WITH_ALIGNED_ALLOC', glib_has_aligned_alloc) config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: util)) -config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul')) +config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix)) config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>')) if rbd.found() config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS',
Signature · 1 line
2.49.0
Quoted 9 lines · Akihiko Odaki
macOS SDK may have the symbol of
strchrnul(), but it is actually available only on macOS 15.4 or later and that fact is codified instring.h. Include the header file usingosdep_prefixto check if the function is available on the deployment target.Signed-off-by Akihiko Odaki <[email protected]>--- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Hi Paolo, Pierrick,
Quoted 5 lines · Akihiko Odaki
macOS SDK may have the symbol of
strchrnul(), but it is actually available only on macOS 15.4 or later and that fact is codified instring.h. Include the header file usingosdep_prefixto check if the function is available on the deployment target.
Quoted 7 lines
Signed-off-by Akihiko Odaki <[email protected]>---
Akihiko Odaki (4):
meson: Usehas_header_symbol()to checkgetcpu()
meson: RemoveCONFIG_STATXandCONFIG_STATX_MNT_ID
meson: Share common C source prefixes
meson: Useosdep_prefixforstrchrnul()
If you don't have objections, I'm queuing this series as a hotfix because multiple users are complaining building QEMU on macOS fails by default. Unfortunately Apple made their SDK change the week we released v10.0.0, I recommend it gets in v10.0.1 soon enough.
Thanks,
Phil.