iOS and Apple Silicon host support
Subsystems (3)
v7 cover iOS and Apple Silicon host support
These set of changes brings QEMU TCG to iOS devices and future Apple Silicon devices. They were originally developed last year and have been working in the UTM app. Recently, we ported the changes to master, re-wrote a lot of the build script changes for meson, and broke up the patches into more distinct units.
The bulk of the changes allow for cross-compiling for both iOS and macOS running Apple Silicon and adds feature detection for parts of QEMU that are not compatible with iOS.
Since v7:
* Removed libucontext (will be submitted in another patchset)
* Removed slirp build flags update (superseded by subproject patchset)
* Reworked all patches to use feature detection instead of #ifdef CONFIG_IOS
* Added feature detection for CoreAudio
* Fix various cross compiling issues on macOS
Since v6:
* Dropped the Apple Silicon JIT support patch (superseded by another patchset)
* Changed libucontext to be a Meson subproject
* Cache availablity check for preadv/pwritev on macOS 11 and iOS 14
Since v5:
* Fixed some more instances of QAPI define of CONFIG_HOST_BLOCK_DEVICE
* Fixed libucontext build on newer version of GCC
Since v4:
* Updated QAPI schema for CONFIG_HOST_BLOCK_DEVICE
* Updated maintainers file for iOS host support
* Moved system() changes to osdep.h
* Fixed typo in libucontext meson.build change
Since v3:
* Moved mirror JIT support to a different patch set.
* Removed dependency on pthread_jit_write_protect_np because it was redundent and also crashes if called on a non-jailbroken iOS device.
* Removed --enable-cross-compile option
* Fixed checkpatch errors
* Fixed iOS build on master due to new test recently added which calls system()
Since v2:
* Changed getting mirror pointer from a macro to inline functions
* Split constification of TCG code pointers to separate patch
* Removed slirp updates (will send future patch once slirp changes are in)
* Removed shared library patch (will send future patch)
-j
Joelle van Dyne (11):
block: feature detection for host block support
configure: cross-compiling with empty cross_prefix
configure: check for sys/disk.h
slirp: feature detection for smbd
osdep: build with non-working system() function
darwin: remove redundant dependency declaration
darwin: fix cross-compiling for Darwin
configure: cross compile should use x86_64 cpu_family
block: check availablity for preadv/pwritev on mac
darwin: detect CoreAudio for build
darwin: remove 64-bit build detection on 32-bit OS
configure | 125 ++++++++++++++++++++++++++++++++++++------- meson.build | 4 +- qapi/block-core.json | 10 ++-- include/qemu/osdep.h | 11 ++++ block.c | 2 +- block/file-posix.c | 68 ++++++++++++++++++----- net/slirp.c | 16 +++--- 7 files changed, 192 insertions(+), 44 deletions(-)
Signature · 1 line
2.28.0
PATCH v7 1/11 block: feature detection for host block support
On Darwin (iOS), there are no system level APIs for directly accessing host block devices. We detect this at configure time.
--- configure | 13 +++++++++++++ meson.build | 2 +- qapi/block-core.json | 10 +++++++--- block/file-posix.c | 33 ++++++++++++++++++++++----------- 4 files changed, 43 insertions(+), 15 deletions(-)
configure +13 -0
@@ -5283,6 +5283,16 @@ but not implemented on your system" fi fi +########################################## +# check for host block device +# assume always true for non-Darwin hosts + +if ! test "$darwin" == "yes" || check_include "IOKit/storage/IOMedia.h" ; then + have_host_block_device=yes +else + have_host_block_device=no +fi + ########################################## # End of CC checks # After here, no more $cc or $ld runs
@@ -5513,6 +5523,9 @@ echo "GIT_UPDATE=$git_update" >> $config_host_mak echo "ARCH=$ARCH" >> $config_host_mak +if test "$have_host_block_device" = "yes" ; then + echo "HAVE_HOST_BLOCK_DEVICE=y" >> $config_host_mak +fi if test "$debug_tcg" = "yes" ; then echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak fi
meson.build +1 -1
@@ -180,7 +180,7 @@ if targetos == 'windows' include_directories: include_directories('.')) elif targetos == 'darwin' coref = dependency('appleframeworks', modules: 'CoreFoundation') - iokit = dependency('appleframeworks', modules: 'IOKit') + iokit = dependency('appleframeworks', modules: 'IOKit', required: 'HAVE_HOST_BLOCK_DEVICE' in config_host) elif targetos == 'sunos' socket = [cc.find_library('socket'), cc.find_library('nsl'),
qapi/block-core.json +7 -3
@@ -959,7 +959,8 @@ 'discriminator': 'driver', 'data': { 'file': 'BlockStatsSpecificFile', - 'host_device': 'BlockStatsSpecificFile', + 'host_device': { 'type': 'BlockStatsSpecificFile', + 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'nvme': 'BlockStatsSpecificNvme' } } ##
@@ -2827,7 +2828,9 @@ { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps', - 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', + 'gluster', 'host_cdrom', + {'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, + 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
@@ -4012,7 +4015,8 @@ 'ftps': 'BlockdevOptionsCurlFtps', 'gluster': 'BlockdevOptionsGluster', 'host_cdrom': 'BlockdevOptionsFile', - 'host_device':'BlockdevOptionsFile', + 'host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'http': 'BlockdevOptionsCurlHttp', 'https': 'BlockdevOptionsCurlHttps', 'iscsi': 'BlockdevOptionsIscsi',
block/file-posix.c +22 -11
@@ -42,6 +42,8 @@#include "scsi/constants.h" #if defined(__APPLE__) && (__MACH__) +#include <sys/ioctl.h> +#if defined(HAVE_HOST_BLOCK_DEVICE )#include <paths.h> #include <sys/param.h> #include <IOKit/IOKitLib.h>
@@ -52,6 +54,7 @@//#include <IOKit/storage/IOCDTypes.h> #include <IOKit/storage/IODVDMedia.h> #include <CoreFoundation/CoreFoundation.h> +#endif /* defined(HAVE_HOST_BLOCK_DEVICE) */ #endif #ifdef __sun__
@@ -181,7 +184,17 @@ typedef struct BDRVRawReopenState {bool check_cache_dropped; } BDRVRawReopenState; -static int fd_open (BlockDriverState *bs); +static int fd_open (BlockDriverState *bs) +{ +BDRVRawState *s = bs->opaque; + +/* this is just to ensure s->fd is sane (its called by io ops) */ +if (s->fd >=0 ) { +return 0 ; + } +return -EIO ; +} +static int64_t raw_getlength (BlockDriverState *bs); typedef struct RawPosixAIOData {
@@ -3014,6 +3027,7 @@ static BlockStatsSpecific *raw_get_specific_stats(BlockDriverState *bs)return stats; } +#if defined(HAVE_HOST_BLOCK_DEVICE )static BlockStatsSpecific *hdev_get_specific_stats (BlockDriverState *bs) {BlockStatsSpecific *stats =g_new (BlockStatsSpecific,1 );
@@ -3023,6 +3037,7 @@ static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)return stats; } +#endif /* HAVE_HOST_BLOCK_DEVICE */ static QemuOptsList raw_create_opts = { .name ="raw-create-opts" ,
@@ -3247,6 +3262,8 @@ BlockDriver bdrv_file = {/***********************************************/ /* host device */ +#if defined(HAVE_HOST_BLOCK_DEVICE ) +#if defined(__APPLE__) && defined(__MACH__)static kern_return_t GetBSDPath (io_iterator_t mediaIterator,char *bsdPath,CFIndex maxPathSize,int flags);
@@ -3539,16 +3556,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) }#endif /* linux */ -static int fd_open (BlockDriverState *bs) -{ -BDRVRawState *s = bs->opaque; - -/* this is just to ensure s->fd is sane (its called by io ops) */ -if (s->fd >=0 ) -return 0 ; -return -EIO ; -} - static coroutine_fn inthdev_co_pdiscard (BlockDriverState *bs,int64_t offset,int bytes) {
@@ -3872,6 +3879,8 @@ static BlockDriver bdrv_host_cdrom = { };#endif /* __FreeBSD__ */ +#endif /* HAVE_HOST_BLOCK_DEVICE */ +static void bdrv_file_init (void ) {/*
@@ -3879,6 +3888,7 @@ static void bdrv_file_init(void)* registered last will get probed first. */ bdrv_register (&bdrv_file); +#if defined(HAVE_HOST_BLOCK_DEVICE )bdrv_register (&bdrv_host_device);#ifdef __linux__bdrv_register (&bdrv_host_cdrom);
@@ -3886,6 +3896,7 @@ static void bdrv_file_init(void)#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)bdrv_register (&bdrv_host_cdrom);#endif +#endif /* HAVE_HOST_BLOCK_DEVICE */ }block_init (bdrv_file_init);
Signature · 1 line
2.28.0
PATCH v7 2/11 configure: cross-compiling with empty cross_prefix
In reply to Joelle van DyneThe iOS toolchain does not use the host prefix naming convention. So we need to enable cross-compile options while allowing the PREFIX to be blank.
--- configure | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
configure +4 -2
@@ -238,6 +238,7 @@ cpu="" iasl="iasl" interp_prefix="/usr/gnemul/qemu-%M" static="no" +cross_compile="no" cross_prefix="" audio_drv_list="" block_drv_rw_whitelist=""
@@ -469,6 +470,7 @@ for opt do optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') case "$opt" in --cross-prefix=*) cross_prefix="$optarg" + cross_compile="yes" ;; --cc=*) CC="$optarg" ;;
@@ -1696,7 +1698,7 @@ $(echo Deprecated targets: $deprecated_targets_list | \ --target-list-exclude=LIST exclude a set of targets from the default target-list Advanced options (experts only): - --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix] + --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix] --cc=CC use C compiler CC [$cc] --iasl=IASL use ACPI compiler IASL [$iasl] --host-cc=CC use C compiler CC [$host_cc] for code run at
@@ -6403,7 +6405,7 @@ if has $sdl2_config; then fi echo "strip = [$(meson_quote $strip)]" >> $cross echo "windres = [$(meson_quote $windres)]" >> $cross -if test -n "$cross_prefix"; then +if test "$cross_compile" = "yes"; then cross_arg="--cross-file config-meson.cross" echo "[host_machine]" >> $cross if test "$mingw32" = "yes" ; then
Signature · 1 line
2.28.0
PATCH v7 3/11 configure: check for sys/disk.h
In reply to Joelle van DyneSome BSD platforms do not have this header.
--- configure | 9 +++++++++ block.c | 2 +- block/file-posix.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-)
configure +9 -0
@@ -5295,6 +5295,12 @@ else have_host_block_device=no fi +if check_include "sys/disk.h" ; then + sys_disk_h=yes +else + sys_disk_h=no +fi + ########################################## # End of CC checks # After here, no more $cc or $ld runs
@@ -5528,6 +5534,9 @@ echo "ARCH=$ARCH" >> $config_host_mak if test "$have_host_block_device" = "yes" ; then echo "HAVE_HOST_BLOCK_DEVICE=y" >> $config_host_mak fi +if test "$sys_disk_h" = "yes" ; then + echo "HAVE_SYS_DISK_H=y" >> $config_host_mak +fi if test "$debug_tcg" = "yes" ; then echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak fi
block.c +1 -1
@@ -54,7 +54,7 @@#ifdef CONFIG_BSD #include <sys/ioctl.h> #include <sys/queue.h> -#ifndef __DragonFly__ +#if defined(HAVE_SYS_DISK_H )#include <sys/disk.h> #endif #endif
block/file-posix.c +1 -1
@@ -2320,7 +2320,7 @@ again: } if (size == 0)#endif -#if defined(__APPLE__) && defined(__MACH__) +#if defined(HAVE_SYS_DISK_H ) && defined(__APPLE__) && defined(__MACH__) {uint64_t sectors =0 ;uint32_t sector_size =0 ;
Signature · 1 line
2.28.0
Re: [PATCH v7 03/11] configure: check for sys/disk.h
Quoted 28 lines · Joelle van Dyne
Some BSD platforms do not have this header.
Signed-off-by Joelle van Dyne <[email protected]>--- configure | 9 +++++++++ block.c | 2 +- block/file-posix.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-)configure +6
-0@@ -5295,6 +5295,12 @@ else have_host_block_device=no fi +if check_include "sys/disk.h" ; then + sys_disk_h=yes +else + sys_disk_h=no +fi + ########################################## # End of CC checks # After here, no more $cc or $ld runs
configure echo "ARCH=$ARCH" >> $config_host_mak · line 5542
Quoted 9 lines
configure +3
-0@@ -5528,6 +5534,9 @@ echo "ARCH=$ARCH" >> $config_host_mak if test "$have_host_block_device" = "yes" ; then echo "HAVE_HOST_BLOCK_DEVICE=y" >> $config_host_mak fi +if test "$sys_disk_h" = "yes" ; then + echo "HAVE_SYS_DISK_H=y" >> $config_host_mak +fi if test "$debug_tcg" = "yes" ; then echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak fi
We should do this check in meson.build, where it is a one-liner:
config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))
(compare the existing HAVE_PTY_H etc).
thanks
-- PMM
PATCH v7 4/11 slirp: feature detection for smbd
In reply to Joelle van DyneReplace Windows specific macro with a more generic feature detection macro. Allows slirp smb feature to be disabled manually as well.
--- configure | 22 +++++++++++++++++++++- meson.build | 2 +- net/slirp.c | 16 ++++++++-------- 3 files changed, 30 insertions(+), 10 deletions(-)
configure +21 -1
@@ -464,6 +464,7 @@ fuse="auto" fuse_lseek="auto" malloc_trim="auto" +slirp_smbd="auto" # parse CC options second for opt do
@@ -845,7 +846,18 @@ do fi done +# Check for smbd dupport : ${smbd=${SMBD-/usr/sbin/smbd}} +if test "$slirp_smbd" != "no" ; then + if test "$mingw32" = "yes" ; then + if test "$slirp_smbd" = "yes" ; then + error_exit "Host smbd not supported on this platform." + fi + slirp_smbd=no + else + slirp_smbd=yes + fi +fi # Default objcc to clang if available, otherwise use CC if has clang; then
@@ -1560,6 +1572,10 @@ for opt do ;; --disable-fuse-lseek) fuse_lseek="disabled" ;; + --enable-slirp-smbd) slirp_smbd=yes + ;; + --disable-slirp-smbd) slirp_smbd=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information"
@@ -1899,6 +1915,7 @@ disabled with --disable-FEATURE, default is enabled if available libdaxctl libdaxctl support fuse FUSE block device export fuse-lseek SEEK_HOLE/SEEK_DATA support for FUSE exports + slirp-smbd use smbd (at path --smbd=*) in slirp networking NOTE: The object files are built at the place where configure is launched EOF
@@ -5595,7 +5612,10 @@ fi if test "$guest_agent" = "yes" ; then echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak fi -echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak +if test "$slirp_smbd" = "yes" ; then + echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak + echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak +fi if test "$vde" = "yes" ; then echo "CONFIG_VDE=y" >> $config_host_mak echo "VDE_LIBS=$vde_libs" >> $config_host_mak
meson.build +1 -1
@@ -2331,7 +2331,7 @@ summary_info += {'sphinx-build': sphinx_build.found()} summary_info += {'genisoimage': config_host['GENISOIMAGE']} # TODO: add back version summary_info += {'slirp support': slirp_opt == 'disabled' ? false : slirp_opt} -if slirp_opt != 'disabled' +if slirp_opt != 'disabled' and 'HAVE_HOST_SMBD' in config_host summary_info += {'smbd': config_host['CONFIG_SMBD_COMMAND']} endif summary_info += {'module support': config_host.has_key('CONFIG_MODULES')}
net/slirp.c +8 -8
@@ -27,7 +27,7 @@#include "net/slirp.h" -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD )#include <pwd.h> #include <sys/wait.h> #endif
@@ -90,7 +90,7 @@ typedef struct SlirpState {Slirp *slirp;Notifier poll_notifier;Notifier exit_notifier; -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD )gchar *smb_dir;#endif GSList *fwd;
@@ -103,7 +103,7 @@ static QTAILQ_HEAD(, SlirpState) slirp_stacks =static int slirp_hostfwd (SlirpState *s,const char *redir_str,Error **errp);static int slirp_guestfwd (SlirpState *s,const char *config_str,Error **errp); -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD )static int slirp_smb (SlirpState *s,const char *exported_dir,struct in_addr vserver_addr,Error **errp);static void slirp_smb_cleanup (SlirpState *s);
@@ -367,7 +367,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,struct in6_addr ip6_prefix;struct in6_addr ip6_host;struct in6_addr ip6_dns; -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD )struct in_addr smbsrv = { .s_addr =0 };#endif NetClientState *nc;
@@ -477,7 +477,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,return -1 ; } -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD )if (vsmbserver && !inet_aton (vsmbserver, &smbsrv)) {error_setg (errp,"Failed to parse SMB address" );return -1 ;
@@ -592,7 +592,7 @@ static int net_slirp_init(NetClientState *peer, const char *model, } } } -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD )if (smb_export) {if (slirp_smb (s, smb_export, smbsrv, errp) <0 ) { goto error;
@@ -784,7 +784,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict) } -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD )/* automatic user mode samba server configuration */ static void slirp_smb_cleanup (SlirpState *s)
@@ -899,7 +899,7 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, return 0; } -#endif /* !defined(_WIN32) */ +#endif /* defined(CONFIG_SLIRP_SMBD) */ static int guestfwd_can_read (void *opaque) {
Signature · 1 line
2.28.0
Re: [PATCH v7 04/11] slirp: feature detection for smbd
configure fi · line 5618
Quoted 12 lines · Joelle van Dyne
Replace Windows specific macro with a more generic feature detection macro. Allows slirp smb feature to be disabled manually as well.
Signed-off-by Joelle van Dyne <[email protected]>---
configure +4
-0+if test "$slirp_smbd" = "yes" ; then + echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak + echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak +fi
This sets "CONFIG_SLIRP_SMBD" and "CONFIG_SMBD_COMMAND"...
meson.build summary_info += {'sphinx-build': sphinx_build.found()} · line 2334
Quoted 13 lines
if test "$vde" = "yes" ; then
echo "CONFIG_VDE=y" >> $config_host_mak
echo "VDE_LIBS=$vde_libs" >> $config_host_makmeson.build +1
-1@@ -2331,7 +2331,7 @@ summary_info += {'sphinx-build': sphinx_build.found()} summary_info += {'genisoimage': config_host['GENISOIMAGE']} # TODO: add back version summary_info += {'slirp support': slirp_opt == 'disabled' ? false : slirp_opt} -if slirp_opt != 'disabled' +if slirp_opt != 'disabled' and 'HAVE_HOST_SMBD' in config_host
...but this is looking for "HAVE_HOST_SMBD". Should it be something else?
meson.build summary_info += {'sphinx-build': sphinx_build.found()} · line 2337
Quoted 3 lines
meson.build +0
-0summary_info += {'smbd': config_host['CONFIG_SMBD_COMMAND']} endif summary_info += {'module support': config_host.has_key('CONFIG_MODULES')}
thanks
-- PMM
Re: [PATCH v7 04/11] slirp: feature detection for smbd
Quoted 17 lines · Peter Maydell
configure fi · line 5618
Quoted 12 lines · Joelle van Dyne
Replace Windows specific macro with a more generic feature detection macro. Allows slirp smb feature to be disabled manually as well.
Signed-off-by Joelle van Dyne <[email protected]>---
configure +4
-0+if test "$slirp_smbd" = "yes" ; then + echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak + echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak +fiThis sets "
CONFIG_SLIRP_SMBD" and "CONFIG_SMBD_COMMAND"...
Quoted 15 lines
meson.build summary_info += {'sphinx-build': sphinx_build.found()} · line 2334
Quoted 13 lines
if test "$vde" = "yes" ; then
echo "CONFIG_VDE=y" >> $config_host_mak
echo "VDE_LIBS=$vde_libs" >> $config_host_makmeson.build +1
-1@@ -2331,7 +2331,7 @@ summary_info += {'sphinx-build': sphinx_build.found()} summary_info += {'genisoimage': config_host['GENISOIMAGE']} # TODO: add back version summary_info += {'slirp support': slirp_opt == 'disabled' ? false : slirp_opt} -if slirp_opt != 'disabled' +if slirp_opt != 'disabled' and 'HAVE_HOST_SMBD' in config_host...but this is looking for "
HAVE_HOST_SMBD". Should it be something else?
Yes, it is a typo, will fix.
-j
Quoted 7 lines
meson.build summary_info += {'sphinx-build': sphinx_build.found()} · line 2337
Quoted 4 lines
meson.build +0
-0summary_info += {'smbd': config_host['CONFIG_SMBD_COMMAND']} endif summary_info += {'module support': config_host.has_key('CONFIG_MODULES')}thanks
-- PMM
PATCH v7 5/11 osdep: build with non-working system() function
In reply to Joelle van DyneBuild without error on hosts without a working system(). An assertion will trigger if system() is called.
--- configure | 19 +++++++++++++++++++ include/qemu/osdep.h | 11 +++++++++++ 2 files changed, 30 insertions(+)
configure +19 -0
@@ -5318,6 +5318,21 @@ else sys_disk_h=no fi +########################################## +# check for system() + +have_system_function=no +cat > $TMPC << EOF +#include <stdlib.h> +int main(void) { + return system(""); +} +EOF +if compile_prog "" "" ; then + have_system_function=yes +fi + + ########################################## # End of CC checks # After here, no more $cc or $ld runs
@@ -6222,6 +6237,10 @@ if test "$secret_keyring" = "yes" ; then echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak fi +if test "$have_system_function" = "yes" ; then + echo "HAVE_SYSTEM_FUNCTION=y" >> $config_host_mak +fi + echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak echo "PYTHON=$python" >> $config_host_mak
include/qemu/osdep.h +11 -0
@@ -682,4 +682,15 @@ char *qemu_get_host_name(Error **errp);*/ size_t qemu_get_host_physmem (void ); +/** +* Platforms which do not support system() gets an assertion failure. +*/ +#ifndef HAVE_SYSTEM_FUNCTION +#define system platform_does_not_support_system +static inline int platform_does_not_support_system (const char *command) +{ +assert (0 ); +} +#endif /* !HAVE_SYSTEM_FUNCTION */ +#endif
Signature · 1 line
2.28.0
Re: [PATCH v7 05/11] osdep: build with non-working system() function
Quoted 5 lines · Joelle van Dyne
Build without error on hosts without a working
system(). An assertion will trigger ifsystem()is called.Signed-off-by Joelle van Dyne <[email protected]>
configure | 19 +++++++++++++++++++
Can we do the "does system() exist?" check in meson.build ? Untested, but looking at the existing check for "does gettid() exist?" it should be two lines:
has_system = cc.has_function('system')
and then later:
config_host_data.set('HAVE_SYSTEM_FUNCTION', has_system)
include/qemu/osdep.h char *qemu_get_host_name(Error **errp); · line 694
Quoted 10 lines
include/qemu/osdep.h +10
-0+/** +* Platforms which do not support system() gets an assertion failure. +*/ +#ifndef HAVE_SYSTEM_FUNCTION +#define system platform_does_not_support_system +static inline int platform_does_not_support_system (const char *command) +{ +assert (0 ); +} +#endif /* !HAVE_SYSTEM_FUNCTION */
I think we should make this return an error code rather than assert:
errno = ENOSYS;
return -1;In particular, the arm, m68k and nios2 semihosting ABIs presented to the guest include 'SYSTEM' semihosting calls which we implement as "call system() with the string the guest hands us". On a platform without a system() function we want to return an error to the guest there, not assert.
The other possible approach would be to find all the places which want to call system() and add suitable ifdeffery to handle platforms without system:
* a win32-specific part of the guest-agent (no action needed)
* net/slirp.c (already handled by the smbd patch in this series)
* code in tests/ (5 instances)
* the 3 semihosting uses
But I think providing an always-fails system() is fine.
thanks
-- PMM
Re: [PATCH v7 05/11] osdep: build with non-working system() function
Quoted 14 lines · Peter Maydell
Quoted 5 lines · Joelle van Dyne
Build without error on hosts without a working
system(). An assertion will trigger ifsystem()is called.Signed-off-by Joelle van Dyne <[email protected]>configure | 19 +++++++++++++++++++Can we do the "does
system()exist?" check in meson.build ? Untested, but looking at the existing check for "doesgettid()exist?" it should be two lines:
Quoted 5 lines
has_system=cc.has_function('system')and then later:
config_host_data.set('HAVE_SYSTEM_FUNCTION', has_system)
...looking at how we do the HAVE_FOO_H settings, I think we can just collapse this into one line:
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system'))
thanks
-- PMM
Re: [PATCH v7 05/11] osdep: build with non-working system() function
Unfortunately, this doesn't work for iOS, which defines system() but throws a compile time error if you try to call it.
-j
Quoted 29 lines · Peter Maydell
Quoted 14 lines · Peter Maydell
Quoted 5 lines · Joelle van Dyne
Build without error on hosts without a working
system(). An assertion will trigger ifsystem()is called.Signed-off-by Joelle van Dyne <[email protected]>configure | 19 +++++++++++++++++++Can we do the "does
system()exist?" check in meson.build ? Untested, but looking at the existing check for "doesgettid()exist?" it should be two lines:Quoted 5 lines
has_system=cc.has_function('system')and then later:
config_host_data.set('HAVE_SYSTEM_FUNCTION', has_system)...looking at how we do the
HAVE_FOO_Hsettings, I think we can just collapse this into one line:
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system'))thanks
-- PMM
Re: [PATCH v7 05/11] osdep: build with non-working system() function
On Sat, 23 Jan 2021 at 03:18, Joelle van Dyne <[email protected]> wrote:
Quoted 6 lines · Peter Maydell
Quoted 3 lines
Can we do the "does
system()exist?" check in meson.build ?
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system'))Unfortunately, this doesn't work for iOS, which defines
system()but throws a compile time error if you try to call it.
That's odd -- as far as I can tell the meson implementation of has_function() does what I expected it to do, ie "try to compile and link a little program that uses the function, and see if it successfully links":
https://github.com/mesonbuild/meson/blob/39ede12aa5b27376341df85bc9ec254913f044bd/mesonbuild/compilers/mixins/clike.py#L791
There's some initial cleverness there too, so I guess some part of that must be what's tripping us up.
In any case, I think we should be doing new checks in meson.build, not configure. Paolo, what's the right way to do a meson "really compile this program and check it built" test?
thanks
-- PMM
Re: [PATCH v7 05/11] osdep: build with non-working system() function
Quoted 17 lines · Peter Maydell
On Sat, 23 Jan 2021 at 03:18, Joelle van Dyne <[email protected]> wrote:
Quoted 6 lines · Peter Maydell
Quoted 3 lines
Can we do the "does
system()exist?" check in meson.build ?
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system'))Unfortunately, this doesn't work for iOS, which defines
system()but throws a compile time error if you try to call it.That's odd -- as far as I can tell the meson implementation of
has_function()does what I expected it to do, ie "try to compile and link a little program that uses the function, and see if it successfully links":
https://github.com/mesonbuild/meson/blob/39ede12aa5b27376341df85bc9ec254913f044bd/mesonbuild/compilers/mixins/clike.py#L791
There's some initial cleverness there too, so I guess some part of that must be what's tripping us up.
Quoted 4 lines
In any case, I think we should be doing new checks in meson.build, not configure. Paolo, what's the right way to do a meson "really compile this program and check it built" test?
One possibility is that you have to specify the #include in the "prefix" argument of cc.has_function for the test to behave as the QEMU code?
If cc.has_function doesn't work, there's cc.compiles() and cc.links().
Paolo
Re: [PATCH v7 05/11] osdep: build with non-working system() function
Here's how meson does cc.has_function
https://github.com/mesonbuild/meson/blob/master/mesonbuild/compilers/mixins/clike.py#L761
Since the compiler error comes from the header file with
__attribute__((availability(ios,unavailable)))
The meson check will always pass.
cc.compiles should work though. Is there a reason why it's not used instead of all the compile_prog checks in ./configure ?
-j
Quoted 31 lines · Paolo Bonzini
Quoted 17 lines · Peter Maydell
On Sat, 23 Jan 2021 at 03:18, Joelle van Dyne <[email protected]> wrote:
Quoted 6 lines · Peter Maydell
Quoted 3 lines
Can we do the "does
system()exist?" check in meson.build ?
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system'))Unfortunately, this doesn't work for iOS, which defines
system()but throws a compile time error if you try to call it.That's odd -- as far as I can tell the meson implementation of
has_function()does what I expected it to do, ie "try to compile and link a little program that uses the function, and see if it successfully links":
https://github.com/mesonbuild/meson/blob/39ede12aa5b27376341df85bc9ec254913f044bd/mesonbuild/compilers/mixins/clike.py#L791
There's some initial cleverness there too, so I guess some part of that must be what's tripping us up.Quoted 4 lines
In any case, I think we should be doing new checks in meson.build, not configure. Paolo, what's the right way to do a meson "really compile this program and check it built" test?
One possibility is that you have to specify the #include in the "prefix" argument of cc.has_function for the test to behave as the QEMU code?
If cc.has_function doesn't work, there's
cc.compiles()andcc.links().Paolo
Re: [PATCH v7 05/11] osdep: build with non-working system() function
Quoted 4 lines · Joelle van Dyne
Here's how meson does cc.has_function
https://github.com/mesonbuild/meson/blob/master/mesonbuild/compilers/mixins/clike.py#L761
Quoted 8 lines
Since the compiler error comes from the header file with
__attribute__((availability(ios,unavailable)))
The meson check will always pass.
cc.compiles should work though. Is there a reason why it's not used instead of all the
compile_progchecks in ./configure ?
Just because the Meson build system is only a few months old.
Alternatively:
# If we have any includes in the prefix supplied by the user,
assume
# that the user wants us to use the symbol prototype defined in
those
# includes. If not, then try to do the Autoconf-style check with
# a dummy prototype definition of our own.so adding a "prefix: '#include <stdlib.h>'" to cc.has_function should work too.
Paolo
Re: [PATCH v7 05/11] osdep: build with non-working system() function
In reply to Joelle van DyneQuoted 2 lines · Joelle van Dyne
cc.compiles should work though. Is there a reason why it's not used instead of all the
compile_progchecks in ./configure ?
As Paolo says, that's because our transition to Meson is pretty recent. We put in the minimum necessary to move all our old makefiles over to meson.build, but left the bulk of the old configure script in place initially. Since then we've been gradually converting tests in configure to meson.build tests, but configure's a big script and it's taking us a while. In the meantime we're preferring new tests to be done in meson.
thanks
-- PMM
PATCH v7 6/11 darwin: remove redundant dependency declaration
In reply to Joelle van DyneMeson will find CoreFoundation, IOKit, and Cocoa as needed.
--- configure | 1 - 1 file changed, 1 deletion(-)
configure +0 -1
@@ -781,7 +781,6 @@ Darwin) fi audio_drv_list="coreaudio try-sdl" audio_possible_drivers="coreaudio sdl" - QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS" # Disable attempts to use ObjectiveC features in os/object.h since they # won't work when we're compiling with gcc as a C compiler. QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
Signature · 1 line
2.28.0
Re: [PATCH v7 06/11] darwin: remove redundant dependency declaration
Quoted 13 lines · Joelle van Dyne
Meson will find CoreFoundation, IOKit, and Cocoa as needed.
Signed-off-by Joelle van Dyne <[email protected]>--- configure | 1 - 1 file changed, 1 deletion(-)configure +0
-0
configure Darwin)
Quoted 8 lines
configure +0
-2@@ -781,7 +781,6 @@ Darwin) fi audio_drv_list="coreaudio try-sdl" audio_possible_drivers="coreaudio sdl" - QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS" # Disable attempts to use ObjectiveC features in os/object.h since they # won't work when we're compiling with gcc as a C compiler. QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS" --
I notice that configure also sets
coreaudio_libs="-framework CoreAudio"
but that looks like it's something that hasn't yet been moved into meson.build, so we can't remove it yet.
thanks
-- PMM
PATCH v7 7/11 darwin: fix cross-compiling for Darwin
In reply to Joelle van DyneAdd objc to the Meson cross file as well as detection of Darwin.
--- configure | 4 ++++ 1 file changed, 4 insertions(+)
configure +4 -0
@@ -6443,6 +6443,7 @@ echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross echo "[binaries]" >> $cross echo "c = [$(meson_quote $cc)]" >> $cross test -n "$cxx" && echo "cpp = [$(meson_quote $cxx)]" >> $cross +test -n "$objcc" && echo "objc = [$(meson_quote $objcc)]" >> $cross echo "ar = [$(meson_quote $ar)]" >> $cross echo "nm = [$(meson_quote $nm)]" >> $cross echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
@@ -6461,6 +6462,9 @@ if test "$cross_compile" = "yes"; then if test "$linux" = "yes" ; then echo "system = 'linux'" >> $cross fi + if test "$darwin" = "yes" ; then + echo "system = 'darwin'" >> $cross + fi case "$ARCH" in i386|x86_64) echo "cpu_family = 'x86'" >> $cross
Signature · 1 line
2.28.0
Re: [PATCH v7 07/11] darwin: fix cross-compiling for Darwin
Quoted 4 lines · Joelle van Dyne
Add objc to the Meson cross file as well as detection of Darwin.
Signed-off-by Joelle van Dyne <[email protected]>
thanks
-- PMM
PATCH v7 8/11 configure: cross compile should use x86_64 cpu_family
In reply to Joelle van Dyne--- configure | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
configure +4 -1
@@ -6466,9 +6466,12 @@ if test "$cross_compile" = "yes"; then echo "system = 'darwin'" >> $cross fi case "$ARCH" in - i386|x86_64) + i386) echo "cpu_family = 'x86'" >> $cross ;; + x86_64) + echo "cpu_family = 'x86_64'" >> $cross + ;; ppc64le) echo "cpu_family = 'ppc64'" >> $cross ;;
Signature · 1 line
2.28.0
PATCH v7 9/11 block: check availablity for preadv/pwritev on mac
In reply to Joelle van DynemacOS 11/iOS 14 added preadv/pwritev APIs. Due to weak linking, configure will succeed with CONFIG_PREADV even when targeting a lower OS version. We therefore need to check at run time if we can actually use these APIs.
--- block/file-posix.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
block/file-posix.c +33 -0
@@ -1386,17 +1386,50 @@ static int handle_aiocb_flush(void *opaque)#ifdef CONFIG_PREADV static bool preadv_present = true; +static bool preadv_checked;static ssize_t qemu_preadv (int fd,const struct iovec *iov,int nr_iov,off_t offset) { +#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */ +if (unlikely (!preadv_checked)) { + if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) { + preadv_checked = true; + }else { + preadv_present = false; +return -ENOSYS ; + } + } +/* Now we suppress the availability warning since we use the cached check */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability-new" +return preadv (fd, iov, nr_iov, offset); +#pragma clang diagnostic pop +#else /* CONFIG_DARWIN */ return preadv (fd, iov, nr_iov, offset); +#endif }static ssize_t qemu_pwritev (int fd,const struct iovec *iov,int nr_iov,off_t offset) { +#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */ +if (unlikely (!preadv_checked)) { + if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) { + preadv_checked = true; + }else { + preadv_present = false; +return -ENOSYS ; + } + } +/* Now we suppress the availability warning since we use the cached check */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability-new" +return pwritev (fd, iov, nr_iov, offset); +#pragma clang diagnostic pop +#else /* CONFIG_DARWIN */ return pwritev (fd, iov, nr_iov, offset); +#endif }#else
Signature · 1 line
2.28.0
PATCH v7 10/11 darwin: detect CoreAudio for build
In reply to Joelle van DyneOn iOS there is no CoreAudio, so we should not assume Darwin always has it.
--- configure | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
configure +33 -2
@@ -319,6 +319,7 @@ fdt="auto" netmap="no" sdl="auto" sdl_image="auto" +coreaudio="auto" virtiofsd="auto" virtfs="auto" libudev="auto"
@@ -779,7 +780,7 @@ Darwin) QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS" QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS" fi - audio_drv_list="coreaudio try-sdl" + audio_drv_list="try-coreaudio try-sdl" audio_possible_drivers="coreaudio sdl" # Disable attempts to use ObjectiveC features in os/object.h since they # won't work when we're compiling with gcc as a C compiler.
@@ -3162,6 +3163,24 @@ EOF fi fi +########################################## +# detect CoreAudio +if test "$coreaudio" != "no" ; then + coreaudio_libs="-framework CoreAudio" + cat > $TMPC << EOF +#include <CoreAudio/CoreAudio.h> +int main(void) +{ + return (int)AudioGetCurrentHostTime(); +} +EOF + if compile_prog "" "$coreaudio_libs" ; then + coreaudio=yes + else + coreaudio=no + fi +fi + ########################################## # Sound support libraries probe
@@ -3218,8 +3237,20 @@ for drv in $audio_drv_list; do fi ;; - coreaudio) + coreaudio | try-coreaudio) + if test "$coreaudio" = "no"; then + if test "$drv" = "try-coreaudio"; then + audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-coreaudio//') + else + error_exit "$drv check failed" \ + "Make sure to have the $drv is available." + fi + else coreaudio_libs="-framework CoreAudio" + if test "$drv" = "try-coreaudio"; then + audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-coreaudio/coreaudio/') + fi + fi ;; dsound)
Signature · 1 line
2.28.0
PATCH v7 11/11 darwin: remove 64-bit build detection on 32-bit OS
In reply to Joelle van DyneA workaround added in early days of 64-bit OSX forced x86_64 if the host machine had 64-bit support. This creates issues when cross- compiling for ARM64. Additionally, the user can always use --cpu=* to manually set the host CPU and therefore this workaround should be removed.
--- configure | 11 ----------- 1 file changed, 11 deletions(-)
configure +0 -11
@@ -626,13 +626,6 @@ fi # the correct CPU with the --cpu option. case $targetos in Darwin) - # on Leopard most of the system is 32-bit, so we have to ask the kernel if we can - # run 64-bit userspace code. - # If the user didn't specify a CPU explicitly and the kernel says this is - # 64 bit hw, then assume x86_64. Otherwise fall through to the usual detection code. - if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then - cpu="x86_64" - fi HOST_DSOSUF=".dylib" ;; SunOS)
@@ -776,10 +769,6 @@ OpenBSD) Darwin) bsd="yes" darwin="yes" - if [ "$cpu" = "x86_64" ] ; then - QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS" - QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS" - fi audio_drv_list="try-coreaudio try-sdl" audio_possible_drivers="coreaudio sdl" # Disable attempts to use ObjectiveC features in os/object.h since they
Signature · 1 line
2.28.0
Re: [PATCH v7 11/11] darwin: remove 64-bit build detection on 32-bit OS
Quoted 20 lines · Joelle van Dyne
A workaround added in early days of 64-bit OSX forced
x86_64if the host machine had 64-bit support. This creates issues when cross- compiling for ARM64. Additionally, the user can always use --cpu=* to manually set the host CPU and therefore this workaround should be removed.Signed-off-by Joelle van Dyne <[email protected]>--- configure | 11 ----------- 1 file changed, 11 deletions(-)configure +0
-0@@ -626,13 +626,6 @@ fi # the correct CPU with the --cpu option. case $targetos in Darwin)
configure fi · line 631
Quoted 10 lines
configure +0
-7- # on Leopard most of the system is 32-bit, so we have to ask the kernel if we can - # run 64-bit userspace code. - # If the user didn't specify a CPU explicitly and the kernel says this is - # 64 bit hw, then assume x86_64. Otherwise fall through to the usual detection code. - if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then - cpu="x86_64" - fi HOST_DSOSUF=".dylib" ;; SunOS)
I was just thinking the other day that we could remove this hack...
thanks
-- PMM