Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
 system/vl.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/system/vl.c b/system/vl.c
index d8a0fe713c9..554f5f2a467 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -27,6 +27,8 @@
 #include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qemu/module.h"
+#include "qemu/target_info.h"
+#include "qemu/target_info-qom.h"
 #include "exec/cpu-common.h"
 #include "exec/page-vary.h"
 #include "hw/qdev-properties.h"
@@ -833,14 +835,29 @@ static bool usb_parse(const char *cmdline, Error **errp)
 /***********************************************************/
 /* machine registration */
 
+static char *machine_binary_filter(void)
+{
+    if (target_info_is_stub()) {
+        return NULL;
+    }
+    return g_strconcat(TYPE_LEGACY_BINARY_PREFIX,
+                       "qemu-system-", target_name(), NULL);
+}
+
 static MachineClass *find_machine(const char *name, GSList *machines)
 {
     GSList *el;
+    g_autofree char *binary_filter = machine_binary_filter();
 
     for (el = machines; el; el = el->next) {
         MachineClass *mc = el->data;
 
         if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
+            if (binary_filter && !object_class_dynamic_cast(el->data,
+                                                            binary_filter)) {
+                /* Machine is not for this binary: fail */
+                return NULL;
+            }
             return mc;
         }
     }
@@ -1563,6 +1580,7 @@ static void machine_help_func(const QDict *qdict)
     g_autoptr(GSList) machines = NULL;
     GSList *el;
     const char *type = qdict_get_try_str(qdict, "type");
+    g_autofree char *binary_filter = machine_binary_filter();
 
     machines = object_class_get_list(TYPE_MACHINE, false);
     if (type) {
@@ -1577,6 +1595,12 @@ static void machine_help_func(const QDict *qdict)
     machines = g_slist_sort(machines, machine_class_cmp);
     for (el = machines; el; el = el->next) {
         MachineClass *mc = el->data;
+
+        if (binary_filter && !object_class_dynamic_cast(el->data,
+                                                        binary_filter)) {
+            /* Machine is not for this binary: skip */
+            continue;
+        }
         if (mc->alias) {
             printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
         }
-- 
2.47.1


Reply via email to