aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2023-10-05 14:19:34 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2023-10-18 10:00:57 +0200
commit655e2a778dd701822bbe0bf90dad74c25bb05e49 (patch)
tree099b463aeb9098db4ed4de8f93bdbb7398135251 /util
parent230f6e06b83474314898f27c0a7b2f0593071875 (diff)
meson, cutils: allow non-relocatable installs
Say QEMU is configured with bindir = "/usr/bin" and a firmware path that starts with "/usr/share/qemu". Ever since QEMU 5.2, QEMU's install has been relocatable: if you move qemu-system-x86_64 from /usr/bin to /home/username/bin, it will start looking for firmware in /home/username/share/qemu. Previously, you would get a non-relocatable install where the moved QEMU will keep looking for firmware in /usr/share/qemu. Windows almost always wants relocatable installs, and in fact that is why QEMU 5.2 introduced relocatability in the first place. However, newfangled distribution mechanisms such as AppImage (https://docs.appimage.org/reference/best-practices.html), and possibly NixOS, also dislike using at runtime the absolute paths that were established at build time. On POSIX systems you almost never care; if you do, your usecase dictates which one is desirable, so there's no single answer. Obviously relocatability works fine most of the time, because not many people have complained about QEMU's switch to relocatable install, and that's why until now there was no way to disable relocatability. But a non-relocatable, non-modular binary can help if you want to do experiments with old firmware and new QEMU or vice versa (because you can just upgrade/downgrade the firmware package, and use rpm2cpio or similar to extract the QEMU binaries outside /usr), so allow both. This patch allows one to build a non-relocatable install using a new option to configure. Why? Because it's not too hard, and because it helps the user double check the relocatability of their install. Note that the same code that handles relocation also lets you run QEMU from the build tree and pick e.g. firmware files from the source tree transparently. Therefore that part remains active with this patch, even if you configure with --disable-relocatable. Suggested-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Emmanouil Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/cutils.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/util/cutils.c b/util/cutils.c
index c99d26c5e2..64f817b477 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1178,9 +1178,11 @@ char *get_relocated_path(const char *dir)
#else
g_string_append(result, dir);
#endif
- } else if (!starts_with_prefix(dir) || !starts_with_prefix(bindir)) {
- g_string_assign(result, dir);
- } else {
+ goto out;
+ }
+
+ if (IS_ENABLED(CONFIG_RELOCATABLE) &&
+ starts_with_prefix(dir) && starts_with_prefix(bindir)) {
g_string_assign(result, exec_dir);
/* Advance over common components. */
@@ -1203,7 +1205,10 @@ char *get_relocated_path(const char *dir)
assert(G_IS_DIR_SEPARATOR(dir[-1]));
g_string_append(result, dir - 1);
}
+ goto out;
}
+ g_string_assign(result, dir);
+out:
return g_string_free(result, false);
}