Make QEMU installation relocatable
Subsystems (2)
cover Make QEMU installation relocatable
Right now, the installation of QEMU is not relocatable; there is a local hack in os_find_datadir() so that Windows binaries look for ROMs in the executable directory, but that has several limitations:
- it does not extend to configuration files, icons, etc.
- it does not allow changing the data directory in any way
- it does not apply to POSIX platforms
This series fixes that by making all paths within the installation prefix relative to the executable. This in practice means all paths will be relocatable, except for /etc and /var if they're moved outside the prefix.
Here is an example of relocatability; before:
$ make DESTDIR=$PWD/test install $ cd test/usr/local/bin $ ./qemu-system-ppc -L help /usr/local/share/qemu-firmware /usr/local/share/qemu
After:
$ make DESTDIR=$PWD/test install $ cd test/usr/local/bin $ ./qemu-system-ppc -L help /home/pbonzini/work/upstream/qemu/+build/test/usr/local/bin/../share/qemu-firmware /home/pbonzini/work/upstream/qemu/+build/test/usr/local/bin/../share/qemu
The main benefit of this is on Windows, as mentioned above; but it also makes behavior more consistent across platforms and allows the removal of the hack that hides the "c:/Program Files/QEMU" prefix from Meson during cross compilation.
Paolo
Paolo Bonzini (13):
fuzz: use qemu_get_exec_dir
oslib: do not call g_strdup from qemu_get_exec_dir
oslib-posix: default exec_dir to bindir
cutils: introduce get_relocated_path
oslib-posix: relocate path to /var
module: relocate path to modules
net: relocate paths to helpers and scripts
vl: relocate paths to data directories
vl: relocate path to configuration file
qemu-bridge-helper: relocate path to default ACL
qga: relocate path to default configuration and hook
ui: relocate paths to icons and translations
configure: use a platform-neutral prefix
configure | 30 ++++++++------------ include/net/net.h | 4 +-- include/qemu-common.h | 1 - include/qemu/cutils.h | 12 ++++++++ include/qemu/osdep.h | 8 ++---- include/sysemu/sysemu.h | 2 +- meson.build | 4 +-- net/tap.c | 28 ++++++++++++++----- os-posix.c | 24 ---------------- os-win32.c | 11 -------- qemu-bridge-helper.c | 9 ++++-- qga/main.c | 8 ++++-- softmmu/vl.c | 43 ++++++++++++++++++++--------- tests/qtest/fuzz/fuzz.c | 12 ++++---- ui/gtk.c | 10 +++++-- ui/sdl2.c | 9 ++++-- util/cutils.c | 61 +++++++++++++++++++++++++++++++++++++++++ util/module.c | 10 ++----- util/oslib-posix.c | 35 +++++++++++------------ util/oslib-win32.c | 14 +++++++--- 20 files changed, 205 insertions(+), 130 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/13 fuzz: use qemu_get_exec_dir
Make things consistent with how softmmu/vl.c uses os_find_datadir. Initializing the path to the executables will also be needed for get_relocatable_path to work.
--- tests/qtest/fuzz/fuzz.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qtest/fuzz/fuzz.c +2 -1
@@ -152,6 +152,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)module_call_init (MODULE_INIT_QOM );module_call_init (MODULE_INIT_LIBQOS ); +qemu_init_exec_dir (**argv); target_name =strstr (**argv,"-target-" );if (target_name) {/* The binary name specifies the target */ target_name +=strlen ("-target-" );
@@ -164,7 +165,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)* location of the executable. Using this we add exec_dir/pc-bios to * the datadirs. */ - bindir =g_path_get_dirname (**argv); + bindir =qemu_get_exec_dir (); datadir =g_build_filename (bindir,"pc-bios" ,NULL );g_free (bindir);if (g_file_test (datadir,G_FILE_TEST_IS_DIR )) {
Signature · 1 line
2.26.2
Re: [PATCH 01/13] fuzz: use qemu_get_exec_dir
Quoted 23 lines · Paolo Bonzini
Make things consistent with how
softmmu/vl.cusesos_find_datadir. Initializing the path to the executables will also be needed forget_relocatable_pathto work.Signed-off-by Paolo Bonzini <[email protected]>--- tests/qtest/fuzz/fuzz.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tests/qtest/fuzz/fuzz.c +1
-0@@ -152,6 +152,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)module_call_init (MODULE_INIT_QOM );module_call_init (MODULE_INIT_LIBQOS ); +qemu_init_exec_dir (**argv); target_name =strstr (**argv,"-target-" );if (target_name) {/* The binary name specifies the target */ target_name +=strlen ("-target-" );
tests/qtest/fuzz/fuzz.c int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) · line 171
Quoted 8 lines
tests/qtest/fuzz/fuzz.c +1
-1@@ -164,7 +165,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)* location of the executable. Using this we add exec_dir/pc-bios to * the datadirs. */ - bindir =g_path_get_dirname (**argv); + bindir =qemu_get_exec_dir (); datadir =g_build_filename (bindir,"pc-bios" ,NULL );g_free (bindir);if (g_file_test (datadir,G_FILE_TEST_IS_DIR )) {
Re: [PATCH 01/13] fuzz: use qemu_get_exec_dir
In reply to Paolo BonziniQuoted 35 lines · Paolo Bonzini
Make things consistent with how
softmmu/vl.cusesos_find_datadir. Initializing the path to the executables will also be needed forget_relocatable_pathto work.Signed-off-by Paolo Bonzini <[email protected]>--- tests/qtest/fuzz/fuzz.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tests/qtest/fuzz/fuzz.c +2
-1@@ -152,6 +152,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)module_call_init (MODULE_INIT_QOM );module_call_init (MODULE_INIT_LIBQOS ); +qemu_init_exec_dir (**argv); target_name =strstr (**argv,"-target-" );if (target_name) {/* The binary name specifies the target */ target_name +=strlen ("-target-" );@@ -164,7 +165,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)* location of the executable. Using this we add exec_dir/pc-bios to * the datadirs. */ - bindir =g_path_get_dirname (**argv); + bindir =qemu_get_exec_dir (); datadir =g_build_filename (bindir,"pc-bios" ,NULL );g_free (bindir);if (g_file_test (datadir,G_FILE_TEST_IS_DIR )) {Signature · 1 line
2.26.2
Thanks.
I think this should be applied after
[PATCH 02/13] oslib: do not call g_strdup from qemu_get_exec_dir for bisectability, since before 02/13, calling qemu_init_exec_dir twice causes an assertion failure.
Otherwise,
PATCH 2/13 oslib: do not call g_strdup from qemu_get_exec_dir
In reply to Paolo BonziniJust return the directory without requiring the caller to free it. This also removes a bogus check for NULL in os_find_datadir and module_load_one; g_strdup of a static variable cannot return NULL.
--- include/qemu/osdep.h | 8 ++------ os-posix.c | 6 +----- os-win32.c | 2 +- tests/qtest/fuzz/fuzz.c | 4 ++-- util/module.c | 7 +------ util/oslib-posix.c | 8 +++++--- util/oslib-win32.c | 12 ++++++++---- 7 files changed, 20 insertions(+), 27 deletions(-)
include/qemu/osdep.h +2 -6
@@ -590,12 +590,8 @@ char *qemu_get_local_state_pathname(const char *relative_pathname);* Try OS specific API first, if not working, parse from argv0. */ void qemu_init_exec_dir (const char *argv0); -/* Get the saved exec dir. -* -* The caller is responsible for releasing the value returned with g_free() -* after use. -*/ -char *qemu_get_exec_dir (void ); +/* Get the saved exec dir. */ +const char *qemu_get_exec_dir (void );/** * qemu_getauxval:
os-posix.c +1 -5
@@ -90,13 +90,9 @@ void os_setup_signal_handling(void)*/ char *os_find_datadir (void ) { - g_autofree char *exec_dir = NULL; g_autofree char *dir = NULL; - exec_dir =qemu_get_exec_dir (); -g_return_val_if_fail (exec_dir !=NULL ,NULL ); - - dir =g_build_filename (exec_dir,"pc-bios" ,NULL ); + dir =g_build_filename (qemu_get_exec_dir (),"pc-bios" ,NULL );if (g_file_test (dir,G_FILE_TEST_IS_DIR )) {return g_steal_pointer (&dir); }
os-win32.c +1 -1
@@ -65,7 +65,7 @@ void os_setup_early_signal_handling(void)*/ char *os_find_datadir (void ) { -return qemu_get_exec_dir (); +return g_strdup (qemu_get_exec_dir ()); }void os_set_line_buffering (void )
tests/qtest/fuzz/fuzz.c +2 -2
@@ -143,7 +143,8 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) {char *target_name; -char *bindir, *datadir; +const char *bindir; +char *datadir;bool serialize = false;/* Initialize qgraph and modules */
@@ -167,7 +168,6 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)*/ bindir =qemu_get_exec_dir (); datadir =g_build_filename (bindir,"pc-bios" ,NULL ); -g_free (bindir);if (g_file_test (datadir,G_FILE_TEST_IS_DIR )) {qemu_add_data_dir (datadir); }
util/module.c +1 -6
@@ -172,7 +172,6 @@ bool module_load_one(const char *prefix, const char *lib_name)#ifdef CONFIG_MODULES char *fname =NULL ; -char *exec_dir;#ifdef CONFIG_MODULE_UPGRADES char *version_dir;#endif
@@ -199,13 +198,12 @@ bool module_load_one(const char *prefix, const char *lib_name)return true; } - exec_dir =qemu_get_exec_dir (); search_dir =getenv ("QEMU_MODULE_DIR" );if (search_dir !=NULL ) { dirs[n_dirs++] =g_strdup_printf ("%s" , search_dir); } dirs[n_dirs++] =g_strdup_printf ("%s" ,CONFIG_QEMU_MODDIR ); - dirs[n_dirs++] =g_strdup_printf ("%s" , exec_dir ? :"" ); + dirs[n_dirs++] =g_strdup (qemu_get_exec_dir ());#ifdef CONFIG_MODULE_UPGRADES version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
@@ -216,9 +214,6 @@ bool module_load_one(const char *prefix, const char *lib_name)assert (n_dirs <=ARRAY_SIZE (dirs)); -g_free (exec_dir); - exec_dir =NULL ; -for (i =0 ; i < n_dirs; i++) { fname =g_strdup_printf ("%s/%s%s" , dirs[i], module_name,CONFIG_HOST_DSOSUF );
util/oslib-posix.c +5 -3
@@ -366,7 +366,9 @@ void qemu_init_exec_dir(const char *argv0)char *p =NULL ;char buf[PATH_MAX ]; -assert (!exec_dir[0 ]); +if (exec_dir[0 ]) { +return ; + }#if defined(__linux__) {
@@ -439,9 +441,9 @@ void qemu_init_exec_dir(const char *argv0)g_free (dir); } -char *qemu_get_exec_dir (void ) +const char *qemu_get_exec_dir (void ) { -return g_strdup (exec_dir); +return exec_dir; }static void sigbus_handler (int signal)
util/oslib-win32.c +8 -4
@@ -315,7 +315,7 @@ void qemu_set_tty_echo(int fd, bool echo) } } -static char exec_dir[PATH_MAX ]; +static char *exec_dir;void qemu_init_exec_dir (const char *argv0) {
@@ -324,6 +324,10 @@ void qemu_init_exec_dir(const char *argv0)char buf[MAX_PATH ];DWORD len; +if (exec_dir) { +return ; + } + len =GetModuleFileName (NULL , buf,sizeof (buf) -1 );if (len ==0 ) {return ;
@@ -336,13 +340,13 @@ void qemu_init_exec_dir(const char *argv0) } *p =0 ;if (access (buf,R_OK ) ==0 ) { -pstrcpy (exec_dir,sizeof (exec_dir), buf); + exec_dir =g_strdup (buf); } } -char *qemu_get_exec_dir (void ) +const char *qemu_get_exec_dir (void ) { -return g_strdup (exec_dir); +return exec_dir; }#if !GLIB_CHECK_VERSION (2 ,50 ,0 )
Signature · 1 line
2.26.2
Re: [PATCH 02/13] oslib: do not call g_strdup from qemu_get_exec_dir
Quoted 184 lines · Paolo Bonzini
Just return the directory without requiring the caller to free it. This also removes a bogus check for NULL in
os_find_datadirandmodule_load_one;g_strdupof a static variable cannot return NULL.Signed-off-by Paolo Bonzini <[email protected]>--- include/qemu/osdep.h | 8 ++------ os-posix.c | 6 +----- os-win32.c | 2 +- tests/qtest/fuzz/fuzz.c | 4 ++-- util/module.c | 7 +------ util/oslib-posix.c | 8 +++++--- util/oslib-win32.c | 12 ++++++++---- 7 files changed, 20 insertions(+), 27 deletions(-)include/qemu/osdep.h +2
-6@@ -590,12 +590,8 @@ char *qemu_get_local_state_pathname(const char *relative_pathname);* Try OS specific API first, if not working, parse from argv0. */ void qemu_init_exec_dir (const char *argv0); -/* Get the saved exec dir. -* -* The caller is responsible for releasing the value returned with g_free() -* after use. -*/ -char *qemu_get_exec_dir (void ); +/* Get the saved exec dir. */ +const char *qemu_get_exec_dir (void );/** * qemu_getauxval: os-posix.c +1
-5@@ -90,13 +90,9 @@ void os_setup_signal_handling(void)*/ char *os_find_datadir (void ) { - g_autofree char *exec_dir = NULL; g_autofree char *dir = NULL; - exec_dir =qemu_get_exec_dir (); -g_return_val_if_fail (exec_dir !=NULL ,NULL ); - - dir =g_build_filename (exec_dir,"pc-bios" ,NULL ); + dir =g_build_filename (qemu_get_exec_dir (),"pc-bios" ,NULL );if (g_file_test (dir,G_FILE_TEST_IS_DIR )) {return g_steal_pointer (&dir); }os-win32.c +1
-1@@ -65,7 +65,7 @@ void os_setup_early_signal_handling(void)*/ char *os_find_datadir (void ) { -return qemu_get_exec_dir (); +return g_strdup (qemu_get_exec_dir ()); }void os_set_line_buffering (void )tests/qtest/fuzz/fuzz.c +2
-2@@ -143,7 +143,8 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) {char *target_name; -char *bindir, *datadir; +const char *bindir; +char *datadir;bool serialize = false;/* Initialize qgraph and modules */ @@ -167,7 +168,6 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)*/ bindir =qemu_get_exec_dir (); datadir =g_build_filename (bindir,"pc-bios" ,NULL ); -g_free (bindir);if (g_file_test (datadir,G_FILE_TEST_IS_DIR )) {qemu_add_data_dir (datadir); }util/module.c +1
-6@@ -172,7 +172,6 @@ bool module_load_one(const char *prefix, const char *lib_name)#ifdef CONFIG_MODULES char *fname =NULL ; -char *exec_dir;#ifdef CONFIG_MODULE_UPGRADES char *version_dir;#endif @@ -199,13 +198,12 @@ bool module_load_one(const char *prefix, const char *lib_name)return true; } - exec_dir =qemu_get_exec_dir (); search_dir =getenv ("QEMU_MODULE_DIR" );if (search_dir !=NULL ) { dirs[n_dirs++] =g_strdup_printf ("%s" , search_dir); } dirs[n_dirs++] =g_strdup_printf ("%s" ,CONFIG_QEMU_MODDIR ); - dirs[n_dirs++] =g_strdup_printf ("%s" , exec_dir ? :"" ); + dirs[n_dirs++] =g_strdup (qemu_get_exec_dir ());#ifdef CONFIG_MODULE_UPGRADES version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),@@ -216,9 +214,6 @@ bool module_load_one(const char *prefix, const char *lib_name)assert (n_dirs <=ARRAY_SIZE (dirs)); -g_free (exec_dir); - exec_dir =NULL ; -for (i =0 ; i < n_dirs; i++) { fname =g_strdup_printf ("%s/%s%s" , dirs[i], module_name,CONFIG_HOST_DSOSUF );util/oslib-posix.c +5
-3@@ -366,7 +366,9 @@ void qemu_init_exec_dir(const char *argv0)char *p =NULL ;char buf[PATH_MAX ]; -assert (!exec_dir[0 ]); +if (exec_dir[0 ]) { +return ; + }#if defined(__linux__) {@@ -439,9 +441,9 @@ void qemu_init_exec_dir(const char *argv0)g_free (dir); } -char *qemu_get_exec_dir (void ) +const char *qemu_get_exec_dir (void ) { -return g_strdup (exec_dir); +return exec_dir; }static void sigbus_handler (int signal)util/oslib-win32.c +6
-2@@ -315,7 +315,7 @@ void qemu_set_tty_echo(int fd, bool echo) } } -static char exec_dir[PATH_MAX ]; +static char *exec_dir;void qemu_init_exec_dir (const char *argv0) {@@ -324,6 +324,10 @@ void qemu_init_exec_dir(const char *argv0)char buf[MAX_PATH ];DWORD len; +if (exec_dir) { +return ; + } + len =GetModuleFileName (NULL , buf,sizeof (buf) -1 );if (len ==0 ) {return ;@@ -336,13 +340,13 @@ void qemu_init_exec_dir(const char *argv0) } *p =0 ;if (access (buf,R_OK ) ==0 ) { -pstrcpy (exec_dir,sizeof (exec_dir), buf); + exec_dir =g_strdup (buf); }
util/oslib-win32.c void qemu_init_exec_dir(const char *argv0) · line 352
Quoted 10 lines
util/oslib-win32.c +2
-2} -char *qemu_get_exec_dir (void ) +const char *qemu_get_exec_dir (void ) { -return g_strdup (exec_dir); +return exec_dir; }#if !GLIB_CHECK_VERSION (2 ,50 ,0 )
PATCH 3/13 oslib-posix: default exec_dir to bindir
In reply to Paolo BonziniIf the exec_dir cannot be retrieved, just assume it's the installation directory that was specified at configure time. This makes it simpler to reason about what the callers will do if they get back an empty path.
--- meson.build | 2 +- util/oslib-posix.c | 23 ++++++++--------------- util/oslib-win32.c | 2 ++ 3 files changed, 11 insertions(+), 16 deletions(-)
meson.build +1 -1
@@ -415,7 +415,7 @@ config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1] config_host_data.set('QEMU_VERSION_MICRO', meson.project_version().split('.')[2]) arrays = ['CONFIG_AUDIO_DRIVERS', 'CONFIG_BDRV_RW_WHITELIST', 'CONFIG_BDRV_RO_WHITELIST'] -strings = ['HOST_DSOSUF', 'CONFIG_IASL', 'qemu_confdir', 'qemu_datadir', +strings = ['HOST_DSOSUF', 'CONFIG_IASL', 'bindir', 'qemu_confdir', 'qemu_datadir', 'qemu_moddir', 'qemu_localstatedir', 'qemu_helperdir', 'qemu_localedir', 'qemu_icondir', 'qemu_desktopdir', 'qemu_firmwarepath'] foreach k, v: config_host
util/oslib-posix.c +8 -15
@@ -358,15 +358,14 @@ void qemu_set_tty_echo(int fd, bool echo)tcsetattr (fd,TCSANOW , &tty); } -static char exec_dir[PATH_MAX ]; +static char *exec_dir;void qemu_init_exec_dir (const char *argv0) { -char *dir;char *p =NULL ;char buf[PATH_MAX ]; -if (exec_dir[0 ]) { +if (exec_dir) {return ; }
@@ -425,20 +424,14 @@ void qemu_init_exec_dir(const char *argv0)#endif /* If we don't have any way of figuring out the actual executable location then try argv[0]. */ -if (!p) { -if (!argv0) { -return ; - } +if (!p && argv0) { p =realpath (argv0, buf); -if (!p) { -return ; - } } - dir =g_path_get_dirname (p); - -pstrcpy (exec_dir,sizeof (exec_dir), dir); - -g_free (dir); +if (p) { + exec_dir =g_path_get_dirname (p); + }else { + exec_dir =g_strdup (CONFIG_BINDIR ); + } }const char *qemu_get_exec_dir (void )
util/oslib-win32.c +2 -0
@@ -341,6 +341,8 @@ void qemu_init_exec_dir(const char *argv0) *p =0 ;if (access (buf,R_OK ) ==0 ) { exec_dir =g_strdup (buf); + }else { + exec_dir =g_strdup (CONFIG_BINDIR ); } }
Signature · 1 line
2.26.2
Re: [PATCH 03/13] oslib-posix: default exec_dir to bindir
Quoted 1 line · Paolo Bonzini
+
exec_dir=g_strdup(CONFIG_BINDIR);
Why the strdup? The string constant should be fine, IIUC.
r~
Re: [PATCH 03/13] oslib-posix: default exec_dir to bindir
Quoted 4 lines · Richard Henderson
Quoted 1 line · Paolo Bonzini
+
exec_dir=g_strdup(CONFIG_BINDIR);Why the strdup? The string constant should be fine, IIUC.
Of course it is.
Paolo
PATCH 4/13 cutils: introduce get_relocated_path
In reply to Paolo BonziniAdd the function that will compute a relocated version of the directories in CONFIG_QEMU_*DIR and CONFIG_QEMU_*PATH.
--- include/qemu/cutils.h | 12 +++++++++ meson.build | 4 +-- util/cutils.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-)
include/qemu/cutils.h +12 -0
@@ -184,4 +184,16 @@ int uleb128_decode_small(const uint8_t *in, uint32_t *n);*/ int qemu_pstrcmp0 (const char **str1,const char **str2); + +/** +* get_relocated_path: +* @dir: the directory (typically a `CONFIG_*DIR` variable) to be relocated. +* +* Returns a path for @dir that uses the directory of the running executable +* as the prefix. For example, if `bindir` is `/usr/bin` and @dir is +* `/usr/share/qemu`, the function will append `../share/qemu` to the +* directory that contains the running executable and return the result. +*/ +char *get_relocated_path (const char *dir); +#endif
meson.build +2 -2
@@ -415,9 +415,9 @@ config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1] config_host_data.set('QEMU_VERSION_MICRO', meson.project_version().split('.')[2]) arrays = ['CONFIG_AUDIO_DRIVERS', 'CONFIG_BDRV_RW_WHITELIST', 'CONFIG_BDRV_RO_WHITELIST'] -strings = ['HOST_DSOSUF', 'CONFIG_IASL', 'bindir', 'qemu_confdir', 'qemu_datadir', +strings = ['HOST_DSOSUF', 'CONFIG_IASL', 'bindir', 'prefix', 'qemu_confdir', 'qemu_datadir', 'qemu_moddir', 'qemu_localstatedir', 'qemu_helperdir', 'qemu_localedir', - 'qemu_icondir', 'qemu_desktopdir', 'qemu_firmwarepath'] + 'qemu_icondir', 'qemu_desktopdir', 'qemu_firmwarepath', 'sysconfdir'] foreach k, v: config_host if arrays.contains(k) if v != ''
util/cutils.c +61 -0
64 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 5/13 oslib-posix: relocate path to /var
In reply to Paolo Bonzini--- util/oslib-posix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
util/oslib-posix.c +4 -2
@@ -339,8 +339,10 @@ int qemu_pipe(int pipefd[2])char *qemu_get_local_state_pathname (const char *relative_pathname) { -return g_strdup_printf ("%s/%s" ,CONFIG_QEMU_LOCALSTATEDIR , - relative_pathname); + g_autofree char *dir = g_strdup_printf("%s/%s", +CONFIG_QEMU_LOCALSTATEDIR , + relative_pathname); +return get_relocated_path (dir); }void qemu_set_tty_echo (int fd,bool echo)
Signature · 1 line
2.26.2
Re: [PATCH 05/13] oslib-posix: relocate path to /var
Quoted 13 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- util/oslib-posix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)util/oslib-posix.c +0
-0@@ -339,8 +339,10 @@ int qemu_pipe(int pipefd[2])char *qemu_get_local_state_pathname (const char *relative_pathname)
util/oslib-posix.c int qemu_pipe(int pipefd[2]) · line 348
Quoted 10 lines
util/oslib-posix.c +4
-2{ -return g_strdup_printf ("%s/%s" ,CONFIG_QEMU_LOCALSTATEDIR , - relative_pathname); + g_autofree char *dir = g_strdup_printf("%s/%s", +CONFIG_QEMU_LOCALSTATEDIR , + relative_pathname); +return get_relocated_path (dir); }void qemu_set_tty_echo (int fd,bool echo)
PATCH 6/13 module: relocate path to modules
In reply to Paolo Bonzini--- util/module.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
util/module.c +2 -1
@@ -19,6 +19,7 @@#endif #include "qemu/queue.h" #include "qemu/module.h" +#include "qemu/cutils.h" #ifdef CONFIG_MODULE_UPGRADES #include "qemu-version.h" #endif
@@ -202,7 +203,7 @@ bool module_load_one(const char *prefix, const char *lib_name)if (search_dir !=NULL ) { dirs[n_dirs++] =g_strdup_printf ("%s" , search_dir); } - dirs[n_dirs++] =g_strdup_printf ("%s" ,CONFIG_QEMU_MODDIR ); + dirs[n_dirs++] =get_relocated_path (CONFIG_QEMU_MODDIR ); dirs[n_dirs++] =g_strdup (qemu_get_exec_dir ());#ifdef CONFIG_MODULE_UPGRADES
Signature · 1 line
2.26.2
PATCH 7/13 net: relocate paths to helpers and scripts
In reply to Paolo Bonzini--- include/net/net.h | 4 ++-- net/tap.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-)
include/net/net.h +2 -2
@@ -209,8 +209,8 @@ void netdev_add(QemuOpts *opts, Error **errp);int net_hub_id_for_client (NetClientState *nc,int *id);NetClientState *net_hub_port_find (int hub_id); -#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" -#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" +#define DEFAULT_NETWORK_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifup" +#define DEFAULT_NETWORK_DOWN_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifdown"#define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"#define DEFAULT_BRIDGE_INTERFACE "br0"
net/tap.c +21 -7
@@ -582,14 +582,20 @@ int net_init_bridge(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) {const NetdevBridgeOptions *bridge; -const char *helper, *br; + g_autofree char *default_helper = NULL; +const char *helper; +const char *br;TAPState *s;int fd, vnet_hdr;assert (netdev->type ==NET_CLIENT_DRIVER_BRIDGE ); bridge = &netdev->u.bridge; - helper = bridge->has_helper ? bridge->helper :DEFAULT_BRIDGE_HELPER ; +if (!bridge->has_helper) { + helper = default_helper =get_relocated_path (DEFAULT_BRIDGE_HELPER ); + }else { + helper = bridge->helper; + } br = bridge->has_br ? bridge->br :DEFAULT_BRIDGE_INTERFACE ; fd =net_bridge_run_helper (helper, br, errp);
@@ -773,8 +779,8 @@ int net_init_tap(const Netdev *netdev, const char *name,const NetdevTapOptions *tap;int fd, vnet_hdr =0 , i =0 , queues;/* for the no-fd, no-helper case */ -const char *script =NULL ;/* suppress wrong "uninit'd use" gcc warning */ -const char *downscript =NULL ; +const char *script; +const char *downscript;Error *err =NULL ;const char *vhostfdname;char ifname[128 ];
@@ -784,6 +790,8 @@ int net_init_tap(const Netdev *netdev, const char *name, tap = &netdev->u.tap; queues = tap->has_queues ? tap->queues :1 ; vhostfdname = tap->has_vhostfd ? tap->vhostfd :NULL ; + script = tap->has_script ? tap->script :NULL ; + downscript = tap->has_downscript ? tap->downscript :NULL ;/* QEMU hubs do not support multiqueue tap, in this case peer is set. * For -netdev, peer is always NULL. */
@@ -934,13 +942,19 @@ free_fail:return -1 ; } }else { + g_autofree char *default_script = NULL; + g_autofree char *default_downscript = NULL;if (tap->has_vhostfds) {error_setg (errp,"vhostfds= is invalid if fds= wasn't specified" );return -1 ; } - script = tap->has_script ? tap->script :DEFAULT_NETWORK_SCRIPT ; - downscript = tap->has_downscript ? tap->downscript : -DEFAULT_NETWORK_DOWN_SCRIPT ; + +if (!tap->has_script) { + script = default_script =get_relocated_path (DEFAULT_NETWORK_SCRIPT ); + } +if (!tap->has_downscript) { + downscript = default_downscript =get_relocated_path (DEFAULT_NETWORK_SCRIPT ); + }if (tap->has_ifname) {pstrcpy (ifname,sizeof ifname, tap->ifname);
Signature · 1 line
2.26.2
Re: [PATCH 07/13] net: relocate paths to helpers and scripts
Quoted 35 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- include/net/net.h | 4 ++-- net/tap.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-)include/net/net.h +2
-2@@ -209,8 +209,8 @@ void netdev_add(QemuOpts *opts, Error **errp);int net_hub_id_for_client (NetClientState *nc,int *id);NetClientState *net_hub_port_find (int hub_id); -#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" -#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" +#define DEFAULT_NETWORK_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifup" +#define DEFAULT_NETWORK_DOWN_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifdown"#define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"#define DEFAULT_BRIDGE_INTERFACE "br0"net/tap.c +3
-1@@ -582,14 +582,20 @@ int net_init_bridge(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) {const NetdevBridgeOptions *bridge; -const char *helper, *br; + g_autofree char *default_helper = NULL; +const char *helper; +const char *br;TAPState *s;int fd, vnet_hdr;
net/tap.c int net_init_bridge(const Netdev *netdev, const char *name, · line 598
Quoted 10 lines
net/tap.c +5
-1assert (netdev->type ==NET_CLIENT_DRIVER_BRIDGE ); bridge = &netdev->u.bridge; - helper = bridge->has_helper ? bridge->helper :DEFAULT_BRIDGE_HELPER ; +if (!bridge->has_helper) { + helper = default_helper =get_relocated_path (DEFAULT_BRIDGE_HELPER ); + }else { + helper = bridge->helper; + }
Nitpicking, I find easier to review adding simply once after out of the if() statement:
helper = bridge->helper;
Quoted 33 lines
net/tap.c +6
-2br = bridge->has_br ? bridge->br :DEFAULT_BRIDGE_INTERFACE ; fd =net_bridge_run_helper (helper, br, errp);@@ -773,8 +779,8 @@ int net_init_tap(const Netdev *netdev, const char *name,const NetdevTapOptions *tap;int fd, vnet_hdr =0 , i =0 , queues;/* for the no-fd, no-helper case */ -const char *script =NULL ;/* suppress wrong "uninit'd use" gcc warning */ -const char *downscript =NULL ; +const char *script; +const char *downscript;Error *err =NULL ;const char *vhostfdname;char ifname[128 ];@@ -784,6 +790,8 @@ int net_init_tap(const Netdev *netdev, const char *name, tap = &netdev->u.tap; queues = tap->has_queues ? tap->queues :1 ; vhostfdname = tap->has_vhostfd ? tap->vhostfd :NULL ; + script = tap->has_script ? tap->script :NULL ; + downscript = tap->has_downscript ? tap->downscript :NULL ;/* QEMU hubs do not support multiqueue tap, in this case peer is set. * For -netdev, peer is always NULL. */ @@ -934,13 +942,19 @@ free_fail:return -1 ; } }else { + g_autofree char *default_script = NULL; + g_autofree char *default_downscript = NULL;if (tap->has_vhostfds) {error_setg (errp,"vhostfds= is invalid if fds= wasn't specified" );return -1 ; }
net/tap.c free_fail: · line 957
Quoted 10 lines
net/tap.c +7
-3- script = tap->has_script ? tap->script :DEFAULT_NETWORK_SCRIPT ; - downscript = tap->has_downscript ? tap->downscript : -DEFAULT_NETWORK_DOWN_SCRIPT ; + +if (!tap->has_script) { + script = default_script =get_relocated_path (DEFAULT_NETWORK_SCRIPT ); + } +if (!tap->has_downscript) { + downscript = default_downscript =get_relocated_path (DEFAULT_NETWORK_SCRIPT ); + }
Quoted 4 lines
net/tap.c +0
-0if (tap->has_ifname) {pstrcpy (ifname,sizeof ifname, tap->ifname);
Re: [PATCH 07/13] net: relocate paths to helpers and scripts
Quoted 11 lines · Philippe Mathieu-Daudé
net/tap.c int net_init_bridge(const Netdev *netdev, const char *name, · line 598
Quoted 6 lines
net/tap.c +5
-1- helper = bridge->has_helper ? bridge->helper :DEFAULT_BRIDGE_HELPER ; +if (!bridge->has_helper) { + helper = default_helper =get_relocated_path (DEFAULT_BRIDGE_HELPER ); + }else { + helper = bridge->helper; + }Nitpicking, I find easier to review adding simply once after out of the
if()statement:helper = bridge->helper;
Even better,
- helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
+ helper = bridge->has_helper ? bridge->helper : NULL;
and move the get_relocated_path in net_bridge_run_helper.
Paolo
PATCH 8/13 vl: relocate paths to data directories
In reply to Paolo BonziniAs an additional advantage, the logic is now unified between POSIX and Win32 systems.
--- include/qemu-common.h | 1 - include/sysemu/sysemu.h | 2 +- os-posix.c | 20 -------------------- os-win32.c | 11 ----------- softmmu/vl.c | 40 ++++++++++++++++++++++++++++------------ tests/qtest/fuzz/fuzz.c | 5 +++-- 6 files changed, 32 insertions(+), 47 deletions(-)
include/qemu-common.h +0 -1
@@ -131,7 +131,6 @@ char *qemu_find_file(int type, const char *name);/* OS specific functions */ void os_setup_early_signal_handling (void ); -char *os_find_datadir (void );int os_parse_cmd_args (int index,const char *optarg);/*
include/sysemu/sysemu.h +1 -1
@@ -14,7 +14,7 @@ extern const char *qemu_name;extern QemuUUID qemu_uuid;extern bool qemu_uuid_set; -void qemu_add_data_dir (const char *path); +void qemu_add_data_dir (char *path);void qemu_add_exit_notifier (Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);
os-posix.c +0 -20
@@ -80,26 +80,6 @@ void os_setup_signal_handling(void)sigaction (SIGTERM , &act,NULL ); } -/* -* Find a likely location for support files using the location of the binary. -* When running from the build tree this will be "$bindir/pc-bios". -* Otherwise, this is CONFIG_QEMU_DATADIR. -* -* The caller must use g_free() to free the returned data when it is -* no longer required. -*/ -char *os_find_datadir (void ) -{ - g_autofree char *dir = NULL; - - dir =g_build_filename (qemu_get_exec_dir (),"pc-bios" ,NULL ); -if (g_file_test (dir,G_FILE_TEST_IS_DIR )) { -return g_steal_pointer (&dir); - } - -return g_strdup (CONFIG_QEMU_DATADIR ); -} -void os_set_proc_name (const char *s) {#if defined(PR_SET_NAME )
os-win32.c +0 -11
@@ -57,17 +57,6 @@ void os_setup_early_signal_handling(void)atexit (os_undo_timer_resolution); } -/* -* Look for support files in the same directory as the executable. -* -* The caller must use g_free() to free the returned data when it is -* no longer required. -*/ -char *os_find_datadir (void ) -{ -return g_strdup (qemu_get_exec_dir ()); -} -void os_set_line_buffering (void ) {setbuf (stdout,NULL );
softmmu/vl.c +28 -12
@@ -2005,7 +2005,7 @@ char *qemu_find_file(int type, const char *name)return NULL ; } -void qemu_add_data_dir (const char *path) +void qemu_add_data_dir (char *path) {int i;
@@ -2017,10 +2017,11 @@ void qemu_add_data_dir(const char *path) }for (i =0 ; i < data_dir_idx; i++) {if (strcmp (data_dir[i], path) ==0 ) { -return ;/* duplicate */ +g_free (path);/* duplicate */ +return ; } } - data_dir[data_dir_idx++] =g_strdup (path); + data_dir[data_dir_idx++] = path; }static inline bool nonempty_str (const char *str)
@@ -2829,6 +2830,26 @@ static void create_default_memdev(MachineState *ms, const char *path) &error_fatal); } +/* +* Find a likely location for support files using the location of the binary. +* When running from the build tree this will be "$bindir/pc-bios". +* Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated). +* +* The caller must use g_free() to free the returned data when it is +* no longer required. +*/ +static char *find_datadir (void ) +{ + g_autofree char *dir = NULL; + + dir =g_build_filename (qemu_get_exec_dir (),"pc-bios" ,NULL ); +if (g_file_test (dir,G_FILE_TEST_IS_DIR )) { +return g_steal_pointer (&dir); + } + +return get_relocated_path (CONFIG_QEMU_DATADIR ); +} +void qemu_init (int argc,char **argv,char **envp) {int i;
@@ -2862,7 +2883,7 @@ void qemu_init(int argc, char **argv, char **envp)Error *main_loop_err =NULL ;Error *err =NULL ;bool list_data_dirs = false; -char *dir, **dirs; +char **dirs;const char *mem_path =NULL ;bool have_custom_ram_size;BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue);
@@ -3195,7 +3216,7 @@ void qemu_init(int argc, char **argv, char **envp)if (is_help_option (optarg)) { list_data_dirs = true; }else { -qemu_add_data_dir (optarg); +qemu_add_data_dir (g_strdup (optarg)); }break ;case QEMU_OPTION_bios:
@@ -3927,17 +3948,12 @@ void qemu_init(int argc, char **argv, char **envp)/* add configured firmware directories */ dirs =g_strsplit (CONFIG_QEMU_FIRMWAREPATH ,G_SEARCHPATH_SEPARATOR_S ,0 );for (i =0 ; dirs[i] !=NULL ; i++) { -qemu_add_data_dir (dirs[i]); +qemu_add_data_dir (get_relocated_path (dirs[i])); }g_strfreev (dirs);/* try to find datadir relative to the executable path */ - dir =os_find_datadir (); -qemu_add_data_dir (dir); -g_free (dir); - -/* add the datadir specified when building */ -qemu_add_data_dir (CONFIG_QEMU_DATADIR ); +qemu_add_data_dir (find_datadir ());/* -L help lists the data directories and exits. */ if (list_data_dirs) {
tests/qtest/fuzz/fuzz.c +3 -2
@@ -170,8 +170,9 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) datadir =g_build_filename (bindir,"pc-bios" ,NULL );if (g_file_test (datadir,G_FILE_TEST_IS_DIR )) {qemu_add_data_dir (datadir); - } -g_free (datadir); + }else { +g_free (datadir); + } }else if (*argc >1 ) {/* The target is specified as an argument */ target_name = (*argv)[1 ];if (!strstr (target_name,"--fuzz-target=" )) {
Signature · 1 line
2.26.2
Re: [PATCH 08/13] vl: relocate paths to data directories
Quoted 96 lines · Paolo Bonzini
As an additional advantage, the logic is now unified between POSIX and Win32 systems.
Signed-off-by Paolo Bonzini <[email protected]>--- include/qemu-common.h | 1 - include/sysemu/sysemu.h | 2 +- os-posix.c | 20 -------------------- os-win32.c | 11 ----------- softmmu/vl.c | 40 ++++++++++++++++++++++++++++------------ tests/qtest/fuzz/fuzz.c | 5 +++-- 6 files changed, 32 insertions(+), 47 deletions(-)include/qemu-common.h +0
-1@@ -131,7 +131,6 @@ char *qemu_find_file(int type, const char *name);/* OS specific functions */ void os_setup_early_signal_handling (void ); -char *os_find_datadir (void );int os_parse_cmd_args (int index,const char *optarg);/* include/sysemu/sysemu.h +1
-1@@ -14,7 +14,7 @@ extern const char *qemu_name;extern QemuUUID qemu_uuid;extern bool qemu_uuid_set; -void qemu_add_data_dir (const char *path); +void qemu_add_data_dir (char *path);void qemu_add_exit_notifier (Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);os-posix.c +0
-20@@ -80,26 +80,6 @@ void os_setup_signal_handling(void)sigaction (SIGTERM , &act,NULL ); } -/* -* Find a likely location for support files using the location of the binary. -* When running from the build tree this will be "$bindir/pc-bios". -* Otherwise, this is CONFIG_QEMU_DATADIR. -* -* The caller must use g_free() to free the returned data when it is -* no longer required. -*/ -char *os_find_datadir (void ) -{ - g_autofree char *dir = NULL; - - dir =g_build_filename (qemu_get_exec_dir (),"pc-bios" ,NULL ); -if (g_file_test (dir,G_FILE_TEST_IS_DIR )) { -return g_steal_pointer (&dir); - } - -return g_strdup (CONFIG_QEMU_DATADIR ); -} -void os_set_proc_name (const char *s) {#if defined(PR_SET_NAME )os-win32.c +0
-11@@ -57,17 +57,6 @@ void os_setup_early_signal_handling(void)atexit (os_undo_timer_resolution); } -/* -* Look for support files in the same directory as the executable. -* -* The caller must use g_free() to free the returned data when it is -* no longer required. -*/ -char *os_find_datadir (void ) -{ -return g_strdup (qemu_get_exec_dir ()); -} -void os_set_line_buffering (void ) {setbuf (stdout,NULL );softmmu/vl.c +0
-0
softmmu/vl.c char *qemu_find_file(int type, const char *name) · line 2008
Quoted 5 lines
softmmu/vl.c +1
-1@@ -2005,7 +2005,7 @@ char *qemu_find_file(int type, const char *name)return NULL ; } -void qemu_add_data_dir (const char *path) +void qemu_add_data_dir (char *path)
But we have 'const char *data_dir[16];', why remove the const?
Quoted 99 lines
softmmu/vl.c +27
-11{int i;@@ -2017,10 +2017,11 @@ void qemu_add_data_dir(const char *path) }for (i =0 ; i < data_dir_idx; i++) {if (strcmp (data_dir[i], path) ==0 ) { -return ;/* duplicate */ +g_free (path);/* duplicate */ +return ; } } - data_dir[data_dir_idx++] =g_strdup (path); + data_dir[data_dir_idx++] = path; }static inline bool nonempty_str (const char *str)@@ -2829,6 +2830,26 @@ static void create_default_memdev(MachineState *ms, const char *path) &error_fatal); } +/* +* Find a likely location for support files using the location of the binary. +* When running from the build tree this will be "$bindir/pc-bios". +* Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated). +* +* The caller must use g_free() to free the returned data when it is +* no longer required. +*/ +static char *find_datadir (void ) +{ + g_autofree char *dir = NULL; + + dir =g_build_filename (qemu_get_exec_dir (),"pc-bios" ,NULL ); +if (g_file_test (dir,G_FILE_TEST_IS_DIR )) { +return g_steal_pointer (&dir); + } + +return get_relocated_path (CONFIG_QEMU_DATADIR ); +} +void qemu_init (int argc,char **argv,char **envp) {int i;@@ -2862,7 +2883,7 @@ void qemu_init(int argc, char **argv, char **envp)Error *main_loop_err =NULL ;Error *err =NULL ;bool list_data_dirs = false; -char *dir, **dirs; +char **dirs;const char *mem_path =NULL ;bool have_custom_ram_size;BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue);@@ -3195,7 +3216,7 @@ void qemu_init(int argc, char **argv, char **envp)if (is_help_option (optarg)) { list_data_dirs = true; }else { -qemu_add_data_dir (optarg); +qemu_add_data_dir (g_strdup (optarg)); }break ;case QEMU_OPTION_bios:@@ -3927,17 +3948,12 @@ void qemu_init(int argc, char **argv, char **envp)/* add configured firmware directories */ dirs =g_strsplit (CONFIG_QEMU_FIRMWAREPATH ,G_SEARCHPATH_SEPARATOR_S ,0 );for (i =0 ; dirs[i] !=NULL ; i++) { -qemu_add_data_dir (dirs[i]); +qemu_add_data_dir (get_relocated_path (dirs[i])); }g_strfreev (dirs);/* try to find datadir relative to the executable path */ - dir =os_find_datadir (); -qemu_add_data_dir (dir); -g_free (dir); - -/* add the datadir specified when building */ -qemu_add_data_dir (CONFIG_QEMU_DATADIR ); +qemu_add_data_dir (find_datadir ());/* -L help lists the data directories and exits. */ if (list_data_dirs) {tests/qtest/fuzz/fuzz.c +3
-2@@ -170,8 +170,9 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) datadir =g_build_filename (bindir,"pc-bios" ,NULL );if (g_file_test (datadir,G_FILE_TEST_IS_DIR )) {qemu_add_data_dir (datadir); - } -g_free (datadir); + }else { +g_free (datadir); + } }else if (*argc >1 ) {/* The target is specified as an argument */ target_name = (*argv)[1 ];if (!strstr (target_name,"--fuzz-target=" )) {
Re: [PATCH 08/13] vl: relocate paths to data directories
Quoted 4 lines · Philippe Mathieu-Daudé
softmmu/vl.c char *qemu_find_file(int type, const char *name) · line 2008
Quoted 3 lines
softmmu/vl.c +1
-1-void qemu_add_data_dir (const char *path) +void qemu_add_data_dir (char *path)But we have 'const char *data_dir[16];', why remove the const?
In order to free duplicates: before this patch the directory can be statically- or stack-allocated, now it's always heap-allocated.
Paolo
Quoted 5 lines
{ int i;softmmu/vl.c +0
-0@@ -2017,10 +2017,11 @@ void qemu_add_data_dir(const char *path) }
softmmu/vl.c void qemu_add_data_dir(const char *path) · line 2025
Quoted 10 lines
softmmu/vl.c +3
-2for (i =0 ; i < data_dir_idx; i++) {if (strcmp (data_dir[i], path) ==0 ) { -return ;/* duplicate */ +g_free (path);/* duplicate */ +return ; } } - data_dir[data_dir_idx++] =g_strdup (path); + data_dir[data_dir_idx++] = path; }
Paolo
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 08/13] vl: relocate paths to data directories
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines · Philippe Mathieu-Daudé
softmmu/vl.c char *qemu_find_file(int type, const char *name) · line 2008
Quoted 3 lines
softmmu/vl.c +1
-1-void qemu_add_data_dir (const char *path) +void qemu_add_data_dir (char *path)But we have 'const char *data_dir[16];', why remove the const?
In order to free duplicates: before this patch the directory can be statically- or stack-allocated, now it's always heap-allocated.
Oh I missed that, thanks.
Quoted 21 lines
Paolo
Quoted 5 lines
{ int i;softmmu/vl.c +0
-0@@ -2017,10 +2017,11 @@ void qemu_add_data_dir(const char *path) }softmmu/vl.c void qemu_add_data_dir(const char *path) · line 2025
Quoted 10 lines
softmmu/vl.c +3
-2for (i =0 ; i < data_dir_idx; i++) {if (strcmp (data_dir[i], path) ==0 ) { -return ;/* duplicate */ +g_free (path);/* duplicate */ +return ; } } - data_dir[data_dir_idx++] =g_strdup (path); + data_dir[data_dir_idx++] = path; }Paolo
PATCH 9/13 vl: relocate path to configuration file
In reply to Paolo Bonzini--- softmmu/vl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
softmmu/vl.c +2 -1
@@ -2676,8 +2676,9 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)static int qemu_read_default_config_file (void ) {int ret; + g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); - ret =qemu_read_config_file (CONFIG_QEMU_CONFDIR "/qemu.conf" ); + ret =qemu_read_config_file (file);if (ret <0 && ret != -ENOENT ) {return ret; }
Signature · 1 line
2.26.2
Re: [PATCH 09/13] vl: relocate path to configuration file
Quoted 11 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- softmmu/vl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)softmmu/vl.c +0
-0
softmmu/vl.c static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) · line 2684
Quoted 10 lines
softmmu/vl.c +2
-1@@ -2676,8 +2676,9 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)static int qemu_read_default_config_file (void ) {int ret; + g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); - ret =qemu_read_config_file (CONFIG_QEMU_CONFDIR "/qemu.conf" ); + ret =qemu_read_config_file (file);if (ret <0 && ret != -ENOENT ) {return ret; }
PATCH 10/13 qemu-bridge-helper: relocate path to default ACL
In reply to Paolo Bonzini--- qemu-bridge-helper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
qemu-bridge-helper.c +7 -2
@@ -40,6 +40,7 @@#endif #include "qemu/queue.h" +#include "qemu/cutils.h" #include "net/tap-linux.h"
@@ -245,6 +246,7 @@ int main(int argc, char **argv)ACLList acl_list;int access_allowed, access_denied;int ret =EXIT_SUCCESS ; + g_autofree char *acl_file = NULL;#ifdef CONFIG_LIBCAP_NG /* if we're run from an suid binary, immediately drop privileges preserving
@@ -257,6 +259,8 @@ int main(int argc, char **argv) }#endif +qemu_init_exec_dir (argv[0 ]); +/* parse arguments */ for (index =1 ; index < argc; index++) {if (strcmp (argv[index],"--use-vnet" ) ==0 ) {
@@ -282,9 +286,10 @@ int main(int argc, char **argv)/* parse default acl file */ QSIMPLEQ_INIT (&acl_list); -if (parse_acl_file (DEFAULT_ACL_FILE , &acl_list) ==-1 ) { + acl_file =get_relocated_path (DEFAULT_ACL_FILE ); +if (parse_acl_file (acl_file, &acl_list) ==-1 ) {fprintf (stderr,"failed to parse default acl file `%s'\n" , -DEFAULT_ACL_FILE ); + acl_file); ret =EXIT_FAILURE ; goto cleanup; }
Signature · 1 line
2.26.2
PATCH 11/13 qga: relocate path to default configuration and hook
In reply to Paolo Bonzini--- qga/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
qga/main.c +5 -3
@@ -29,6 +29,7 @@#include "qapi/error.h" #include "channel.h" #include "qemu/bswap.h" +#include "qemu/cutils.h" #include "qemu/help_option.h" #include "qemu/sockets.h" #include "qemu/systemd.h"
@@ -968,7 +969,7 @@ static void config_load(GAConfig *config) {GError *gerr =NULL ;GKeyFile *keyfile; -const char *conf =g_getenv ("QGA_CONF" ) ?:QGA_CONF_DEFAULT ; + g_autofree char *conf = g_strdup(g_getenv("QGA_CONF")) ?: get_relocated_path(QGA_CONF_DEFAULT);/* read system config */ keyfile =g_key_file_new ();
@@ -1027,7 +1028,7 @@ end:if (gerr && !(gerr->domain ==G_FILE_ERROR && gerr->code ==G_FILE_ERROR_NOENT )) {g_critical ("error loading configuration from path: %s, %s" , -QGA_CONF_DEFAULT , gerr->message); + conf, gerr->message);exit (EXIT_FAILURE ); }g_clear_error (&gerr);
@@ -1141,7 +1142,7 @@ static void config_parse(GAConfig *config, int argc, char **argv)#ifdef CONFIG_FSFREEZE case 'F' :g_free (config->fsfreeze_hook); - config->fsfreeze_hook =g_strdup (optarg ?:QGA_FSFREEZE_HOOK_DEFAULT ); + config->fsfreeze_hook =g_strdup (optarg) ?:get_relocated_path (QGA_FSFREEZE_HOOK_DEFAULT );break ;#endif case 't' :
@@ -1463,6 +1464,7 @@ int main(int argc, char **argv) config->log_level =G_LOG_LEVEL_ERROR |G_LOG_LEVEL_CRITICAL ; +qemu_init_exec_dir (argv[0 ]);qga_qmp_init_marshal (&ga_commands);init_dfl_pathnames ();
Signature · 1 line
2.26.2
PATCH 12/13 ui: relocate paths to icons and translations
In reply to Paolo Bonzini--- ui/gtk.c | 10 ++++++++-- ui/sdl2.c | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-)
ui/gtk.c +8 -2
@@ -51,6 +51,7 @@#include <math.h> #include "trace.h" +#include "qemu/cutils.h" #include "ui/input.h" #include "sysemu/runstate.h" #include "sysemu/sysemu.h"
@@ -2200,6 +2201,7 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)GtkDisplayState *s =g_malloc0 (sizeof (*s));GdkDisplay *window_display;GtkIconTheme *theme; +char *dir;if (!gtkinit) {fprintf (stderr,"gtk initialization failed\n" );
@@ -2209,7 +2211,9 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) s->opts = opts; theme =gtk_icon_theme_get_default (); -gtk_icon_theme_prepend_search_path (theme,CONFIG_QEMU_ICONDIR ); + dir =get_relocated_path (CONFIG_QEMU_ICONDIR ); +gtk_icon_theme_prepend_search_path (theme, dir); +g_free (dir);g_set_prgname ("qemu" ); s->window =gtk_window_new (GTK_WINDOW_TOPLEVEL );
@@ -2225,7 +2229,9 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)* sure that we don't accidentally break implicit assumptions. */ setlocale (LC_MESSAGES ,"" );setlocale (LC_CTYPE ,"C.UTF-8" ); -bindtextdomain ("qemu" ,CONFIG_QEMU_LOCALEDIR ); + dir =get_relocated_path (CONFIG_QEMU_LOCALEDIR ); +bindtextdomain ("qemu" , dir); +g_free (dir);bind_textdomain_codeset ("qemu" ,"UTF-8" );textdomain ("qemu" );
ui/sdl2.c +7 -2
@@ -25,6 +25,7 @@#include "qemu/osdep.h" #include "qemu/module.h" +#include "qemu/cutils.h" #include "ui/console.h" #include "ui/input.h" #include "ui/sdl2.h"
@@ -795,6 +796,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)int i;SDL_SysWMinfo info;SDL_Surface *icon =NULL ; +char *dir;assert (o->type ==DISPLAY_TYPE_SDL );
@@ -868,15 +870,18 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o) }#ifdef CONFIG_SDL_IMAGE - icon =IMG_Load (CONFIG_QEMU_ICONDIR "/hicolor/128x128/apps/qemu.png" ); + dir =get_relocated_path (CONFIG_QEMU_ICONDIR "/hicolor/128x128/apps/qemu.png" ); + icon =IMG_Load (dir);#else /* Load a 32x32x4 image. White pixels are transparent. */ - icon =SDL_LoadBMP (CONFIG_QEMU_ICONDIR "/hicolor/32x32/apps/qemu.bmp" ); + dir =get_relocated_path (CONFIG_QEMU_ICONDIR "/hicolor/32x32/apps/qemu.bmp" ); + icon =SDL_LoadBMP (dir);if (icon) {uint32_t colorkey =SDL_MapRGB (icon->format,255 ,255 ,255 );SDL_SetColorKey (icon,SDL_TRUE , colorkey); }#endif +g_free (dir);if (icon) {SDL_SetWindowIcon (sdl2_console[0 ].real_window, icon); }
Signature · 1 line
2.26.2
Re: [PATCH 12/13] ui: relocate paths to icons and translations
Quoted 5 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- ui/gtk.c | 10 ++++++++-- ui/sdl2.c | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-)
PATCH 13/13 configure: use a platform-neutral prefix
In reply to Paolo BonziniNow that the installation is relocatable, there is no need to compile a Windows-format prefix into Win32 binaries. Instead, the prefix will only be used to compute installation-relative paths, and it can be any string.
Drop the "Program Files" path completely: it is only usable on English versions of Windows; therefore, using the NSIS installer to get the "correct" path to the Program Files folder is recommended, and NSIS works just as well with any prefix.
--- configure | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)
configure +11 -19
@@ -1009,7 +1009,7 @@ if test "$mingw32" = "yes" ; then if compile_prog "" "-liberty" ; then LIBS="-liberty $LIBS" fi - prefix="c:/Program Files/QEMU" + prefix="/qemu" qemu_suffix="" libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32 $libs_qga" fi
@@ -8145,17 +8145,9 @@ echo "strip = $(meson_quote $strip)" >> $cross echo "windres = $(meson_quote $windres)" >> $cross if test -n "$cross_prefix"; then cross_arg="--cross-file config-meson.cross" - # Hack: Meson expects an absolute path for the *build* machine - # for the prefix, so add a slash in front of a Windows path that - # includes a drive letter. - # - # See https://github.com/mesonbuild/meson/issues/7577. echo "[host_machine]" >> $cross if test "$mingw32" = "yes" ; then echo "system = 'windows'" >> $cross - case $prefix in - ?:*) pre_prefix=/ ;; - esac fi case "$ARCH" in i386|x86_64)
@@ -8181,16 +8173,16 @@ mv $cross config-meson.cross rm -rf meson-private meson-info meson-logs NINJA=${ninja:-$PWD/ninjatool} $meson setup \ - --prefix "${pre_prefix}$prefix" \ - --libdir "${pre_prefix}$libdir" \ - --libexecdir "${pre_prefix}$libexecdir" \ - --bindir "${pre_prefix}$bindir" \ - --includedir "${pre_prefix}$includedir" \ - --datadir "${pre_prefix}$datadir" \ - --mandir "${pre_prefix}$mandir" \ - --sysconfdir "${pre_prefix}$sysconfdir" \ - --localstatedir "${pre_prefix}$local_statedir" \ - -Ddocdir="${pre_prefix}$docdir" \ + --prefix "$prefix" \ + --libdir "$libdir" \ + --libexecdir "$libexecdir" \ + --bindir "$bindir" \ + --includedir "$includedir" \ + --datadir "$datadir" \ + --mandir "$mandir" \ + --sysconfdir "$sysconfdir" \ + --localstatedir "$local_statedir" \ + -Ddocdir="$docdir" \ -Dqemu_suffix="$qemu_suffix" \ -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) \ -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo false; fi) \
Signature · 1 line
2.26.2
Quoted 31 lines · Paolo Bonzini
Right now, the installation of QEMU is not relocatable; there is a local hack in
os_find_datadir()so that Windows binaries look for ROMs in the executable directory, but that has several limitations:- it does not extend to configuration files, icons, etc.
- it does not allow changing the data directory in any way
- it does not apply to POSIX platforms
This series fixes that by making all paths within the installation prefix relative to the executable. This in practice means all paths will be relocatable, except for /etc and /var if they're moved outside the prefix.
Here is an example of relocatability; before:
$ make DESTDIR=$PWD/test install $ cd test/usr/local/bin $ ./qemu-system-ppc -L help /usr/local/share/qemu-firmware /usr/local/share/qemuAfter:
$ make DESTDIR=$PWD/test install $ cd test/usr/local/bin $ ./qemu-system-ppc -L help /home/pbonzini/work/upstream/qemu/+build/test/usr/local/bin/../share/qemu-firmware /home/pbonzini/work/upstream/qemu/+build/test/usr/local/bin/../share/qemu
Quoted 6 lines
The main benefit of this is on Windows, as mentioned above; but it also makes behavior more consistent across platforms and allows the removal of the hack that hides the "c:/Program Files/QEMU" prefix from Meson during cross compilation.
Paolo
Hi Paolo,
I've managed to give this a quick go this evening and I see the same link error reported by Yonggang Luo at
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg00586.html, i.e.:
"cc" -o storage-daemon/qemu-storage-daemon.exe version.rc_version.o storage-daemon/qemu-storage-daemon.exe.p/meson-generated_.._qapi_qapi-introspect.c.obj storage-daemon/qemu-storage-daemon.exe.p/meson-generated_.._qapi_qapi-commands.c.obj storage-daemon/qemu-storage-daemon.exe.p/meson-generated_.._qapi_qapi-emit-events.c.obj storage-daemon/qemu-storage-daemon.exe.p/meson-generated_.._qapi_qapi-events.c.obj storage-daemon/qemu-storage-daemon.exe.p/meson-generated_.._qapi_qapi-visit.c.obj storage-daemon/qemu-storage-daemon.exe.p/meson-generated_.._qapi_qapi-init-commands.c.obj storage-daemon/qemu-storage-daemon.exe.p/meson-generated_.._qapi_qapi-types.c.obj storage-daemon/qemu-storage-daemon.exe.p/qemu-storage-daemon.c.obj
storage-daemon/qemu-storage-daemon.exe.p/.._iothread.c.obj
storage-daemon/qemu-storage-daemon.exe.p/.._blockdev-nbd.c.obj
storage-daemon/qemu-storage-daemon.exe.p/.._blockdev.c.obj
storage-daemon/qemu-storage-daemon.exe.p/.._job-qmp.c.obj
"-L/home/Mark/qemu/build/dtc/libfdt" "-Wl,--allow-shlib-undefined"
"-Wl,--whole-archive" "libqmp.fa" "libblock.fa" "crypto/libcrypto.fa"
"authz/libauthz.fa" "qom/libqom.fa" "io/libio.fa" "chardev/libchardev.fa"
"-Wl,--no-whole-archive" "-Wl,--nxcompat" "-Wl,--no-seh" "-Wl,--dynamicbase"
"-Wl,--warn-common" "-m64" "-fstack-protector-strong" "-Wl,--start-group"
"libqemuutil.a" "libqmp.fa" "libblock.fa" "crypto/libcrypto.fa" "authz/libauthz.fa"
"qom/libqom.fa" "io/libio.fa" "chardev/libchardev.fa" "@block.syms" "-lwinmm"
"-LC:/msys64/mingw64/lib" "-lgio-2.0" "-lgobject-2.0" "-lglib-2.0" "-lintl"
"-pthread" "-lm" "-LC:/msys64/mingw64/lib" "-lgthread-2.0" "-lglib-2.0" "-lintl"
"-lws2_32" "-LC:/msys64/mingw64/lib" "-lzstd" "-LC:/msys64/mingw64/lib" "-lxml2"
"-LC:/msys64/mingw64/lib" "-lz" "-lbz2" "-LC:/msys64/mingw64/lib" "-lgthread-2.0"
"-lglib-2.0" "-lintl" "-mconsole" "-lkernel32" "-luser32" "-lgdi32" "-lwinspool"
"-lshell32" "-lole32" "-loleaut32" "-luuid" "-lcomdlg32" "-ladvapi32" "-Wl,--end-group" C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lfdt
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lcapstone
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lfdt
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lcapstone
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lslirp
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lslirp
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile.ninja:1405: qemu-system-ppc.exe] Error 1
make[1]: *** Waiting for unfinished jobs....
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile.ninja:1407: qemu-system-ppcw.exe] Error 1
make[1]: Leaving directory '/home/Mark/qemu/build'
make: *** [GNUmakefile:11: install] Error 2
I think this means that it's missing something from Yonggang Luo's patch here:
https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg07668.html. I haven't looked at patch 1 in that series for converting undefsym.sh to undefsym.py yet, although last time I was able to get a working build without it.
Also patch 13 wouldn't apply for me to git master: I ended up having to make the changes by hand, so looks like something requiring a rebase has recently snuck in.
ATB,
Mark.
Il mar 1 set 2020, 23:15 Mark Cave-Ayland <[email protected]> ha scritto:
Quoted 3 lines
I think this means that it's missing something from Yonggang Luo's patch here:
https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg07668.html.
Yes, I am a bit afraid of that patch. I don't understand exactly why it's needed and I need to look more closely.
Paolo
I haven't looked
Quoted 15 lines
at patch 1 in that series for converting
undefsym.shtoundefsym.pyyet, although
last time I was able to get a working build without it.Also patch 13 wouldn't apply for me to git master: I ended up having to make the
changes by hand, so looks like something requiring a rebase has recently snuck in.ATB,
Mark.
Quoted 11 lines · Paolo Bonzini
Il mar 1 set 2020, 23:15 Mark Cave-Ayland <[email protected] <mailto:[email protected]>> ha scritto:
I think this means that it's missing something from Yonggang Luo's patch here:
https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg07668.html.Yes, I am a bit afraid of that patch. I don't understand exactly why it's needed and I need to look more closely.
Paolo
I did a quick experiment first thing this morning and it really is just the Windows linker ld.exe that requires a Windows-style path, since I was able to successfully build with just this:
configure +0 -0
@@ -1015,6 +1015,9 @@ if test "$mingw32" = "yes" ; then prefix="/qemu" confsuffix="" libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32
$libs_qga"
+ ld_pwd=$(pwd -W)
+else
+ ld_pwd=$(pwd)
fi
werror=""
@@ -4290,7 +4293,7 @@ EOF
symlink "$source_path/dtc/Makefile" "dtc/Makefile"
fi
fdt_cflags="-I${source_path}/dtc/libfdt"
- fdt_ldflags="-L$PWD/dtc/libfdt"
+ fdt_ldflags="-L${ld_pwd}/dtc/libfdt"
fdt_libs="$fdt_libs"
elif test "$fdt" = "yes" ; then
# Not a git build & no libfdt found, prompt for system install
@@ -5275,7 +5278,7 @@ case "$capstone" in
else
LIBCAPSTONE=libcapstone.a
fi
- capstone_libs="-L$PWD/capstone -lcapstone"
+ capstone_libs="-L${ld_pwd}/capstone -lcapstone"
capstone_cflags="-I${source_path}/capstone/include"
;;@@ -6276,7 +6279,7 @@ case "$slirp" in
fi
mkdir -p slirp slirp_cflags="-I${source_path}/slirp/src -I$PWD/slirp/src"
- slirp_libs="-L$PWD/slirp -lslirp"
+ slirp_libs="-L${ld_pwd}/slirp -lslirp"
if test "$mingw32" = "yes" ; then
slirp_libs="$slirp_libs -lws2_32 -liphlpapi"
fiI'll try again with the relocatable install later - do I still need to pass --prefix into configure or should I leave that for now and just use DESTDIR?
ATB,
Mark.
configure
Quoted 13 lines · Mark Cave-Ayland
configure +0
-0@@ -1015,6 +1015,9 @@ if test "$mingw32" = "yes" ; then prefix="/qemu" confsuffix="" libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32$libs_qga"
configure +3
-0+ ld_pwd=$(pwd -W) +else + ld_pwd=$(pwd) fi
That wouldn't work for cross-compilation, but I got the idea. :)
Quoted 20 lines
werror=""
configure +2
-2@@ -4290,7 +4293,7 @@ EOF symlink "$source_path/dtc/Makefile" "dtc/Makefile" fi fdt_cflags="-I${source_path}/dtc/libfdt" - fdt_ldflags="-L$PWD/dtc/libfdt" + fdt_ldflags="-L${ld_pwd}/dtc/libfdt" fdt_libs="$fdt_libs" elif test "$fdt" = "yes" ; then # Not a git build & no libfdt found, prompt for system install@@ -5275,7 +5278,7 @@ case "$capstone" in else LIBCAPSTONE=libcapstone.a fi - capstone_libs="-L$PWD/capstone -lcapstone" + capstone_libs="-L${ld_pwd}/capstone -lcapstone" capstone_cflags="-I${source_path}/capstone/include" ;;
configure case "$slirp" in · line 6285
Quoted 8 lines
configure +1
-1@@ -6276,7 +6279,7 @@ case "$slirp" in fi mkdir -p slirp slirp_cflags="-I${source_path}/slirp/src -I$PWD/slirp/src" - slirp_libs="-L$PWD/slirp -lslirp" + slirp_libs="-L${ld_pwd}/slirp -lslirp" if test "$mingw32" = "yes" ; then slirp_libs="$slirp_libs -lws2_32 -liphlpapi" fi
Since there is no recursive make anymore, these can be just -Ldtc/libfdt, -Lcapstone and -Lslirp. Nice. :)
Quoted 2 lines
I'll try again with the relocatable install later - do I still need to pass --prefix into configure or should I leave that for now and just use DESTDIR?
You can just use DESTDIR.
Paolo
Quoted 36 lines · Paolo Bonzini
configure
Quoted 13 lines · Mark Cave-Ayland
configure +0
-0@@ -1015,6 +1015,9 @@ if test "$mingw32" = "yes" ; then prefix="/qemu" confsuffix="" libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi -lnetapi32$libs_qga"
configure +3
-0+ ld_pwd=$(pwd -W) +else + ld_pwd=$(pwd) fiThat wouldn't work for cross-compilation, but I got the idea. :)
Quoted 19 lines
werror=""
configure +2
-2@@ -4290,7 +4293,7 @@ EOF symlink "$source_path/dtc/Makefile" "dtc/Makefile" fi fdt_cflags="-I${source_path}/dtc/libfdt" - fdt_ldflags="-L$PWD/dtc/libfdt" + fdt_ldflags="-L${ld_pwd}/dtc/libfdt" fdt_libs="$fdt_libs" elif test "$fdt" = "yes" ; then # Not a git build & no libfdt found, prompt for system install@@ -5275,7 +5278,7 @@ case "$capstone" in else LIBCAPSTONE=libcapstone.a fi - capstone_libs="-L$PWD/capstone -lcapstone" + capstone_libs="-L${ld_pwd}/capstone -lcapstone" capstone_cflags="-I${source_path}/capstone/include" ;;
Quoted 12 lines
configure case "$slirp" in · line 6285
Quoted 9 lines
configure +1
-1@@ -6276,7 +6279,7 @@ case "$slirp" in fi mkdir -p slirp slirp_cflags="-I${source_path}/slirp/src -I$PWD/slirp/src" - slirp_libs="-L$PWD/slirp -lslirp" + slirp_libs="-L${ld_pwd}/slirp -lslirp" if test "$mingw32" = "yes" ; then slirp_libs="$slirp_libs -lws2_32 -liphlpapi" fiSince there is no recursive make anymore, these can be just -Ldtc/libfdt, -Lcapstone and -Lslirp. Nice. :)
Yes indeed, a quick test with this diff on top of your patchset gives me a working build and link (minus the manual patch still required to capstone):
configure +3 -3
@@ -4290,7 +4290,7 @@ EOF symlink "$source_path/dtc/Makefile" "dtc/Makefile" fi fdt_cflags="-I${source_path}/dtc/libfdt" - fdt_ldflags="-L$PWD/dtc/libfdt" + fdt_ldflags="-Ldtc/libfdt" fdt_libs="$fdt_libs" elif test "$fdt" = "yes" ; then # Not a git build & no libfdt found, prompt for system install
@@ -5275,7 +5275,7 @@ case "$capstone" in else LIBCAPSTONE=libcapstone.a fi - capstone_libs="-L$PWD/capstone -lcapstone" + capstone_libs="-Lcapstone -lcapstone" capstone_cflags="-I${source_path}/capstone/include" ;;
@@ -6276,7 +6276,7 @@ case "$slirp" in fi mkdir -p slirp slirp_cflags="-I${source_path}/slirp/src -I$PWD/slirp/src" - slirp_libs="-L$PWD/slirp -lslirp" + slirp_libs="-Lslirp -lslirp" if test "$mingw32" = "yes" ; then slirp_libs="$slirp_libs -lws2_32 -liphlpapi" fi
Quoted 4 lines
Quoted 2 lines
I'll try again with the relocatable install later - do I still need to pass --prefix into configure or should I leave that for now and just use DESTDIR?
You can just use DESTDIR.
This doesn't quite look right: I went with "make V=1 DESTDIR=/home/Mark/rel-qemu-git install" and the resulting tree came out like this:
/home/Mark/rel-qemu-git:
total 20
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 msys64 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 qemu
/home/Mark/rel-qemu-git/msys64:
total 4
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 qemu
/home/Mark/rel-qemu-git/msys64/qemu:
total 29072
-rwxr-xr-x 1 Mark None 311296 Sep 2 11:26 qemu-edid.exe -rwxr-xr-x 1 Mark None 496640 Sep 2 11:26 qemu-ga.exe -rwxr-xr-x 1 Mark None 1650688 Sep 2 11:26 qemu-img.exe -rwxr-xr-x 1 Mark None 1597440 Sep 2 11:26 qemu-io.exe -rwxr-xr-x 1 Mark None 2001920 Sep 2 11:26 qemu-storage-daemon.exe -rwxr-xr-x 1 Mark None 11850752 Sep 2 11:26 qemu-system-ppc.exe -rwxr-xr-x 1 Mark None 11850752 Sep 2 11:26 qemu-system-ppcw.exe drwxr-xr-x 1 Mark None 0 Sep 2 11:26 share
/home/Mark/rel-qemu-git/msys64/qemu/share:
total 4
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 locale
/home/Mark/rel-qemu-git/msys64/qemu/share/locale:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 bg drwxr-xr-x 1 Mark None 0 Sep 2 11:26 de_DE drwxr-xr-x 1 Mark None 0 Sep 2 11:26 fr_FR drwxr-xr-x 1 Mark None 0 Sep 2 11:26 hu drwxr-xr-x 1 Mark None 0 Sep 2 11:26 it drwxr-xr-x 1 Mark None 0 Sep 2 11:26 sv drwxr-xr-x 1 Mark None 0 Sep 2 11:26 tr drwxr-xr-x 1 Mark None 0 Sep 2 11:26 zh_CN
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/bg:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 LC_MESSAGES
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/bg/LC_MESSAGES:
total 4
-rw-r--r-- 1 Mark None 1633 Sep 2 11:26 qemu.mo
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/de_DE:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 LC_MESSAGES
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/de_DE/LC_MESSAGES:
total 4
-rw-r--r-- 1 Mark None 1342 Sep 2 11:26 qemu.mo
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/fr_FR:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 LC_MESSAGES
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/fr_FR/LC_MESSAGES:
total 4
-rw-r--r-- 1 Mark None 1363 Sep 2 11:26 qemu.mo
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/hu:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 LC_MESSAGES
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/hu/LC_MESSAGES:
total 4
-rw-r--r-- 1 Mark None 1019 Sep 2 11:26 qemu.mo
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/it:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 LC_MESSAGES
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/it/LC_MESSAGES:
total 4
-rw-r--r-- 1 Mark None 1324 Sep 2 11:26 qemu.mo
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/sv:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 LC_MESSAGES
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/sv/LC_MESSAGES:
total 4
-rw-r--r-- 1 Mark None 1381 Sep 2 11:26 qemu.mo
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/tr:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 LC_MESSAGES
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/tr/LC_MESSAGES:
total 4
-rw-r--r-- 1 Mark None 1047 Sep 2 11:26 qemu.mo
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/zh_CN:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 LC_MESSAGES
/home/Mark/rel-qemu-git/msys64/qemu/share/locale/zh_CN/LC_MESSAGES:
total 4
-rw-r--r-- 1 Mark None 1393 Sep 2 11:26 qemu.mo
/home/Mark/rel-qemu-git/qemu:
total 12068
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 applications -rw-r--r-- 1 Mark None 3211 Sep 2 11:26 bamboo.dtb -rw-r--r-- 1 Mark None 131072 Sep 2 11:26 bios.bin -rw-r--r-- 1 Mark None 262144 Sep 2 11:26 bios-256k.bin -rw-r--r-- 1 Mark None 65536 Sep 2 11:26 bios-microvm.bin -rw-r--r-- 1 Mark None 9779 Sep 2 11:26 canyonlands.dtb -rw-r--r-- 1 Mark None 42903 Sep 2 11:26 edk2-licenses.txt -rw-r--r-- 1 Mark None 240128 Sep 2 11:26 efi-e1000.rom -rw-r--r-- 1 Mark None 240128 Sep 2 11:26 efi-e1000e.rom -rw-r--r-- 1 Mark None 240128 Sep 2 11:26 efi-eepro100.rom -rw-r--r-- 1 Mark None 238592 Sep 2 11:26 efi-ne2k_pci.rom -rw-r--r-- 1 Mark None 238592 Sep 2 11:26 efi-pcnet.rom -rw-r--r-- 1 Mark None 242688 Sep 2 11:26 efi-rtl8139.rom -rw-r--r-- 1 Mark None 242688 Sep 2 11:26 efi-virtio.rom -rw-r--r-- 1 Mark None 236032 Sep 2 11:26 efi-vmxnet3.rom drwxr-xr-x 1 Mark None 0 Sep 2 11:26 firmware -rw-r--r-- 1 Mark None 783192 Sep 2 11:26 hppa-firmware.img drwxr-xr-x 1 Mark None 0 Sep 2 11:26 icons drwxr-xr-x 1 Mark None 0 Sep 2 11:26 keymaps -rw-r--r-- 1 Mark None 9216 Sep 2 11:26 kvmvapic.bin -rw-r--r-- 1 Mark None 1024 Sep 2 11:26 linuxboot.bin -rw-r--r-- 1 Mark None 1536 Sep 2 11:26 linuxboot_dma.bin -rw-r--r-- 1 Mark None 1024 Sep 2 11:26 multiboot.bin -rw-r--r-- 1 Mark None 696912 Sep 2 11:26 openbios-ppc -rw-r--r-- 1 Mark None 382048 Sep 2 11:26 openbios-sparc32 -rw-r--r-- 1 Mark None 1593408 Sep 2 11:26 openbios-sparc64 -rw-r--r-- 1 Mark None 62144 Sep 2 11:26 opensbi-riscv32-generic-fw_dynamic.bin -rw-r--r-- 1 Mark None 558668 Sep 2 11:26 opensbi-riscv32-generic-fw_dynamic.elf -rw-r--r-- 1 Mark None 70792 Sep 2 11:26 opensbi-riscv64-generic-fw_dynamic.bin -rw-r--r-- 1 Mark None 620424 Sep 2 11:26 opensbi-riscv64-generic-fw_dynamic.elf -rw-r--r-- 1 Mark None 156328 Sep 2 11:26 palcode-clipper -rw-r--r-- 1 Mark None 9882 Sep 2 11:26 petalogix-ml605.dtb -rw-r--r-- 1 Mark None 8161 Sep 2 11:26 petalogix-s3adsp1800.dtb -rw-r--r-- 1 Mark None 1536 Sep 2 11:26 pvh.bin -rw-r--r-- 1 Mark None 67072 Sep 2 11:26 pxe-e1000.rom -rw-r--r-- 1 Mark None 61440 Sep 2 11:26 pxe-eepro100.rom -rw-r--r-- 1 Mark None 61440 Sep 2 11:26 pxe-ne2k_pci.rom -rw-r--r-- 1 Mark None 61440 Sep 2 11:26 pxe-pcnet.rom -rw-r--r-- 1 Mark None 61440 Sep 2 11:26 pxe-rtl8139.rom -rw-r--r-- 1 Mark None 60416 Sep 2 11:26 pxe-virtio.rom -rw-r--r-- 1 Mark None 850 Sep 2 11:26 QEMU,cgthree.bin -rw-r--r-- 1 Mark None 1402 Sep 2 11:26 QEMU,tcx.bin -rw-r--r-- 1 Mark None 18752 Sep 2 11:26 qemu_vga.ndrv -rw-r--r-- 1 Mark None 154542 Sep 2 11:26 qemu-nsis.bmp -rw-r--r-- 1 Mark None 42608 Sep 2 11:26 s390-ccw.img -rw-r--r-- 1 Mark None 67232 Sep 2 11:26 s390-netboot.img -rw-r--r-- 1 Mark None 4096 Sep 2 11:26 sgabios.bin -rw-r--r-- 1 Mark None 1667280 Sep 2 11:26 skiboot.lid -rw-r--r-- 1 Mark None 968368 Sep 2 11:26 slof.bin -rw-r--r-- 1 Mark None 348512 Sep 2 11:20 trace-events-all -rw-r--r-- 1 Mark None 349148 Sep 2 11:26 u-boot.e500 -rw-r--r-- 1 Mark None 524288 Sep 2 11:26 u-boot-sam460-20100605.bin -rw-r--r-- 1 Mark None 38912 Sep 2 11:26 vgabios.bin -rw-r--r-- 1 Mark None 39424 Sep 2 11:26 vgabios-ati.bin -rw-r--r-- 1 Mark None 28672 Sep 2 11:26 vgabios-bochs-display.bin -rw-r--r-- 1 Mark None 38912 Sep 2 11:26 vgabios-cirrus.bin -rw-r--r-- 1 Mark None 39424 Sep 2 11:26 vgabios-qxl.bin -rw-r--r-- 1 Mark None 28672 Sep 2 11:26 vgabios-ramfb.bin -rw-r--r-- 1 Mark None 39424 Sep 2 11:26 vgabios-stdvga.bin -rw-r--r-- 1 Mark None 39424 Sep 2 11:26 vgabios-virtio.bin -rw-r--r-- 1 Mark None 39424 Sep 2 11:26 vgabios-vmware.bin
/home/Mark/rel-qemu-git/qemu/applications:
total 1
-rw-r--r-- 1 Mark None 134 Sep 2 11:26 qemu.desktop
/home/Mark/rel-qemu-git/qemu/firmware:
total 21
-rw-r--r-- 1 Mark None 696 Sep 2 11:19 50-edk2-i386-secure.json -rw-r--r-- 1 Mark None 721 Sep 2 11:19 50-edk2-x86_64-secure.json -rw-r--r-- 1 Mark None 602 Sep 2 11:19 60-edk2-aarch64.json -rw-r--r-- 1 Mark None 590 Sep 2 11:19 60-edk2-arm.json -rw-r--r-- 1 Mark None 647 Sep 2 11:19 60-edk2-i386.json -rw-r--r-- 1 Mark None 672 Sep 2 11:19 60-edk2-x86_64.json
/home/Mark/rel-qemu-git/qemu/icons:
total 4
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 hicolor
/home/Mark/rel-qemu-git/qemu/icons/hicolor:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 128x128 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 16x16 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 24x24 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 256x256 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 32x32 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 48x48 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 512x512 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 64x64 drwxr-xr-x 1 Mark None 0 Sep 2 11:26 scalable
/home/Mark/rel-qemu-git/qemu/icons/hicolor/128x128:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/128x128/apps:
total 12
-rw-r--r-- 1 Mark None 8286 Sep 2 11:26 qemu.png
/home/Mark/rel-qemu-git/qemu/icons/hicolor/16x16:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/16x16/apps:
total 4
-rw-r--r-- 1 Mark None 765 Sep 2 11:26 qemu.png
/home/Mark/rel-qemu-git/qemu/icons/hicolor/24x24:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/24x24/apps:
total 4
-rw-r--r-- 1 Mark None 1201 Sep 2 11:26 qemu.png
/home/Mark/rel-qemu-git/qemu/icons/hicolor/256x256:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/256x256/apps:
total 20
-rw-r--r-- 1 Mark None 17572 Sep 2 11:26 qemu.png
/home/Mark/rel-qemu-git/qemu/icons/hicolor/32x32:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/32x32/apps:
total 12
-rw-r--r-- 1 Mark None 4234 Sep 2 11:26 qemu.bmp -rw-r--r-- 1 Mark None 1696 Sep 2 11:26 qemu.png
/home/Mark/rel-qemu-git/qemu/icons/hicolor/48x48:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/48x48/apps:
total 4
-rw-r--r-- 1 Mark None 2694 Sep 2 11:26 qemu.png
/home/Mark/rel-qemu-git/qemu/icons/hicolor/512x512:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/512x512/apps:
total 40
-rw-r--r-- 1 Mark None 38007 Sep 2 11:26 qemu.png
/home/Mark/rel-qemu-git/qemu/icons/hicolor/64x64:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/64x64/apps:
total 4
-rw-r--r-- 1 Mark None 3807 Sep 2 11:26 qemu.png
/home/Mark/rel-qemu-git/qemu/icons/hicolor/scalable:
total 0
drwxr-xr-x 1 Mark None 0 Sep 2 11:26 apps
/home/Mark/rel-qemu-git/qemu/icons/hicolor/scalable/apps:
total 32
-rw-r--r-- 1 Mark None 30955 Sep 2 11:26 qemu.svg
/home/Mark/rel-qemu-git/qemu/keymaps:
total 12
-rw-r--r-- 1 Mark None 4632 Aug 23 21:31 sl -rw-r--r-- 1 Mark None 3346 Aug 23 21:31 sv
The main issues I can see are that the .exe files end up under /msys64/qemu and the ROMs end up directly under /qemu rather than in $DESTDIR/share.
Do we know why there is also a qemu-system-ppcw.exe that appears?
ATB,
Mark.
Quoted 4 lines · Mark Cave-Ayland
The main issues I can see are that the .exe files end up under /msys64/qemu and the ROMs end up directly under /qemu rather than in $DESTDIR/share.
Do we know why there is also a qemu-system-ppcw.exe that appears?
The other thing to bear in mind is I may have made a mistake patching up patch 13 by hand - could you push a rebased version to a branch somewhere for me to test?
ATB,
Mark.
Quoted 2 lines · Mark Cave-Ayland
The main issues I can see are that the .exe files end up under /msys64/qemu and the ROMs end up directly under /qemu rather than in $DESTDIR/share.
This series doesn't try to change the layout; it only makes it possible to do so (because QEMU is now able to look for ROMs relative to the executable).
Just to be on the same page, how did you run "configure"?
Quoted 1 line
Do we know why there is also a qemu-system-ppcw.exe that appears?
That executable doesn't bring up a console window.
Paolo
Quoted 9 lines · Paolo Bonzini
Quoted 2 lines · Mark Cave-Ayland
The main issues I can see are that the .exe files end up under /msys64/qemu and the ROMs end up directly under /qemu rather than in $DESTDIR/share.
This series doesn't try to change the layout; it only makes it possible to do so (because QEMU is now able to look for ROMs relative to the executable).
Just to be on the same page, how did you run "configure"?
Ah okay. It was something simple like:
./configure --target-list="ppc-softmmu" --ninja=ninja make V=1 DESTDIR=/home/Mark/rel-qemu-git install
A quick test shows that I can move qemu-system-ppc.exe to a new directory and as long as the pc-bios directory is in the same place then it will work fine.
Quoted 3 lines
Quoted 1 line
Do we know why there is also a qemu-system-ppcw.exe that appears?
That executable doesn't bring up a console window.
From what I can see neither executable brings up a console window here. I have a vague memory that mingw needs an extra flag/change of link options for this to work compared to cygwin but it could use some investigation (for example qemu-system-ppc.exe just hangs if the pc-bios directory is missing).
ATB,
Mark.
Il mer 2 set 2020, 20:45 Mark Cave-Ayland <[email protected]> ha scritto:
Quoted 11 lines · Paolo Bonzini
Quoted 3 lines · Mark Cave-Ayland
Quoted 1 line
The main issues I can see are that the .exe files end up under
/msys64/qemu
Quoted 6 lines
Quoted 1 line
and the ROMs end up directly under /qemu rather than in $DESTDIR/share.
This series doesn't try to change the layout; it only makes it possible to do so (because QEMU is now able to look for ROMs relative to the executable).
Quoted 6 lines
Quoted 1 line
Just to be on the same page, how did you run "configure"?
Ah okay. It was something simple like:
./configure --target-list="ppc-softmmu" --ninja=ninja make V=1 DESTDIR=/home/Mark/rel-qemu-git install
That msys64 in the installation prefix is strange though. Can you send the content of meson-logs directory?
Paolo