From: Thomas Huth <thuth@redhat.com>
In the future, we might want to avoid compiling certain targets separately
for 32-bit mode (i.e. -i386, -arm and -ppc) where the 64-bit variant is a
superset of the 32-bit variant. But it would be good to provide a way to
mimic the 32-bit behavior via the program name in case the users need this
compatibility for some scenarios. Thus add a function that checks
for the old 32-bit program names and sets a flag accordingly.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
include/qemu/target-info.h | 7 +++++++
system/vl.c | 1 +
target-info.c | 20 ++++++++++++++++++--
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h
index 0713ab4bb16..aa9b2e9b0cf 100644
--- a/include/qemu/target-info.h
+++ b/include/qemu/target-info.h
@@ -9,6 +9,13 @@
#ifndef QEMU_TARGET_INFO_H
#define QEMU_TARGET_INFO_H
+/**
+ * target_info_adjust:
+ *
+ * Returns: Adjust the target according to the binary name of the executable.
+ */
+void target_info_adjust(const char *argv0);
+
/**
* target_name:
*
diff --git a/system/vl.c b/system/vl.c
index 246623b3196..45c9f5d5c7a 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2884,6 +2884,7 @@ void qemu_init(int argc, char **argv)
error_init(argv[0]);
qemu_init_exec_dir(argv[0]);
+ target_info_adjust(argv[0]);
os_setup_limits();
diff --git a/target-info.c b/target-info.c
index dea73b5fbca..b18fd4e0060 100644
--- a/target-info.c
+++ b/target-info.c
@@ -12,6 +12,21 @@
#include "qemu/target-info-impl.h"
#include "qapi/error.h"
+static bool force_32bit;
+
+void target_info_adjust(const char *argv0)
+{
+ switch (target_arch()) {
+ case SYS_EMU_TARGET_X86_64:
+ if (g_str_has_suffix(argv0, "-i386")) {
+ force_32bit = true;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
const char *target_name(void)
{
return target_info()->target_name;
@@ -107,10 +122,11 @@ bool target_base_x86(void)
bool target_i386(void)
{
- return target_arch() == SYS_EMU_TARGET_I386;
+ return target_arch() == SYS_EMU_TARGET_I386 ||
+ (target_arch() == SYS_EMU_TARGET_X86_64 && force_32bit);
}
bool target_x86_64(void)
{
- return target_arch() == SYS_EMU_TARGET_X86_64;
+ return target_arch() == SYS_EMU_TARGET_X86_64 && !force_32bit;
}
--
2.53.0