target-info-qom: detect target from QOM
For now, we expect only one target to be available at runtime. This will change with the single-binary and we'll detect which one to use dynamically. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260514172303.1484273-5-pierrick.bouvier@oss.qualcomm.com Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Pierrick Bouvier committed
May 14, 2026 at 10:23 UTC
20a1a1579a32c4d12753e73af4beae53b4c12293
4 files changed
+22
include/qemu/target-info-qom.h
+2
@@ -25,4 +25,6 @@ typedef struct TargetInfoQomClass {
25
26
OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
27
28
+void target_info_qom_set_target(void);
29
+
30
#endif /* QEMU_TARGET_INFO_QOM_H */
system/vl.c
+2
@@ -28,6 +28,7 @@
28
#include "qemu/units.h"
29
#include "qemu/module.h"
30
#include "qemu/target-info.h"
31
+#include "qemu/target-info-qom.h"
32
#include "exec/cpu-common.h"
33
#include "exec/page-vary.h"
34
#include "hw/core/qdev-properties.h"
@@ -2890,6 +2891,7 @@ void qemu_init(int argc, char **argv)
2891
os_setup_limits();
2892
2893
module_call_init(MODULE_INIT_TARGET_INFO);
2894
+ target_info_qom_set_target();
2895
2896
module_init_info(qemu_modinfo);
2897
module_allow_arch(target_name());
target-info-qom.c
+16
@@ -46,3 +46,19 @@ static const TypeInfo target_info_parent_type = {
46
};
47
48
DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
49
+
50
+static const TargetInfo *target_info_ptr;
51
+
52
+void target_info_qom_set_target(void)
53
+{
54
+ g_autoptr(GSList) targets = object_class_get_list(TYPE_TARGET_INFO, false);
55
+
56
+ size_t num_found = g_slist_length(targets);
57
+ if (num_found != 1) {
58
+ error_setg(&error_fatal, num_found == 0 ?
59
+ "no target-info is available" :
60
+ "more than one target-info is available");
61
+ }
62
+
63
+ target_info_ptr = TARGET_INFO_CLASS(targets->data)->target_info;
64
+}
tests/qtest/fuzz/fuzz.c
+2
@@ -22,6 +22,7 @@
22
#include "system/runstate.h"
23
#include "qemu/main-loop.h"
24
#include "qemu/rcu.h"
25
+#include "qemu/target-info-qom.h"
26
#include "tests/qtest/libqtest.h"
27
#include "tests/qtest/libqos/qgraph.h"
28
#include "fuzz.h"
@@ -173,6 +174,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
174
/* Initialize qgraph and modules */
175
qos_graph_init();
176
module_call_init(MODULE_INIT_TARGET_INFO);
177
+ target_info_qom_set_target();
178
module_call_init(MODULE_INIT_FUZZ_TARGET);
179
module_call_init(MODULE_INIT_QOM);
180
module_call_init(MODULE_INIT_LIBQOS);