* [PATCH v5 0/6] single-binary: deduplicate target_info()
@ 2026-05-09 0:54 Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 1/6] qom/object: register OBJECT and INTERFACE QOM types before main Pierrick Bouvier
` (6 more replies)
0 siblings, 7 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 0:54 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Pierrick Bouvier,
Anton Johansson
We are getting close to be able to link several targets in a single QEMU system
binary, and the last obstacle on the road is to embed several TargetInfo in the
same binary. The end result of this series is to have a single definition for
target_info symbol.
This series adds TargetInfo types in QOM, and retrieve them dynamically(). At
the moment, we don't deal yet with multiple TargetInfo selection, but install
all that is needed to be able to do it easily.
Because TargetInfo data is set through class_init, it creates an issue at
startup, where we may try to instantiate additional (unrelated) types just to
retrieve the list of "target-info-X" types. Those other types class_init may be
using target information, to add target specific properties for instance.
This issue has been fixed by adding a new object_class_get_list_by_name_prefix
that does not force instantiation of all QOM types, but only those matching a
specific pattern. This way, we first initialize and retrieve target-info types
before others.
An alternative would be to leave all this out of QOM, and use startup
initializer to add them in a single list. However, because all the single-binary
work has been using QOM where possible, it would be really sad to not use it for
this final step. Comments are welcome!
Finally, sticking to our promise not create a special "single-binary
configuration", the goal is to use the *exact* same codepath for normal binaries
also. It means that even for existing system binaries, the goal will be to use
QOM to retrieve current target, even if there is only one.
v5
--
- Fix header guard name for target-info-init.h
(TARGET_INFO_INIT_H -> QEMU_TARGET_INFO_INIT_H)
- add a new patch to initialize type_table with TYPE_OBJECT and TYPE_INTERFACE,
as suggested by Richard
- use a single class_init for all target-info-* classes.
v4
--
- Revert to v2 MODULE_INIT_TARGET_INFO as Daniel didn't comment on issues about
about MODULE_INIT_QOM_EARLY.
v3
--
- fix rebase mistake for one header guard
- remove MODULE_INIT_TARGET_INFO and introduce MODULE_INIT_QOM_EARLY, as
requested by Daniel
v2
--
- fix header guards
- introduce new module init step (MODULE_INIT_TARGET_INFO)
- as a consequence of item above, we need to register TYPE_OBJECT before startup
- fix xtensa core type registration using type_init instead of static ctor
Pierrick Bouvier (6):
qom/object: register OBJECT and INTERFACE QOM types before main
qom/object: initialize type_table in static ctor with fundamental QOM
types
target-info: extract target_info() definition in target-info-init.h
target-info-qom: detect target from QOM
target-info: replace target_info() in system-mode
target-info-qom: use a single class_init for target-info-* classes
configs/targets/aarch64-softmmu.c | 6 +--
configs/targets/arm-softmmu.c | 6 +--
include/qemu/module.h | 1 +
include/qemu/target-info-init.h | 63 +++++++++++++++++++++++++++++++
include/qemu/target-info-qom.h | 31 +++++++++++++++
qom/object.c | 22 +++--------
system/vl.c | 4 ++
target-info-qom.c | 41 ++++++++++++++++++++
target-info-stub.c | 6 +--
9 files changed, 152 insertions(+), 28 deletions(-)
create mode 100644 include/qemu/target-info-init.h
create mode 100644 include/qemu/target-info-qom.h
--
2.43.0
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v5 1/6] qom/object: register OBJECT and INTERFACE QOM types before main
2026-05-09 0:54 [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
@ 2026-05-09 0:54 ` Pierrick Bouvier
2026-05-11 10:24 ` Philippe Mathieu-Daudé
2026-05-09 0:54 ` [PATCH v5 2/6] qom/object: initialize type_table in static ctor with fundamental QOM types Pierrick Bouvier
` (5 subsequent siblings)
6 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 0:54 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Pierrick Bouvier,
Anton Johansson
Those types are special, as they are the base of all other QOM types. In
next commit, we'll introduce an extra step in module initialization for
target-info-* types.
However, those types depend on TYPE_OBJECT, which is only registered
at MODULE_INIT_QOM step.
To avoid having to introduce another step, and modify all code calling
module_call_init(MODULE_INIT_QOM), we simply register those base types
directly in the static constructor, before anything else.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
qom/object.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index f981e270440..a5d268d0722 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2839,7 +2839,7 @@ static void object_class_init(ObjectClass *klass, const void *data)
NULL);
}
-static void register_types(void)
+static void __attribute__((constructor)) register_types(void)
{
static const TypeInfo interface_info = {
.name = TYPE_INTERFACE,
@@ -2857,5 +2857,3 @@ static void register_types(void)
type_interface = type_register_internal(&interface_info);
type_register_internal(&object_info);
}
-
-type_init(register_types)
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v5 2/6] qom/object: initialize type_table in static ctor with fundamental QOM types
2026-05-09 0:54 [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 1/6] qom/object: register OBJECT and INTERFACE QOM types before main Pierrick Bouvier
@ 2026-05-09 0:54 ` Pierrick Bouvier
2026-05-09 14:21 ` Richard Henderson
2026-05-11 10:25 ` Philippe Mathieu-Daudé
2026-05-09 0:54 ` [PATCH v5 3/6] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
` (4 subsequent siblings)
6 siblings, 2 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 0:54 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Pierrick Bouvier,
Anton Johansson
This saves us having to check if it's initialized everytime we have to
access it. No other QOM type should be initialized or accessed during
static ctor calls, so we don't depend on their ordering.
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
qom/object.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index a5d268d0722..bd48f22bb00 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -76,28 +76,19 @@ struct TypeImpl
static Type type_interface;
-static GHashTable *type_table_get(void)
-{
- static GHashTable *type_table;
-
- if (type_table == NULL) {
- type_table = g_hash_table_new(g_str_hash, g_str_equal);
- }
-
- return type_table;
-}
+static GHashTable *type_table;
static bool enumerating_types;
static void type_table_add(TypeImpl *ti)
{
assert(!enumerating_types);
- g_hash_table_insert(type_table_get(), (void *)ti->name, ti);
+ g_hash_table_insert(type_table, (void *)ti->name, ti);
}
static TypeImpl *type_table_lookup(const char *name)
{
- return g_hash_table_lookup(type_table_get(), name);
+ return g_hash_table_lookup(type_table, name);
}
static TypeImpl *type_new(const TypeInfo *info)
@@ -1069,7 +1060,7 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
OCFData data = { fn, implements_type, include_abstract, opaque };
enumerating_types = true;
- g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &data);
+ g_hash_table_foreach(type_table, object_class_foreach_tramp, &data);
enumerating_types = false;
}
@@ -2854,6 +2845,7 @@ static void __attribute__((constructor)) register_types(void)
.abstract = true,
};
+ type_table = g_hash_table_new(g_str_hash, g_str_equal);
type_interface = type_register_internal(&interface_info);
type_register_internal(&object_info);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v5 3/6] target-info: extract target_info() definition in target-info-init.h
2026-05-09 0:54 [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 1/6] qom/object: register OBJECT and INTERFACE QOM types before main Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 2/6] qom/object: initialize type_table in static ctor with fundamental QOM types Pierrick Bouvier
@ 2026-05-09 0:54 ` Pierrick Bouvier
2026-05-09 15:01 ` Richard Henderson
2026-05-09 0:54 ` [PATCH v5 4/6] target-info-qom: detect target from QOM Pierrick Bouvier
` (3 subsequent siblings)
6 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 0:54 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Pierrick Bouvier,
Anton Johansson
This allows us to prepare next commits, which will introduce qom
registration for system mode.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
configs/targets/aarch64-softmmu.c | 6 +--
configs/targets/arm-softmmu.c | 6 +--
include/qemu/module.h | 1 +
include/qemu/target-info-init.h | 78 +++++++++++++++++++++++++++++++
include/qemu/target-info-qom.h | 28 +++++++++++
system/vl.c | 2 +
target-info-qom.c | 14 ++++++
target-info-stub.c | 6 +--
8 files changed, 129 insertions(+), 12 deletions(-)
create mode 100644 include/qemu/target-info-init.h
create mode 100644 include/qemu/target-info-qom.h
diff --git a/configs/targets/aarch64-softmmu.c b/configs/targets/aarch64-softmmu.c
index 82ccb575759..75d95b0e743 100644
--- a/configs/targets/aarch64-softmmu.c
+++ b/configs/targets/aarch64-softmmu.c
@@ -8,6 +8,7 @@
#include "qemu/osdep.h"
#include "qemu/target-info-impl.h"
+#include "qemu/target-info-init.h"
#include "hw/arm/machines-qom.h"
#include "target/arm/cpu-qom.h"
#include "target/arm/cpu-param.h"
@@ -23,7 +24,4 @@ static const TargetInfo target_info_aarch64_system = {
.page_bits_init = TARGET_PAGE_BITS_LEGACY,
};
-const TargetInfo *target_info(void)
-{
- return &target_info_aarch64_system;
-}
+target_info_init(target_info_aarch64_system)
diff --git a/configs/targets/arm-softmmu.c b/configs/targets/arm-softmmu.c
index 18940e51e55..73546fa5737 100644
--- a/configs/targets/arm-softmmu.c
+++ b/configs/targets/arm-softmmu.c
@@ -8,6 +8,7 @@
#include "qemu/osdep.h"
#include "qemu/target-info-impl.h"
+#include "qemu/target-info-init.h"
#include "hw/arm/machines-qom.h"
#include "target/arm/cpu-qom.h"
#include "target/arm/cpu-param.h"
@@ -23,7 +24,4 @@ static const TargetInfo target_info_arm_system = {
.page_bits_init = TARGET_PAGE_BITS_LEGACY,
};
-const TargetInfo *target_info(void)
-{
- return &target_info_arm_system;
-}
+target_info_init(target_info_arm_system)
diff --git a/include/qemu/module.h b/include/qemu/module.h
index 9885ac9afb3..fccf017bf9e 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -43,6 +43,7 @@ typedef enum {
MODULE_INIT_MIGRATION,
MODULE_INIT_BLOCK,
MODULE_INIT_OPTS,
+ MODULE_INIT_TARGET_INFO,
MODULE_INIT_QOM,
MODULE_INIT_TRACE,
MODULE_INIT_XEN_BACKEND,
diff --git a/include/qemu/target-info-init.h b/include/qemu/target-info-init.h
new file mode 100644
index 00000000000..3f4eda19083
--- /dev/null
+++ b/include/qemu/target-info-init.h
@@ -0,0 +1,78 @@
+/*
+ * QEMU target info initialization
+ *
+ * Copyright (c) Qualcomm
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This file is included by each file defining a TargetInfo structure and is
+ * responsible for registering it.
+ */
+
+#ifndef QEMU_TARGET_INFO_INIT_H
+#define QEMU_TARGET_INFO_INIT_H
+
+#define DEFINE_TARGET_INFO_TYPE(info) \
+static void do_qemu_init_target_info(void) \
+{ \
+ type_register_static(&info); \
+} \
+module_init(do_qemu_init_target_info, MODULE_INIT_TARGET_INFO)
+
+#ifdef COMPILING_PER_TARGET
+#ifdef CONFIG_USER_ONLY
+
+/*
+ * User mode does not support multiple targets in the same binary, so just
+ * define target_info().
+ */
+#define target_info_init(ti_var) \
+const TargetInfo *target_info(void) \
+{ \
+ return &ti_var; \
+}
+
+#else /* CONFIG_USER_ONLY */
+
+#include "qemu/target-info-qom.h"
+#include "qom/object.h"
+
+#define TYPE_TARGET_INFO_TARGET TYPE_TARGET_INFO"-"TARGET_NAME
+
+typedef struct TargetInfoQomTarget {
+ TargetInfoQom parent;
+} TargetInfoQomTarget;
+
+typedef struct TargetInfoQomTargetClass {
+ TargetInfoQomClass parent_class;
+} TargetInfoQomTargetClass;
+
+OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass, TARGET_INFO_TARGET)
+
+#define target_info_init(ti_var) \
+const TargetInfo *target_info(void) \
+{ \
+ return &ti_var; \
+} \
+ \
+static void target_info_qom_class_init(ObjectClass *oc, const void * data) \
+{ \
+ TargetInfoQomTargetClass *klass = TARGET_INFO_TARGET_CLASS(oc); \
+ klass->parent_class.target_info = &ti_var; \
+} \
+ \
+static const TypeInfo target_info_qom_target_type_info = { \
+ .name = TYPE_TARGET_INFO_TARGET, \
+ .parent = TYPE_TARGET_INFO, \
+ .instance_size = sizeof(TargetInfoQomTarget), \
+ .class_size = sizeof(TargetInfoQomTargetClass), \
+ .class_init = target_info_qom_class_init, \
+ .abstract = false, \
+}; \
+ \
+DEFINE_TARGET_INFO_TYPE(target_info_qom_target_type_info)
+
+#endif /* CONFIG_USER_ONLY */
+#endif /* COMPILING_PER_TARGET */
+
+#endif /* QEMU_TARGET_INFO_INIT_H */
diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
new file mode 100644
index 00000000000..585995c7ad0
--- /dev/null
+++ b/include/qemu/target-info-qom.h
@@ -0,0 +1,28 @@
+/*
+ * QEMU target info QOM types
+ *
+ * Copyright (c) Qualcomm
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_TARGET_INFO_QOM_H
+#define QEMU_TARGET_INFO_QOM_H
+
+#include "qemu/target-info-impl.h"
+#include "qom/object.h"
+
+#define TYPE_TARGET_INFO "target-info"
+
+typedef struct TargetInfoQom {
+ Object parent_obj;
+} TargetInfoQom;
+
+typedef struct TargetInfoQomClass {
+ ObjectClass parent_class;
+ const TargetInfo *target_info;
+} TargetInfoQomClass;
+
+OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
+
+#endif /* QEMU_TARGET_INFO_QOM_H */
diff --git a/system/vl.c b/system/vl.c
index d2f4044e5d8..e44da0941d4 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2889,6 +2889,8 @@ void qemu_init(int argc, char **argv)
os_setup_limits();
+ module_call_init(MODULE_INIT_TARGET_INFO);
+
module_init_info(qemu_modinfo);
module_allow_arch(target_name());
diff --git a/target-info-qom.c b/target-info-qom.c
index 7fd58d24818..ba2c7923760 100644
--- a/target-info-qom.c
+++ b/target-info-qom.c
@@ -7,7 +7,11 @@
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "qom/object.h"
+#include "qemu/target-info-impl.h"
+#include "qemu/target-info-init.h"
+#include "qemu/target-info-qom.h"
#include "hw/arm/machines-qom.h"
static const TypeInfo target_info_types[] = {
@@ -22,3 +26,13 @@ static const TypeInfo target_info_types[] = {
};
DEFINE_TYPES(target_info_types)
+
+static const TypeInfo target_info_parent_type = {
+ .name = TYPE_TARGET_INFO,
+ .parent = TYPE_OBJECT,
+ .instance_size = sizeof(TargetInfoQom),
+ .class_size = sizeof(TargetInfoQomClass),
+ .abstract = true,
+};
+
+DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
diff --git a/target-info-stub.c b/target-info-stub.c
index 07d8647ed8e..22b7911201c 100644
--- a/target-info-stub.c
+++ b/target-info-stub.c
@@ -9,6 +9,7 @@
#include "qemu/osdep.h"
#include "qemu/target-info.h"
#include "qemu/target-info-impl.h"
+#include "qemu/target-info-init.h"
#include "hw/core/boards.h"
#include "cpu.h"
#include "exec/cpu-defs.h"
@@ -41,7 +42,4 @@ static const TargetInfo target_info_stub = {
#endif
};
-const TargetInfo *target_info(void)
-{
- return &target_info_stub;
-}
+target_info_init(target_info_stub)
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v5 4/6] target-info-qom: detect target from QOM
2026-05-09 0:54 [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
` (2 preceding siblings ...)
2026-05-09 0:54 ` [PATCH v5 3/6] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
@ 2026-05-09 0:54 ` Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 5/6] target-info: replace target_info() in system-mode Pierrick Bouvier
` (2 subsequent siblings)
6 siblings, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 0:54 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Pierrick Bouvier,
Anton Johansson
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>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
include/qemu/target-info-qom.h | 2 ++
system/vl.c | 2 ++
target-info-qom.c | 16 ++++++++++++++++
3 files changed, 20 insertions(+)
diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
index 585995c7ad0..91be415ed33 100644
--- a/include/qemu/target-info-qom.h
+++ b/include/qemu/target-info-qom.h
@@ -25,4 +25,6 @@ typedef struct TargetInfoQomClass {
OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
+void target_info_qom_set_target(void);
+
#endif /* QEMU_TARGET_INFO_QOM_H */
diff --git a/system/vl.c b/system/vl.c
index e44da0941d4..e690aa3ed8c 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -28,6 +28,7 @@
#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/core/qdev-properties.h"
@@ -2890,6 +2891,7 @@ void qemu_init(int argc, char **argv)
os_setup_limits();
module_call_init(MODULE_INIT_TARGET_INFO);
+ target_info_qom_set_target();
module_init_info(qemu_modinfo);
module_allow_arch(target_name());
diff --git a/target-info-qom.c b/target-info-qom.c
index ba2c7923760..9d1f50ffcab 100644
--- a/target-info-qom.c
+++ b/target-info-qom.c
@@ -36,3 +36,19 @@ static const TypeInfo target_info_parent_type = {
};
DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
+
+static const TargetInfo *target_info_ptr;
+
+void target_info_qom_set_target(void)
+{
+ g_autoptr(GSList) targets = object_class_get_list(TYPE_TARGET_INFO, false);
+
+ size_t num_found = g_slist_length(targets);
+ if (num_found != 1) {
+ error_setg(&error_fatal, num_found == 0 ?
+ "no target-info is available" :
+ "more than one target-info is available");
+ }
+
+ target_info_ptr = TARGET_INFO_CLASS(targets->data)->target_info;
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v5 5/6] target-info: replace target_info() in system-mode
2026-05-09 0:54 [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
` (3 preceding siblings ...)
2026-05-09 0:54 ` [PATCH v5 4/6] target-info-qom: detect target from QOM Pierrick Bouvier
@ 2026-05-09 0:54 ` Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 6/6] target-info-qom: use a single class_init for target-info-* classes Pierrick Bouvier
2026-05-12 15:03 ` [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
6 siblings, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 0:54 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Pierrick Bouvier,
Anton Johansson
We now can use TargetInfo information available from QOM, and remove
duplicated target_info() symbol.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
include/qemu/target-info-init.h | 5 -----
target-info-qom.c | 5 +++++
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/qemu/target-info-init.h b/include/qemu/target-info-init.h
index 3f4eda19083..176fd975a16 100644
--- a/include/qemu/target-info-init.h
+++ b/include/qemu/target-info-init.h
@@ -50,11 +50,6 @@ typedef struct TargetInfoQomTargetClass {
OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass, TARGET_INFO_TARGET)
#define target_info_init(ti_var) \
-const TargetInfo *target_info(void) \
-{ \
- return &ti_var; \
-} \
- \
static void target_info_qom_class_init(ObjectClass *oc, const void * data) \
{ \
TargetInfoQomTargetClass *klass = TARGET_INFO_TARGET_CLASS(oc); \
diff --git a/target-info-qom.c b/target-info-qom.c
index 9d1f50ffcab..cc470b3b4d6 100644
--- a/target-info-qom.c
+++ b/target-info-qom.c
@@ -39,6 +39,11 @@ DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
static const TargetInfo *target_info_ptr;
+const TargetInfo *target_info(void)
+{
+ return target_info_ptr;
+}
+
void target_info_qom_set_target(void)
{
g_autoptr(GSList) targets = object_class_get_list(TYPE_TARGET_INFO, false);
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v5 6/6] target-info-qom: use a single class_init for target-info-* classes
2026-05-09 0:54 [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
` (4 preceding siblings ...)
2026-05-09 0:54 ` [PATCH v5 5/6] target-info: replace target_info() in system-mode Pierrick Bouvier
@ 2026-05-09 0:54 ` Pierrick Bouvier
2026-05-09 0:59 ` Pierrick Bouvier
2026-05-12 15:03 ` [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
6 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 0:54 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Pierrick Bouvier,
Anton Johansson
Instead of defining a class_init per class, just use a common
constructor and set class_data to corresponding TargetInfo structure.
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
include/qemu/target-info-init.h | 14 ++------------
include/qemu/target-info-qom.h | 1 +
target-info-qom.c | 6 ++++++
3 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/include/qemu/target-info-init.h b/include/qemu/target-info-init.h
index 176fd975a16..3945f2998e0 100644
--- a/include/qemu/target-info-init.h
+++ b/include/qemu/target-info-init.h
@@ -37,8 +37,6 @@ const TargetInfo *target_info(void) \
#include "qemu/target-info-qom.h"
#include "qom/object.h"
-#define TYPE_TARGET_INFO_TARGET TYPE_TARGET_INFO"-"TARGET_NAME
-
typedef struct TargetInfoQomTarget {
TargetInfoQom parent;
} TargetInfoQomTarget;
@@ -47,24 +45,16 @@ typedef struct TargetInfoQomTargetClass {
TargetInfoQomClass parent_class;
} TargetInfoQomTargetClass;
-OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass, TARGET_INFO_TARGET)
-
#define target_info_init(ti_var) \
-static void target_info_qom_class_init(ObjectClass *oc, const void * data) \
-{ \
- TargetInfoQomTargetClass *klass = TARGET_INFO_TARGET_CLASS(oc); \
- klass->parent_class.target_info = &ti_var; \
-} \
- \
static const TypeInfo target_info_qom_target_type_info = { \
- .name = TYPE_TARGET_INFO_TARGET, \
+ .name = TYPE_TARGET_INFO"-"TARGET_NAME, \
.parent = TYPE_TARGET_INFO, \
.instance_size = sizeof(TargetInfoQomTarget), \
.class_size = sizeof(TargetInfoQomTargetClass), \
.class_init = target_info_qom_class_init, \
+ .class_data = &ti_var, \
.abstract = false, \
}; \
- \
DEFINE_TARGET_INFO_TYPE(target_info_qom_target_type_info)
#endif /* CONFIG_USER_ONLY */
diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
index 91be415ed33..a37c3e101e0 100644
--- a/include/qemu/target-info-qom.h
+++ b/include/qemu/target-info-qom.h
@@ -25,6 +25,7 @@ typedef struct TargetInfoQomClass {
OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
+void target_info_qom_class_init(ObjectClass *oc, const void * data);
void target_info_qom_set_target(void);
#endif /* QEMU_TARGET_INFO_QOM_H */
diff --git a/target-info-qom.c b/target-info-qom.c
index cc470b3b4d6..5b0498ca654 100644
--- a/target-info-qom.c
+++ b/target-info-qom.c
@@ -37,6 +37,12 @@ static const TypeInfo target_info_parent_type = {
DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
+void target_info_qom_class_init(ObjectClass *oc, const void * data)
+{
+ TargetInfoQomClass *klass = TARGET_INFO_CLASS(oc);
+ klass->target_info = data;
+}
+
static const TargetInfo *target_info_ptr;
const TargetInfo *target_info(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v5 6/6] target-info-qom: use a single class_init for target-info-* classes
2026-05-09 0:54 ` [PATCH v5 6/6] target-info-qom: use a single class_init for target-info-* classes Pierrick Bouvier
@ 2026-05-09 0:59 ` Pierrick Bouvier
2026-05-09 15:03 ` Richard Henderson
0 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 0:59 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Anton Johansson
On 5/8/2026 5:54 PM, Pierrick Bouvier wrote:
> Instead of defining a class_init per class, just use a common
> constructor and set class_data to corresponding TargetInfo structure.
>
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> ---
> include/qemu/target-info-init.h | 14 ++------------
> include/qemu/target-info-qom.h | 1 +
> target-info-qom.c | 6 ++++++
> 3 files changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/include/qemu/target-info-init.h b/include/qemu/target-info-init.h
> index 176fd975a16..3945f2998e0 100644
> --- a/include/qemu/target-info-init.h
> +++ b/include/qemu/target-info-init.h
> @@ -37,8 +37,6 @@ const TargetInfo *target_info(void) \
> #include "qemu/target-info-qom.h"
> #include "qom/object.h"
>
> -#define TYPE_TARGET_INFO_TARGET TYPE_TARGET_INFO"-"TARGET_NAME
> -
> typedef struct TargetInfoQomTarget {
> TargetInfoQom parent;
> } TargetInfoQomTarget;
> @@ -47,24 +45,16 @@ typedef struct TargetInfoQomTargetClass {
> TargetInfoQomClass parent_class;
> } TargetInfoQomTargetClass;
>
> -OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass, TARGET_INFO_TARGET)
> -
> #define target_info_init(ti_var) \
> -static void target_info_qom_class_init(ObjectClass *oc, const void * data) \
> -{ \
> - TargetInfoQomTargetClass *klass = TARGET_INFO_TARGET_CLASS(oc); \
> - klass->parent_class.target_info = &ti_var; \
> -} \
> - \
> static const TypeInfo target_info_qom_target_type_info = { \
> - .name = TYPE_TARGET_INFO_TARGET, \
> + .name = TYPE_TARGET_INFO"-"TARGET_NAME, \
> .parent = TYPE_TARGET_INFO, \
> .instance_size = sizeof(TargetInfoQomTarget), \
> .class_size = sizeof(TargetInfoQomTargetClass), \
> .class_init = target_info_qom_class_init, \
> + .class_data = &ti_var, \
> .abstract = false, \
> }; \
> - \
> DEFINE_TARGET_INFO_TYPE(target_info_qom_target_type_info)
>
> #endif /* CONFIG_USER_ONLY */
> diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
> index 91be415ed33..a37c3e101e0 100644
> --- a/include/qemu/target-info-qom.h
> +++ b/include/qemu/target-info-qom.h
> @@ -25,6 +25,7 @@ typedef struct TargetInfoQomClass {
>
> OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
>
> +void target_info_qom_class_init(ObjectClass *oc, const void * data);
> void target_info_qom_set_target(void);
>
> #endif /* QEMU_TARGET_INFO_QOM_H */
> diff --git a/target-info-qom.c b/target-info-qom.c
> index cc470b3b4d6..5b0498ca654 100644
> --- a/target-info-qom.c
> +++ b/target-info-qom.c
> @@ -37,6 +37,12 @@ static const TypeInfo target_info_parent_type = {
>
> DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
>
> +void target_info_qom_class_init(ObjectClass *oc, const void * data)
> +{
> + TargetInfoQomClass *klass = TARGET_INFO_CLASS(oc);
> + klass->target_info = data;
> +}
> +
> static const TargetInfo *target_info_ptr;
>
> const TargetInfo *target_info(void)
This patch can be squashed with 3, but I thought it might be better for
review to keep it on top for now.
Regards,
Pierrick
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v5 2/6] qom/object: initialize type_table in static ctor with fundamental QOM types
2026-05-09 0:54 ` [PATCH v5 2/6] qom/object: initialize type_table in static ctor with fundamental QOM types Pierrick Bouvier
@ 2026-05-09 14:21 ` Richard Henderson
2026-05-11 10:25 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 16+ messages in thread
From: Richard Henderson @ 2026-05-09 14:21 UTC (permalink / raw)
To: Pierrick Bouvier, qemu-devel
Cc: Daniel P. Berrangé, Marc-André Lureau,
Markus Armbruster, Max Filippov, Paolo Bonzini,
Philippe Mathieu-Daudé, Anton Johansson
On 5/8/26 19:54, Pierrick Bouvier wrote:
> This saves us having to check if it's initialized everytime we have to
> access it. No other QOM type should be initialized or accessed during
> static ctor calls, so we don't depend on their ordering.
>
> Suggested-by: Richard Henderson<richard.henderson@linaro.org>
> Signed-off-by: Pierrick Bouvier<pierrick.bouvier@oss.qualcomm.com>
> ---
> qom/object.c | 18 +++++-------------
> 1 file changed, 5 insertions(+), 13 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v5 3/6] target-info: extract target_info() definition in target-info-init.h
2026-05-09 0:54 ` [PATCH v5 3/6] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
@ 2026-05-09 15:01 ` Richard Henderson
2026-05-09 21:21 ` Pierrick Bouvier
0 siblings, 1 reply; 16+ messages in thread
From: Richard Henderson @ 2026-05-09 15:01 UTC (permalink / raw)
To: Pierrick Bouvier, qemu-devel
Cc: Daniel P. Berrangé, Marc-André Lureau,
Markus Armbruster, Max Filippov, Paolo Bonzini,
Philippe Mathieu-Daudé, Anton Johansson
On 5/8/26 19:54, Pierrick Bouvier wrote:
> +#define TYPE_TARGET_INFO_TARGET TYPE_TARGET_INFO"-"TARGET_NAME
I guess avoiding TARGET_NAME can wait until we actually build a single binary.
> +typedef struct TargetInfoQomTarget {
> + TargetInfoQom parent;
> +} TargetInfoQomTarget;
> +
> +typedef struct TargetInfoQomTargetClass {
> + TargetInfoQomClass parent_class;
> +} TargetInfoQomTargetClass;
> +
> +OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass, TARGET_INFO_TARGET)
Since neither the object nor class are actually used; you don't need these.
> +static void target_info_qom_class_init(ObjectClass *oc, const void * data) \
> +{ \
> + TargetInfoQomTargetClass *klass = TARGET_INFO_TARGET_CLASS(oc); \
> + klass->parent_class.target_info = &ti_var; \
> +} \
This belongs in vl.c as target_info_parent_type.class_base_init.
> +static const TypeInfo target_info_qom_target_type_info = { \
> + .name = TYPE_TARGET_INFO_TARGET, \
> + .parent = TYPE_TARGET_INFO, \
> + .instance_size = sizeof(TargetInfoQomTarget), \
> + .class_size = sizeof(TargetInfoQomTargetClass), \
> + .class_init = target_info_qom_class_init, \
> + .abstract = false, \
> +}; \
This reduces to just name, parent, and class_data.
You don't need sizes, class_init, or abstract.
r~
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v5 6/6] target-info-qom: use a single class_init for target-info-* classes
2026-05-09 0:59 ` Pierrick Bouvier
@ 2026-05-09 15:03 ` Richard Henderson
2026-05-09 21:29 ` Pierrick Bouvier
0 siblings, 1 reply; 16+ messages in thread
From: Richard Henderson @ 2026-05-09 15:03 UTC (permalink / raw)
To: Pierrick Bouvier, qemu-devel
Cc: Daniel P. Berrangé, Marc-André Lureau,
Markus Armbruster, Max Filippov, Paolo Bonzini,
Philippe Mathieu-Daudé, Anton Johansson
On 5/8/26 19:59, Pierrick Bouvier wrote:
> On 5/8/2026 5:54 PM, Pierrick Bouvier wrote:
>> Instead of defining a class_init per class, just use a common
>> constructor and set class_data to corresponding TargetInfo structure.
>>
>> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
>> ---
>> include/qemu/target-info-init.h | 14 ++------------
>> include/qemu/target-info-qom.h | 1 +
>> target-info-qom.c | 6 ++++++
>> 3 files changed, 9 insertions(+), 12 deletions(-)
>>
>> diff --git a/include/qemu/target-info-init.h b/include/qemu/target-info-init.h
>> index 176fd975a16..3945f2998e0 100644
>> --- a/include/qemu/target-info-init.h
>> +++ b/include/qemu/target-info-init.h
>> @@ -37,8 +37,6 @@ const TargetInfo *target_info(void) \
>> #include "qemu/target-info-qom.h"
>> #include "qom/object.h"
>>
>> -#define TYPE_TARGET_INFO_TARGET TYPE_TARGET_INFO"-"TARGET_NAME
>> -
>> typedef struct TargetInfoQomTarget {
>> TargetInfoQom parent;
>> } TargetInfoQomTarget;
>> @@ -47,24 +45,16 @@ typedef struct TargetInfoQomTargetClass {
>> TargetInfoQomClass parent_class;
>> } TargetInfoQomTargetClass;
>>
>> -OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass, TARGET_INFO_TARGET)
>> -
>> #define target_info_init(ti_var) \
>> -static void target_info_qom_class_init(ObjectClass *oc, const void * data) \
>> -{ \
>> - TargetInfoQomTargetClass *klass = TARGET_INFO_TARGET_CLASS(oc); \
>> - klass->parent_class.target_info = &ti_var; \
>> -} \
>> - \
>> static const TypeInfo target_info_qom_target_type_info = { \
>> - .name = TYPE_TARGET_INFO_TARGET, \
>> + .name = TYPE_TARGET_INFO"-"TARGET_NAME, \
>> .parent = TYPE_TARGET_INFO, \
>> .instance_size = sizeof(TargetInfoQomTarget), \
>> .class_size = sizeof(TargetInfoQomTargetClass), \
>> .class_init = target_info_qom_class_init, \
>> + .class_data = &ti_var, \
>> .abstract = false, \
>> }; \
>> - \
>> DEFINE_TARGET_INFO_TYPE(target_info_qom_target_type_info)
>>
>> #endif /* CONFIG_USER_ONLY */
>> diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
>> index 91be415ed33..a37c3e101e0 100644
>> --- a/include/qemu/target-info-qom.h
>> +++ b/include/qemu/target-info-qom.h
>> @@ -25,6 +25,7 @@ typedef struct TargetInfoQomClass {
>>
>> OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
>>
>> +void target_info_qom_class_init(ObjectClass *oc, const void * data);
>> void target_info_qom_set_target(void);
>>
>> #endif /* QEMU_TARGET_INFO_QOM_H */
>> diff --git a/target-info-qom.c b/target-info-qom.c
>> index cc470b3b4d6..5b0498ca654 100644
>> --- a/target-info-qom.c
>> +++ b/target-info-qom.c
>> @@ -37,6 +37,12 @@ static const TypeInfo target_info_parent_type = {
>>
>> DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
>>
>> +void target_info_qom_class_init(ObjectClass *oc, const void * data)
>> +{
>> + TargetInfoQomClass *klass = TARGET_INFO_CLASS(oc);
>> + klass->target_info = data;
>> +}
>> +
>> static const TargetInfo *target_info_ptr;
>>
>> const TargetInfo *target_info(void)
>
> This patch can be squashed with 3, but I thought it might be better for
> review to keep it on top for now.
Mmm. You've missed the part about using class_base_init instead of class_init, so that
you don't need the extern function declaration. See review of patch 3.
r~
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v5 3/6] target-info: extract target_info() definition in target-info-init.h
2026-05-09 15:01 ` Richard Henderson
@ 2026-05-09 21:21 ` Pierrick Bouvier
0 siblings, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 21:21 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Daniel P. Berrangé, Marc-André Lureau,
Markus Armbruster, Max Filippov, Paolo Bonzini,
Philippe Mathieu-Daudé, Anton Johansson
On 5/9/2026 8:01 AM, Richard Henderson wrote:
> On 5/8/26 19:54, Pierrick Bouvier wrote:
>> +#define TYPE_TARGET_INFO_TARGET TYPE_TARGET_INFO"-"TARGET_NAME
>
> I guess avoiding TARGET_NAME can wait until we actually build a single
> binary.
>
The point of this series is to prepare this now, as we already have
other patches (not yet posted) to link several architectures.
I can name it target-info-target for now, but I'm not sure what we gain
from this to be honest, we'll need TARGET_NAME in the end.
>> +typedef struct TargetInfoQomTarget {
>> + TargetInfoQom parent;
>> +} TargetInfoQomTarget;
>> +
>> +typedef struct TargetInfoQomTargetClass {
>> + TargetInfoQomClass parent_class;
>> +} TargetInfoQomTargetClass;
>> +
>> +OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass,
>> TARGET_INFO_TARGET)
>
> Since neither the object nor class are actually used; you don't need these.
>
>> +static void target_info_qom_class_init(ObjectClass *oc, const void *
>> data) \
>> +{ \
>> + TargetInfoQomTargetClass *klass =
>> TARGET_INFO_TARGET_CLASS(oc); \
>> + klass->parent_class.target_info =
>> &ti_var; \
>> +} \
>
> This belongs in vl.c as target_info_parent_type.class_base_init.
>
>> +static const TypeInfo target_info_qom_target_type_info =
>> { \
>> + .name =
>> TYPE_TARGET_INFO_TARGET, \
>> + .parent =
>> TYPE_TARGET_INFO, \
>> + .instance_size =
>> sizeof(TargetInfoQomTarget), \
>> + .class_size =
>> sizeof(TargetInfoQomTargetClass), \
>> + .class_init =
>> target_info_qom_class_init, \
>> + .abstract =
>> false, \
>> +}; \
>
> This reduces to just name, parent, and class_data.
> You don't need sizes, class_init, or abstract.
>
>
> r~
The rest of the patch is the same as v4, I added a new patch (6) to
implement what you asked. I'll squash it in this patch once you're ok.
Regards,
Pierrick
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v5 6/6] target-info-qom: use a single class_init for target-info-* classes
2026-05-09 15:03 ` Richard Henderson
@ 2026-05-09 21:29 ` Pierrick Bouvier
0 siblings, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-09 21:29 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Daniel P. Berrangé, Marc-André Lureau,
Markus Armbruster, Max Filippov, Paolo Bonzini,
Philippe Mathieu-Daudé, Anton Johansson
On 5/9/2026 8:03 AM, Richard Henderson wrote:
> On 5/8/26 19:59, Pierrick Bouvier wrote:
>> On 5/8/2026 5:54 PM, Pierrick Bouvier wrote:
>>> Instead of defining a class_init per class, just use a common
>>> constructor and set class_data to corresponding TargetInfo structure.
>>>
>>> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
>>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
>>> ---
>>> include/qemu/target-info-init.h | 14 ++------------
>>> include/qemu/target-info-qom.h | 1 +
>>> target-info-qom.c | 6 ++++++
>>> 3 files changed, 9 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/include/qemu/target-info-init.h b/include/qemu/target-
>>> info-init.h
>>> index 176fd975a16..3945f2998e0 100644
>>> --- a/include/qemu/target-info-init.h
>>> +++ b/include/qemu/target-info-init.h
>>> @@ -37,8 +37,6 @@ const TargetInfo *target_info(void) \
>>> #include "qemu/target-info-qom.h"
>>> #include "qom/object.h"
>>> -#define TYPE_TARGET_INFO_TARGET TYPE_TARGET_INFO"-"TARGET_NAME
>>> -
>>> typedef struct TargetInfoQomTarget {
>>> TargetInfoQom parent;
>>> } TargetInfoQomTarget;
>>> @@ -47,24 +45,16 @@ typedef struct TargetInfoQomTargetClass {
>>> TargetInfoQomClass parent_class;
>>> } TargetInfoQomTargetClass;
>>> -OBJECT_DECLARE_TYPE(TargetInfoQomTarget, TargetInfoQomTargetClass,
>>> TARGET_INFO_TARGET)
>>> -
>>> #define
>>> target_info_init(ti_var) \
>>> -static void target_info_qom_class_init(ObjectClass *oc, const void *
>>> data) \
>>> -
>>> { \
>>> - TargetInfoQomTargetClass *klass =
>>> TARGET_INFO_TARGET_CLASS(oc); \
>>> - klass->parent_class.target_info =
>>> &ti_var; \
>>> -} \
>>> -
>>> \
>>> static const TypeInfo target_info_qom_target_type_info =
>>> { \
>>> - .name =
>>> TYPE_TARGET_INFO_TARGET, \
>>> + .name =
>>> TYPE_TARGET_INFO"-"TARGET_NAME, \
>>> .parent =
>>> TYPE_TARGET_INFO, \
>>> .instance_size =
>>> sizeof(TargetInfoQomTarget), \
>>> .class_size =
>>> sizeof(TargetInfoQomTargetClass), \
>>> .class_init =
>>> target_info_qom_class_init, \
>>> + .class_data =
>>> &ti_var, \
>>> .abstract =
>>> false, \
>>> }; \
>>> -
>>> \
>>> DEFINE_TARGET_INFO_TYPE(target_info_qom_target_type_info)
>>> #endif /* CONFIG_USER_ONLY */
>>> diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-
>>> info-qom.h
>>> index 91be415ed33..a37c3e101e0 100644
>>> --- a/include/qemu/target-info-qom.h
>>> +++ b/include/qemu/target-info-qom.h
>>> @@ -25,6 +25,7 @@ typedef struct TargetInfoQomClass {
>>> OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
>>> +void target_info_qom_class_init(ObjectClass *oc, const void * data);
>>> void target_info_qom_set_target(void);
>>> #endif /* QEMU_TARGET_INFO_QOM_H */
>>> diff --git a/target-info-qom.c b/target-info-qom.c
>>> index cc470b3b4d6..5b0498ca654 100644
>>> --- a/target-info-qom.c
>>> +++ b/target-info-qom.c
>>> @@ -37,6 +37,12 @@ static const TypeInfo target_info_parent_type = {
>>> DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
>>> +void target_info_qom_class_init(ObjectClass *oc, const void * data)
>>> +{
>>> + TargetInfoQomClass *klass = TARGET_INFO_CLASS(oc);
>>> + klass->target_info = data;
>>> +}
>>> +
>>> static const TargetInfo *target_info_ptr;
>>> const TargetInfo *target_info(void)
>>
>> This patch can be squashed with 3, but I thought it might be better for
>> review to keep it on top for now.
>
> Mmm. You've missed the part about using class_base_init instead of
> class_init, so that you don't need the extern function declaration. See
> review of patch 3.
>
I feel that this pattern of using a super ctor with a data set by child
is very counter intuitive, but I'll trust your judgment on how QOM is
supposed to work.
I'll squash this with patch 3 in next version so there is no confusion also.
>
> r~
Regards,
Pierrick
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v5 1/6] qom/object: register OBJECT and INTERFACE QOM types before main
2026-05-09 0:54 ` [PATCH v5 1/6] qom/object: register OBJECT and INTERFACE QOM types before main Pierrick Bouvier
@ 2026-05-11 10:24 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 16+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-05-11 10:24 UTC (permalink / raw)
To: Pierrick Bouvier, qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Anton Johansson
On 9/5/26 02:54, Pierrick Bouvier wrote:
> Those types are special, as they are the base of all other QOM types. In
> next commit, we'll introduce an extra step in module initialization for
> target-info-* types.
>
> However, those types depend on TYPE_OBJECT, which is only registered
> at MODULE_INIT_QOM step.
>
> To avoid having to introduce another step, and modify all code calling
> module_call_init(MODULE_INIT_QOM), we simply register those base types
> directly in the static constructor, before anything else.
Clever!
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> ---
> qom/object.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v5 2/6] qom/object: initialize type_table in static ctor with fundamental QOM types
2026-05-09 0:54 ` [PATCH v5 2/6] qom/object: initialize type_table in static ctor with fundamental QOM types Pierrick Bouvier
2026-05-09 14:21 ` Richard Henderson
@ 2026-05-11 10:25 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 16+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-05-11 10:25 UTC (permalink / raw)
To: Pierrick Bouvier, qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Anton Johansson
On 9/5/26 02:54, Pierrick Bouvier wrote:
> This saves us having to check if it's initialized everytime we have to
> access it. No other QOM type should be initialized or accessed during
> static ctor calls, so we don't depend on their ordering.
>
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> ---
> qom/object.c | 18 +++++-------------
> 1 file changed, 5 insertions(+), 13 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v5 0/6] single-binary: deduplicate target_info()
2026-05-09 0:54 [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
` (5 preceding siblings ...)
2026-05-09 0:54 ` [PATCH v5 6/6] target-info-qom: use a single class_init for target-info-* classes Pierrick Bouvier
@ 2026-05-12 15:03 ` Pierrick Bouvier
6 siblings, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2026-05-12 15:03 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Daniel P. Berrangé,
Marc-André Lureau, Markus Armbruster, Max Filippov,
Paolo Bonzini, Philippe Mathieu-Daudé, Anton Johansson
On 5/8/2026 5:54 PM, Pierrick Bouvier wrote:
> We are getting close to be able to link several targets in a single QEMU system
> binary, and the last obstacle on the road is to embed several TargetInfo in the
> same binary. The end result of this series is to have a single definition for
> target_info symbol.
>
> This series adds TargetInfo types in QOM, and retrieve them dynamically(). At
> the moment, we don't deal yet with multiple TargetInfo selection, but install
> all that is needed to be able to do it easily.
>
> Because TargetInfo data is set through class_init, it creates an issue at
> startup, where we may try to instantiate additional (unrelated) types just to
> retrieve the list of "target-info-X" types. Those other types class_init may be
> using target information, to add target specific properties for instance.
> This issue has been fixed by adding a new object_class_get_list_by_name_prefix
> that does not force instantiation of all QOM types, but only those matching a
> specific pattern. This way, we first initialize and retrieve target-info types
> before others.
>
> An alternative would be to leave all this out of QOM, and use startup
> initializer to add them in a single list. However, because all the single-binary
> work has been using QOM where possible, it would be really sad to not use it for
> this final step. Comments are welcome!
>
> Finally, sticking to our promise not create a special "single-binary
> configuration", the goal is to use the *exact* same codepath for normal binaries
> also. It means that even for existing system binaries, the goal will be to use
> QOM to retrieve current target, even if there is only one.
>
> v5
> --
>
> - Fix header guard name for target-info-init.h
> (TARGET_INFO_INIT_H -> QEMU_TARGET_INFO_INIT_H)
> - add a new patch to initialize type_table with TYPE_OBJECT and TYPE_INTERFACE,
> as suggested by Richard
> - use a single class_init for all target-info-* classes.
>
> v4
> --
>
> - Revert to v2 MODULE_INIT_TARGET_INFO as Daniel didn't comment on issues about
> about MODULE_INIT_QOM_EARLY.
>
> v3
> --
>
> - fix rebase mistake for one header guard
> - remove MODULE_INIT_TARGET_INFO and introduce MODULE_INIT_QOM_EARLY, as
> requested by Daniel
>
> v2
> --
>
> - fix header guards
> - introduce new module init step (MODULE_INIT_TARGET_INFO)
> - as a consequence of item above, we need to register TYPE_OBJECT before startup
> - fix xtensa core type registration using type_init instead of static ctor
>
> Pierrick Bouvier (6):
> qom/object: register OBJECT and INTERFACE QOM types before main
> qom/object: initialize type_table in static ctor with fundamental QOM
> types
> target-info: extract target_info() definition in target-info-init.h
> target-info-qom: detect target from QOM
> target-info: replace target_info() in system-mode
> target-info-qom: use a single class_init for target-info-* classes
>
> configs/targets/aarch64-softmmu.c | 6 +--
> configs/targets/arm-softmmu.c | 6 +--
> include/qemu/module.h | 1 +
> include/qemu/target-info-init.h | 63 +++++++++++++++++++++++++++++++
> include/qemu/target-info-qom.h | 31 +++++++++++++++
> qom/object.c | 22 +++--------
> system/vl.c | 4 ++
> target-info-qom.c | 41 ++++++++++++++++++++
> target-info-stub.c | 6 +--
> 9 files changed, 152 insertions(+), 28 deletions(-)
> create mode 100644 include/qemu/target-info-init.h
> create mode 100644 include/qemu/target-info-qom.h
>
v6 sent:
https://lore.kernel.org/qemu-devel/20260512150208.1167711-6-pierrick.bouvier@oss.qualcomm.com/T/#
Regards,
Pierrick
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2026-05-12 15:04 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-09 0:54 [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 1/6] qom/object: register OBJECT and INTERFACE QOM types before main Pierrick Bouvier
2026-05-11 10:24 ` Philippe Mathieu-Daudé
2026-05-09 0:54 ` [PATCH v5 2/6] qom/object: initialize type_table in static ctor with fundamental QOM types Pierrick Bouvier
2026-05-09 14:21 ` Richard Henderson
2026-05-11 10:25 ` Philippe Mathieu-Daudé
2026-05-09 0:54 ` [PATCH v5 3/6] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
2026-05-09 15:01 ` Richard Henderson
2026-05-09 21:21 ` Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 4/6] target-info-qom: detect target from QOM Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 5/6] target-info: replace target_info() in system-mode Pierrick Bouvier
2026-05-09 0:54 ` [PATCH v5 6/6] target-info-qom: use a single class_init for target-info-* classes Pierrick Bouvier
2026-05-09 0:59 ` Pierrick Bouvier
2026-05-09 15:03 ` Richard Henderson
2026-05-09 21:29 ` Pierrick Bouvier
2026-05-12 15:03 ` [PATCH v5 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.