* [PATCH 1/6] target-info: extract target_info() definition in target-info-init.h
2026-04-28 23:45 [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
@ 2026-04-28 23:45 ` Pierrick Bouvier
2026-04-29 8:36 ` marcandre.lureau
2026-04-28 23:45 ` [PATCH 2/6] target-info: introduce TargetInfo in QOM Pierrick Bouvier
` (5 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-28 23:45 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Daniel P. Berrangé, Pierrick Bouvier,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
This allows us to prepare next commits, which will introduce qom
registration for system mode.
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
configs/targets/aarch64-softmmu.c | 6 ++----
configs/targets/arm-softmmu.c | 6 ++----
include/qemu/target-info-init.h | 20 ++++++++++++++++++++
target-info-stub.c | 6 ++----
4 files changed, 26 insertions(+), 12 deletions(-)
create mode 100644 include/qemu/target-info-init.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/target-info-init.h b/include/qemu/target-info-init.h
new file mode 100644
index 00000000000..9be06d8523a
--- /dev/null
+++ b/include/qemu/target-info-init.h
@@ -0,0 +1,20 @@
+/*
+ * 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 TARGET_INFO_DEF_H
+
+#define target_info_init(ti_var) \
+const TargetInfo *target_info(void) \
+{ \
+ return &ti_var; \
+}
+
+#endif /* TARGET_INFO_DEF_H */
diff --git a/target-info-stub.c b/target-info-stub.c
index f5896a72621..af7cdc5e67a 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/page-vary.h"
@@ -40,7 +41,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] 19+ messages in thread* Re: [PATCH 1/6] target-info: extract target_info() definition in target-info-init.h
2026-04-28 23:45 ` [PATCH 1/6] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
@ 2026-04-29 8:36 ` marcandre.lureau
0 siblings, 0 replies; 19+ messages in thread
From: marcandre.lureau @ 2026-04-29 8:36 UTC (permalink / raw)
To: qemu-devel, Pierrick Bouvier
Cc: Markus Armbruster, Daniel P. Berrangé,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On Tue, 28 Apr 2026 16:45:14 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
> This allows us to prepare next commits, which will introduce qom
> registration for system mode.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
--
Marc-André Lureau <marcandre.lureau@redhat.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 2/6] target-info: introduce TargetInfo in QOM
2026-04-28 23:45 [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
2026-04-28 23:45 ` [PATCH 1/6] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
@ 2026-04-28 23:45 ` Pierrick Bouvier
2026-04-29 8:36 ` marcandre.lureau
2026-04-28 23:45 ` [PATCH 3/6] system/vl: initialize QOM first Pierrick Bouvier
` (4 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-28 23:45 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Daniel P. Berrangé, Pierrick Bouvier,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
For the single-binary, we want to be able to retrieve at runtime the
current target among the different ones available.
A consequence is that we can't rely on existing target_info() definition
since it will create a conflict once more than one target is available.
To solve this, we add TargetInfo in QOM, with this hierarchy.
We define one class "target-info-X" per target, that inherits from
abstract class "target-info". Using concrete vs abstract class ensure we
can easily filter "target-info-X" from all QOM types.
Associated TargetInfo is directly set through class initialization,
without relying on any instance.
For user mode, we simply define target_info() like it was done
previously. In this patch, we keep the same definition for system-mode
also, and it will be replaced in next commits.
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
include/qemu/target-info-init.h | 48 +++++++++++++++++++++++++++++++++
include/qemu/target-info-qom.h | 23 ++++++++++++++++
target-info-qom.c | 10 +++++++
3 files changed, 81 insertions(+)
create mode 100644 include/qemu/target-info-qom.h
diff --git a/include/qemu/target-info-init.h b/include/qemu/target-info-init.h
index 9be06d8523a..f3cea985540 100644
--- a/include/qemu/target-info-init.h
+++ b/include/qemu/target-info-init.h
@@ -11,10 +11,58 @@
#ifndef TARGET_INFO_DEF_H
+#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_TYPES(target_info_qom_target_type_info)
+
+#endif /* CONFIG_USER_ONLY */
+
#endif /* TARGET_INFO_DEF_H */
diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
new file mode 100644
index 00000000000..db069db718a
--- /dev/null
+++ b/include/qemu/target-info-qom.h
@@ -0,0 +1,23 @@
+/*
+ * QEMU target info QOM types
+ *
+ * Copyright (c) Qualcomm
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#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)
diff --git a/target-info-qom.c b/target-info-qom.c
index 7fd58d24818..5ce29f80301 100644
--- a/target-info-qom.c
+++ b/target-info-qom.c
@@ -7,10 +7,20 @@
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "qom/object.h"
+#include "qemu/target-info-impl.h"
+#include "qemu/target-info-qom.h"
#include "hw/arm/machines-qom.h"
static const TypeInfo target_info_types[] = {
+ {
+ .name = TYPE_TARGET_INFO,
+ .parent = TYPE_OBJECT,
+ .instance_size = sizeof(TargetInfoQom),
+ .class_size = sizeof(TargetInfoQomClass),
+ .abstract = true,
+ },
{
.name = TYPE_TARGET_ARM_MACHINE,
.parent = TYPE_INTERFACE,
--
2.43.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH 2/6] target-info: introduce TargetInfo in QOM
2026-04-28 23:45 ` [PATCH 2/6] target-info: introduce TargetInfo in QOM Pierrick Bouvier
@ 2026-04-29 8:36 ` marcandre.lureau
2026-04-29 18:22 ` Pierrick Bouvier
0 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2026-04-29 8:36 UTC (permalink / raw)
To: qemu-devel, Pierrick Bouvier
Cc: Markus Armbruster, Daniel P. Berrangé,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On Tue, 28 Apr 2026 16:45:15 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
> diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
> new file mode 100644
> index 00000000000..db069db718a
> --- /dev/null
> +++ b/include/qemu/target-info-qom.h
> @@ -0,0 +1,23 @@
> +/*
> + * QEMU target info QOM types
> + *
> + * Copyright (c) Qualcomm
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/target-info-impl.h"
> +#include "qom/object.h"
Missing include guard. Add:
#ifndef QEMU_TARGET_INFO_QOM_H
#define QEMU_TARGET_INFO_QOM_H
before the includes, and a matching #endif at the end.
--
Marc-André Lureau <marcandre.lureau@redhat.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/6] target-info: introduce TargetInfo in QOM
2026-04-29 8:36 ` marcandre.lureau
@ 2026-04-29 18:22 ` Pierrick Bouvier
0 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-29 18:22 UTC (permalink / raw)
To: marcandre.lureau, qemu-devel
Cc: Markus Armbruster, Daniel P. Berrangé,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On 4/29/2026 1:36 AM, marcandre.lureau@redhat.com wrote:
> On Tue, 28 Apr 2026 16:45:15 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
>> diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
>> new file mode 100644
>> index 00000000000..db069db718a
>> --- /dev/null
>> +++ b/include/qemu/target-info-qom.h
>> @@ -0,0 +1,23 @@
>> +/*
>> + * QEMU target info QOM types
>> + *
>> + * Copyright (c) Qualcomm
>> + *
>> + * SPDX-License-Identifier: GPL-2.0-or-later
>> + */
>> +
>> +#include "qemu/target-info-impl.h"
>> +#include "qom/object.h"
>
> Missing include guard. Add:
>
> #ifndef QEMU_TARGET_INFO_QOM_H
> #define QEMU_TARGET_INFO_QOM_H
>
> before the includes, and a matching #endif at the end.
>
Oops indeed. I'll add it thanks.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 3/6] system/vl: initialize QOM first
2026-04-28 23:45 [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
2026-04-28 23:45 ` [PATCH 1/6] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
2026-04-28 23:45 ` [PATCH 2/6] target-info: introduce TargetInfo in QOM Pierrick Bouvier
@ 2026-04-28 23:45 ` Pierrick Bouvier
2026-04-29 8:36 ` marcandre.lureau
2026-04-28 23:45 ` [PATCH 4/6] qom/object: add object_class_get_list_by_name_prefix Pierrick Bouvier
` (3 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-28 23:45 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Daniel P. Berrangé, Pierrick Bouvier,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
We will introduce detection of target from QOM, so we need to make sure
QOM is initialized first.
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
system/runstate.c | 1 -
system/vl.c | 3 +++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/system/runstate.c b/system/runstate.c
index 770253b467b..c8e92f8a603 100644
--- a/system/runstate.c
+++ b/system/runstate.c
@@ -981,7 +981,6 @@ void qemu_init_subsystems(void)
atexit(qemu_run_exit_notifiers);
- module_call_init(MODULE_INIT_QOM);
module_call_init(MODULE_INIT_MIGRATION);
runstate_init();
diff --git a/system/vl.c b/system/vl.c
index 0e1fc217b4f..b4a5ea6f857 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2889,6 +2889,9 @@ void qemu_init(int argc, char **argv)
os_setup_limits();
module_init_info(qemu_modinfo);
+ /* We need to initialize QOM first to detect target */
+ module_call_init(MODULE_INIT_QOM);
+
module_allow_arch(target_name());
qemu_init_subsystems();
--
2.43.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH 3/6] system/vl: initialize QOM first
2026-04-28 23:45 ` [PATCH 3/6] system/vl: initialize QOM first Pierrick Bouvier
@ 2026-04-29 8:36 ` marcandre.lureau
2026-04-29 8:46 ` Daniel P. Berrangé
0 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2026-04-29 8:36 UTC (permalink / raw)
To: qemu-devel, Pierrick Bouvier
Cc: Markus Armbruster, Daniel P. Berrangé,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On Tue, 28 Apr 2026 16:45:16 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
> diff --git a/system/vl.c b/system/vl.c
> index 0e1fc217b4f..b4a5ea6f857 100644
> --- a/system/vl.c
> +++ b/system/vl.c
> @@ -2889,6 +2889,9 @@ void qemu_init(int argc, char **argv)
> os_setup_limits();
>
> module_init_info(qemu_modinfo);
> + /* We need to initialize QOM first to detect target */
> + module_call_init(MODULE_INIT_QOM);
> +
> module_allow_arch(target_name());
This change is not trivial. By moving the call here, we lose the
initializations from qemu_init_subsystems(). Verifying that all
type_init() code is safe to run without it is a tedious task. It might
be better to introduce a new MODULE_INIT_TARGET_INFO instead
--
Marc-André Lureau <marcandre.lureau@redhat.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 3/6] system/vl: initialize QOM first
2026-04-29 8:36 ` marcandre.lureau
@ 2026-04-29 8:46 ` Daniel P. Berrangé
2026-04-29 21:23 ` Pierrick Bouvier
0 siblings, 1 reply; 19+ messages in thread
From: Daniel P. Berrangé @ 2026-04-29 8:46 UTC (permalink / raw)
To: marcandre.lureau
Cc: qemu-devel, Pierrick Bouvier, Markus Armbruster,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On Wed, Apr 29, 2026 at 12:36:03PM +0400, marcandre.lureau@redhat.com wrote:
> On Tue, 28 Apr 2026 16:45:16 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
> > diff --git a/system/vl.c b/system/vl.c
> > index 0e1fc217b4f..b4a5ea6f857 100644
> > --- a/system/vl.c
> > +++ b/system/vl.c
> > @@ -2889,6 +2889,9 @@ void qemu_init(int argc, char **argv)
> > os_setup_limits();
> >
> > module_init_info(qemu_modinfo);
> > + /* We need to initialize QOM first to detect target */
> > + module_call_init(MODULE_INIT_QOM);
> > +
> > module_allow_arch(target_name());
>
> This change is not trivial. By moving the call here, we lose the
> initializations from qemu_init_subsystems(). Verifying that all
> type_init() code is safe to run without it is a tedious task. It might
> be better to introduce a new MODULE_INIT_TARGET_INFO instead
I'd be inclined to have a MODULE_INIT_QOM_EARLY, along with a
type_init_early(), so we're not presuming target info is the only
use case for earlier init.
Regards,
Daniel
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 3/6] system/vl: initialize QOM first
2026-04-29 8:46 ` Daniel P. Berrangé
@ 2026-04-29 21:23 ` Pierrick Bouvier
0 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-29 21:23 UTC (permalink / raw)
To: Daniel P. Berrangé, marcandre.lureau
Cc: qemu-devel, Markus Armbruster, Philippe Mathieu-Daudé,
Anton Johansson, Richard Henderson, Paolo Bonzini
On 4/29/2026 1:46 AM, Daniel P. Berrangé wrote:
> On Wed, Apr 29, 2026 at 12:36:03PM +0400, marcandre.lureau@redhat.com wrote:
>> On Tue, 28 Apr 2026 16:45:16 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
>>> diff --git a/system/vl.c b/system/vl.c
>>> index 0e1fc217b4f..b4a5ea6f857 100644
>>> --- a/system/vl.c
>>> +++ b/system/vl.c
>>> @@ -2889,6 +2889,9 @@ void qemu_init(int argc, char **argv)
>>> os_setup_limits();
>>>
>>> module_init_info(qemu_modinfo);
>>> + /* We need to initialize QOM first to detect target */
>>> + module_call_init(MODULE_INIT_QOM);
>>> +
>>> module_allow_arch(target_name());
>>
>> This change is not trivial. By moving the call here, we lose the
>> initializations from qemu_init_subsystems(). Verifying that all
>> type_init() code is safe to run without it is a tedious task. It might
>> be better to introduce a new MODULE_INIT_TARGET_INFO instead
>
That seems like the right approach, thanks!
> I'd be inclined to have a MODULE_INIT_QOM_EARLY, along with a
> type_init_early(), so we're not presuming target info is the only
> use case for earlier init.
>
I feel that if we need such behavior, we can introduce another step when
needed. For the current scenario, it's really target-info vs all other
types, so it makes sense to reflect that in the name. Thus I would
prefer to follow Daniel naming for this one, if it works for you.
> Regards,
> Daniel
>
Thanks,
Pierrick
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 4/6] qom/object: add object_class_get_list_by_name_prefix
2026-04-28 23:45 [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
` (2 preceding siblings ...)
2026-04-28 23:45 ` [PATCH 3/6] system/vl: initialize QOM first Pierrick Bouvier
@ 2026-04-28 23:45 ` Pierrick Bouvier
2026-04-29 8:36 ` marcandre.lureau
2026-04-28 23:45 ` [PATCH 5/6] target-info-qom: detect target from QOM Pierrick Bouvier
` (2 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-28 23:45 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Daniel P. Berrangé, Pierrick Bouvier,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
The existing object_class_get_list forces an initialization of all QOM
types, which triggers call to class_init for all types.
This function checks type name before initializing it.
Next commit will query list of target-info QOM types. However, some
existing classes already rely on target detection to add conditional
properties. Thus, we need to be able to initialize only target-info
types first.
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
include/qom/object.h | 13 +++++++++++++
qom/object.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index 510885218ba..a6d7b3874a7 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1033,6 +1033,19 @@ GSList *object_class_get_list(const char *implements_type,
GSList *object_class_get_list_sorted(const char *implements_type,
bool include_abstract);
+/**
+ * object_class_get_list:
+ * @name_prefix: Name prefix for type to filter for.
+ * @include_abstract: Whether to include abstract classes.
+ *
+ * To the opposite of object_class_get_list, only matching types are
+ * initialized.
+ *
+ * Returns: A singly-linked list of the classes in reverse hashtable order.
+ */
+GSList *object_class_get_list_by_name_prefix(const char *name_prefix,
+ bool include_abstract);
+
/**
* object_ref:
* @obj: the object
diff --git a/qom/object.c b/qom/object.c
index f981e270440..14527108a2e 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1062,6 +1062,30 @@ static void object_class_foreach_tramp(gpointer key, gpointer value,
data->fn(k, data->opaque);
}
+static void object_class_foreach_match_name_prefix(gpointer key, gpointer value,
+ gpointer opaque)
+{
+ OCFData *data = opaque;
+ TypeImpl *type = value;
+ ObjectClass *k;
+
+ const char *name_prefix = data->implements_type;
+ size_t prefix_len = name_prefix ? strlen(name_prefix) : 0;
+
+ if (strncmp(type->name, name_prefix, prefix_len)) {
+ return;
+ }
+
+ type_initialize(type);
+ k = type->class;
+
+ if (!data->include_abstract && type->abstract) {
+ return;
+ }
+
+ data->fn(k, data->opaque);
+}
+
void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
const char *implements_type, bool include_abstract,
void *opaque)
@@ -1131,6 +1155,22 @@ GSList *object_class_get_list(const char *implements_type,
return list;
}
+GSList *object_class_get_list_by_name_prefix(const char *name_prefix,
+ bool include_abstract)
+{
+ GSList *list = NULL;
+
+ OCFData data = { object_class_get_list_tramp,
+ name_prefix, include_abstract, &list };
+
+ enumerating_types = true;
+ g_hash_table_foreach(type_table_get(),
+ object_class_foreach_match_name_prefix,
+ &data);
+ enumerating_types = false;
+ return list;
+}
+
static gint object_class_cmp(gconstpointer a, gconstpointer b, gpointer d)
{
return g_ascii_strcasecmp(object_class_get_name((ObjectClass *)a),
--
2.43.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH 4/6] qom/object: add object_class_get_list_by_name_prefix
2026-04-28 23:45 ` [PATCH 4/6] qom/object: add object_class_get_list_by_name_prefix Pierrick Bouvier
@ 2026-04-29 8:36 ` marcandre.lureau
2026-04-29 8:48 ` Daniel P. Berrangé
0 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2026-04-29 8:36 UTC (permalink / raw)
To: qemu-devel, Pierrick Bouvier
Cc: Markus Armbruster, Daniel P. Berrangé,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On Tue, 28 Apr 2026 16:45:17 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 510885218ba..a6d7b3874a7 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -1033,6 +1033,19 @@ GSList *object_class_get_list(const char *implements_type,
> GSList *object_class_get_list_sorted(const char *implements_type,
> bool include_abstract);
>
> +/**
> + * object_class_get_list:
Should be "object_class_get_list_by_name_prefix:".
> + * @name_prefix: Name prefix for type to filter for.
> + * @include_abstract: Whether to include abstract classes.
> + *
> + * To the opposite of object_class_get_list, only matching types are
Suggest "Unlike object_class_get_list,"
>
> diff --git a/qom/object.c b/qom/object.c
> index f981e270440..14527108a2e 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1062,6 +1062,30 @@ static void object_class_foreach_tramp(gpointer key, gpointer value,
> data->fn(k, data->opaque);
> }
>
> +static void object_class_foreach_match_name_prefix(gpointer key, gpointer value,
> + gpointer opaque)
> +{
> + OCFData *data = opaque;
> + TypeImpl *type = value;
> + ObjectClass *k;
> +
> + const char *name_prefix = data->implements_type;
Perhaps the "implements_type" field should be renamed.
> [ ... skip 11 lines ... ]
> + }
> +
> + data->fn(k, data->opaque);
> +}
> +
> void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
I wonder if we introduce MODULE_INIT_TARGET_INFO, is this all needed?
since only TargetInfo types would be registered..
Suggest: "Unlike object_class_get_list,"
Suggest: "Unlike object_class_get_list,"
--
Marc-André Lureau <marcandre.lureau@redhat.com>
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 4/6] qom/object: add object_class_get_list_by_name_prefix
2026-04-29 8:36 ` marcandre.lureau
@ 2026-04-29 8:48 ` Daniel P. Berrangé
2026-04-29 21:20 ` Pierrick Bouvier
0 siblings, 1 reply; 19+ messages in thread
From: Daniel P. Berrangé @ 2026-04-29 8:48 UTC (permalink / raw)
To: marcandre.lureau
Cc: qemu-devel, Pierrick Bouvier, Markus Armbruster,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On Wed, Apr 29, 2026 at 12:36:03PM +0400, marcandre.lureau@redhat.com wrote:
> On Tue, 28 Apr 2026 16:45:17 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
> > diff --git a/include/qom/object.h b/include/qom/object.h
> > index 510885218ba..a6d7b3874a7 100644
> > --- a/include/qom/object.h
> > +++ b/include/qom/object.h
> > @@ -1033,6 +1033,19 @@ GSList *object_class_get_list(const char *implements_type,
> > GSList *object_class_get_list_sorted(const char *implements_type,
> > bool include_abstract);
> >
> > +/**
> > + * object_class_get_list:
>
> Should be "object_class_get_list_by_name_prefix:".
>
> > + * @name_prefix: Name prefix for type to filter for.
> > + * @include_abstract: Whether to include abstract classes.
> > + *
> > + * To the opposite of object_class_get_list, only matching types are
>
> Suggest "Unlike object_class_get_list,"
>
> >
> > diff --git a/qom/object.c b/qom/object.c
> > index f981e270440..14527108a2e 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -1062,6 +1062,30 @@ static void object_class_foreach_tramp(gpointer key, gpointer value,
> > data->fn(k, data->opaque);
> > }
> >
> > +static void object_class_foreach_match_name_prefix(gpointer key, gpointer value,
> > + gpointer opaque)
> > +{
> > + OCFData *data = opaque;
> > + TypeImpl *type = value;
> > + ObjectClass *k;
> > +
> > + const char *name_prefix = data->implements_type;
>
> Perhaps the "implements_type" field should be renamed.
>
> > [ ... skip 11 lines ... ]
> > + }
> > +
> > + data->fn(k, data->opaque);
> > +}
> > +
> > void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
>
> I wonder if we introduce MODULE_INIT_TARGET_INFO, is this all needed?
> since only TargetInfo types would be registered..
Yeah, i feel like this patch should be redundant if we provide a
separate initializer for early types to get registered.
Daniel
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 4/6] qom/object: add object_class_get_list_by_name_prefix
2026-04-29 8:48 ` Daniel P. Berrangé
@ 2026-04-29 21:20 ` Pierrick Bouvier
0 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-29 21:20 UTC (permalink / raw)
To: Daniel P. Berrangé, marcandre.lureau
Cc: qemu-devel, Markus Armbruster, Philippe Mathieu-Daudé,
Anton Johansson, Richard Henderson, Paolo Bonzini
On 4/29/2026 1:48 AM, Daniel P. Berrangé wrote:
> On Wed, Apr 29, 2026 at 12:36:03PM +0400, marcandre.lureau@redhat.com wrote:
>> On Tue, 28 Apr 2026 16:45:17 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
>>> diff --git a/include/qom/object.h b/include/qom/object.h
>>> index 510885218ba..a6d7b3874a7 100644
>>> --- a/include/qom/object.h
>>> +++ b/include/qom/object.h
>>> @@ -1033,6 +1033,19 @@ GSList *object_class_get_list(const char *implements_type,
>>> GSList *object_class_get_list_sorted(const char *implements_type,
>>> bool include_abstract);
>>>
>>> +/**
>>> + * object_class_get_list:
>>
>> Should be "object_class_get_list_by_name_prefix:".
>>
>>> + * @name_prefix: Name prefix for type to filter for.
>>> + * @include_abstract: Whether to include abstract classes.
>>> + *
>>> + * To the opposite of object_class_get_list, only matching types are
>>
>> Suggest "Unlike object_class_get_list,"
>>
>>>
>>> diff --git a/qom/object.c b/qom/object.c
>>> index f981e270440..14527108a2e 100644
>>> --- a/qom/object.c
>>> +++ b/qom/object.c
>>> @@ -1062,6 +1062,30 @@ static void object_class_foreach_tramp(gpointer key, gpointer value,
>>> data->fn(k, data->opaque);
>>> }
>>>
>>> +static void object_class_foreach_match_name_prefix(gpointer key, gpointer value,
>>> + gpointer opaque)
>>> +{
>>> + OCFData *data = opaque;
>>> + TypeImpl *type = value;
>>> + ObjectClass *k;
>>> +
>>> + const char *name_prefix = data->implements_type;
>>
>> Perhaps the "implements_type" field should be renamed.
>>
>>> [ ... skip 11 lines ... ]
>>> + }
>>> +
>>> + data->fn(k, data->opaque);
>>> +}
>>> +
>>> void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
>>
>> I wonder if we introduce MODULE_INIT_TARGET_INFO, is this all needed?
>> since only TargetInfo types would be registered..
>
> Yeah, i feel like this patch should be redundant if we provide a
> separate initializer for early types to get registered.
>
You're both right, this patch is not necessary anymore.
Since only target-info QOM types are registered after this step, we can
safely call object_class_get_list.
> Daniel
>
Regards,
Pierrick
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 5/6] target-info-qom: detect target from QOM
2026-04-28 23:45 [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
` (3 preceding siblings ...)
2026-04-28 23:45 ` [PATCH 4/6] qom/object: add object_class_get_list_by_name_prefix Pierrick Bouvier
@ 2026-04-28 23:45 ` Pierrick Bouvier
2026-04-29 8:36 ` marcandre.lureau
2026-04-28 23:45 ` [PATCH 6/6] target-info: replace target_info() in system-mode Pierrick Bouvier
2026-04-30 4:00 ` [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
6 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-28 23:45 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Daniel P. Berrangé, Pierrick Bouvier,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
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.
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 | 17 +++++++++++++++++
3 files changed, 21 insertions(+)
diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h
index db069db718a..9549465aa64 100644
--- a/include/qemu/target-info-qom.h
+++ b/include/qemu/target-info-qom.h
@@ -21,3 +21,5 @@ typedef struct TargetInfoQomClass {
} TargetInfoQomClass;
OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
+
+void target_info_qom_set_target(void);
diff --git a/system/vl.c b/system/vl.c
index b4a5ea6f857..96a03ff2ff7 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"
@@ -2891,6 +2892,7 @@ void qemu_init(int argc, char **argv)
module_init_info(qemu_modinfo);
/* We need to initialize QOM first to detect target */
module_call_init(MODULE_INIT_QOM);
+ target_info_qom_set_target();
module_allow_arch(target_name());
diff --git a/target-info-qom.c b/target-info-qom.c
index 5ce29f80301..748fdd5a8fb 100644
--- a/target-info-qom.c
+++ b/target-info-qom.c
@@ -32,3 +32,20 @@ static const TypeInfo target_info_types[] = {
};
DEFINE_TYPES(target_info_types)
+
+static const TargetInfo *target_info_ptr;
+
+void target_info_qom_set_target(void)
+{
+ g_autoptr(GSList) targets =
+ object_class_get_list_by_name_prefix(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] 19+ messages in thread* Re: [PATCH 5/6] target-info-qom: detect target from QOM
2026-04-28 23:45 ` [PATCH 5/6] target-info-qom: detect target from QOM Pierrick Bouvier
@ 2026-04-29 8:36 ` marcandre.lureau
0 siblings, 0 replies; 19+ messages in thread
From: marcandre.lureau @ 2026-04-29 8:36 UTC (permalink / raw)
To: qemu-devel, Pierrick Bouvier
Cc: Markus Armbruster, Daniel P. Berrangé,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On Tue, 28 Apr 2026 16:45:18 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
> 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>
--
Marc-André Lureau <marcandre.lureau@redhat.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 6/6] target-info: replace target_info() in system-mode
2026-04-28 23:45 [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
` (4 preceding siblings ...)
2026-04-28 23:45 ` [PATCH 5/6] target-info-qom: detect target from QOM Pierrick Bouvier
@ 2026-04-28 23:45 ` Pierrick Bouvier
2026-04-29 8:36 ` marcandre.lureau
2026-04-30 4:00 ` [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
6 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-28 23:45 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Daniel P. Berrangé, Pierrick Bouvier,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
We now can use TargetInfo information available from QOM, and remove
duplicated target_info() symbol.
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 f3cea985540..51aa9419e88 100644
--- a/include/qemu/target-info-init.h
+++ b/include/qemu/target-info-init.h
@@ -41,11 +41,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 748fdd5a8fb..feba764a6bc 100644
--- a/target-info-qom.c
+++ b/target-info-qom.c
@@ -35,6 +35,11 @@ DEFINE_TYPES(target_info_types)
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 =
--
2.43.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH 6/6] target-info: replace target_info() in system-mode
2026-04-28 23:45 ` [PATCH 6/6] target-info: replace target_info() in system-mode Pierrick Bouvier
@ 2026-04-29 8:36 ` marcandre.lureau
0 siblings, 0 replies; 19+ messages in thread
From: marcandre.lureau @ 2026-04-29 8:36 UTC (permalink / raw)
To: qemu-devel, Pierrick Bouvier
Cc: Markus Armbruster, Daniel P. Berrangé,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On Tue, 28 Apr 2026 16:45:19 -0700, Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> wrote:
> We now can use TargetInfo information available from QOM, and remove
> duplicated target_info() symbol.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
--
Marc-André Lureau <marcandre.lureau@redhat.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 0/6] single-binary: deduplicate target_info()
2026-04-28 23:45 [PATCH 0/6] single-binary: deduplicate target_info() Pierrick Bouvier
` (5 preceding siblings ...)
2026-04-28 23:45 ` [PATCH 6/6] target-info: replace target_info() in system-mode Pierrick Bouvier
@ 2026-04-30 4:00 ` Pierrick Bouvier
6 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 4:00 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Daniel P. Berrangé,
Philippe Mathieu-Daudé, Anton Johansson, Richard Henderson,
Paolo Bonzini
On 4/28/2026 4:45 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.
>
> Pierrick Bouvier (6):
> target-info: extract target_info() definition in target-info-init.h
> target-info: introduce TargetInfo in QOM
> system/vl: initialize QOM first
> qom/object: add object_class_get_list_by_name_prefix
> target-info-qom: detect target from QOM
> target-info: replace target_info() in system-mode
>
> configs/targets/aarch64-softmmu.c | 6 +--
> configs/targets/arm-softmmu.c | 6 +--
> include/qemu/target-info-init.h | 63 +++++++++++++++++++++++++++++++
> include/qemu/target-info-qom.h | 25 ++++++++++++
> include/qom/object.h | 13 +++++++
> qom/object.c | 40 ++++++++++++++++++++
> system/runstate.c | 1 -
> system/vl.c | 5 +++
> target-info-qom.c | 32 ++++++++++++++++
> target-info-stub.c | 6 +--
> 10 files changed, 184 insertions(+), 13 deletions(-)
> create mode 100644 include/qemu/target-info-init.h
> create mode 100644 include/qemu/target-info-qom.h
>
Sent v2:
20260430035626.3511676-1-pierrick.bouvier@oss.qualcomm.com
Regards,
Pierrick
^ permalink raw reply [flat|nested] 19+ messages in thread