* [PATCH v2 1/7] target-info: extract target_info() definition in target-info-init.h
2026-04-30 3:56 [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
@ 2026-04-30 3:56 ` Pierrick Bouvier
2026-04-30 8:03 ` Marc-André Lureau
2026-04-30 3:56 ` [PATCH v2 2/7] target-info: introduce TargetInfo in QOM Pierrick Bouvier
` (6 subsequent siblings)
7 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 3:56 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov, Daniel P. Berrangé
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/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 v2 1/7] target-info: extract target_info() definition in target-info-init.h
2026-04-30 3:56 ` [PATCH v2 1/7] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
@ 2026-04-30 8:03 ` Marc-André Lureau
2026-04-30 16:23 ` Pierrick Bouvier
0 siblings, 1 reply; 19+ messages in thread
From: Marc-André Lureau @ 2026-04-30 8:03 UTC (permalink / raw)
To: Pierrick Bouvier
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, Paolo Bonzini, Max Filippov,
Daniel P. Berrangé
Hi
On Thu, Apr 30, 2026 at 7:56 AM 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>
> 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
> +
missing #define 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 [flat|nested] 19+ messages in thread* Re: [PATCH v2 1/7] target-info: extract target_info() definition in target-info-init.h
2026-04-30 8:03 ` Marc-André Lureau
@ 2026-04-30 16:23 ` Pierrick Bouvier
0 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 16:23 UTC (permalink / raw)
To: Marc-André Lureau
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, Paolo Bonzini, Max Filippov,
Daniel P. Berrangé
On 4/30/2026 1:03 AM, Marc-André Lureau wrote:
> Hi
>
> On Thu, Apr 30, 2026 at 7:56 AM 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>
>> 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
>> +
>
> missing #define TARGET_INFO_DEF_H
>
Wrong rebase, this was fixed in patch 2. I'll move it here for v3.
Thanks,
Pierrick
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 2/7] target-info: introduce TargetInfo in QOM
2026-04-30 3:56 [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
2026-04-30 3:56 ` [PATCH v2 1/7] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
@ 2026-04-30 3:56 ` Pierrick Bouvier
2026-04-30 3:56 ` [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main Pierrick Bouvier
` (5 subsequent siblings)
7 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 3:56 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov, Daniel P. Berrangé
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 | 49 +++++++++++++++++++++++++++++++++
include/qemu/target-info-qom.h | 28 +++++++++++++++++++
target-info-qom.c | 10 +++++++
3 files changed, 87 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..1e52ad62820 100644
--- a/include/qemu/target-info-init.h
+++ b/include/qemu/target-info-init.h
@@ -10,11 +10,60 @@
*/
#ifndef TARGET_INFO_DEF_H
+#define 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..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/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* [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main
2026-04-30 3:56 [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
2026-04-30 3:56 ` [PATCH v2 1/7] target-info: extract target_info() definition in target-info-init.h Pierrick Bouvier
2026-04-30 3:56 ` [PATCH v2 2/7] target-info: introduce TargetInfo in QOM Pierrick Bouvier
@ 2026-04-30 3:56 ` Pierrick Bouvier
2026-04-30 7:12 ` Daniel P. Berrangé
2026-04-30 3:56 ` [PATCH v2 4/7] target/xtensa/core: register types using type_init Pierrick Bouvier
` (4 subsequent siblings)
7 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 3:56 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov, Daniel P. Berrangé
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.
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] 19+ messages in thread* Re: [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main
2026-04-30 3:56 ` [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main Pierrick Bouvier
@ 2026-04-30 7:12 ` Daniel P. Berrangé
2026-04-30 16:03 ` Pierrick Bouvier
0 siblings, 1 reply; 19+ messages in thread
From: Daniel P. Berrangé @ 2026-04-30 7:12 UTC (permalink / raw)
To: Pierrick Bouvier
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov
On Wed, Apr 29, 2026 at 08:56:22PM -0700, 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.
>
> 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)
IMHO this should have been done using the MODULE_INIT_QOM_EARLY
approach that I suggested on v1, rather than special casing both
the base classes and MODULE_INIT_TARGET_INFO
With regards,
Daniel
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main
2026-04-30 7:12 ` Daniel P. Berrangé
@ 2026-04-30 16:03 ` Pierrick Bouvier
2026-04-30 17:07 ` Daniel P. Berrangé
0 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 16:03 UTC (permalink / raw)
To: Daniel P. Berrangé
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov
On 4/30/2026 12:12 AM, Daniel P. Berrangé wrote:
> On Wed, Apr 29, 2026 at 08:56:22PM -0700, 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.
>>
>> 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)
>
> IMHO this should have been done using the MODULE_INIT_QOM_EARLY
> approach that I suggested on v1, rather than special casing both
> the base classes and MODULE_INIT_TARGET_INFO
>
I'm ok to follow your approach if you really prefer it.
However, can you specify what should be the semantic to put in comment
for it? I have trouble finding to explain what is early vs non early,
while it's clear for me what is TARGET_INFO vs REST_OF_QOM.
As well, adding a INIT_QOM_EARLY implies we need to call it in all
locations where we already call INIT_QOM for future-proofing, which
seems very redundant. Should we had it or not?
What do you think about these two points?
> With regards,
> Daniel
>
Regards,
Pierrick
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main
2026-04-30 16:03 ` Pierrick Bouvier
@ 2026-04-30 17:07 ` Daniel P. Berrangé
2026-04-30 17:28 ` Pierrick Bouvier
0 siblings, 1 reply; 19+ messages in thread
From: Daniel P. Berrangé @ 2026-04-30 17:07 UTC (permalink / raw)
To: Pierrick Bouvier
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov
On Thu, Apr 30, 2026 at 09:03:52AM -0700, Pierrick Bouvier wrote:
> On 4/30/2026 12:12 AM, Daniel P. Berrangé wrote:
> > On Wed, Apr 29, 2026 at 08:56:22PM -0700, 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.
> >>
> >> 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)
> >
> > IMHO this should have been done using the MODULE_INIT_QOM_EARLY
> > approach that I suggested on v1, rather than special casing both
> > the base classes and MODULE_INIT_TARGET_INFO
> >
>
> I'm ok to follow your approach if you really prefer it.
> However, can you specify what should be the semantic to put in comment
> for it? I have trouble finding to explain what is early vs non early,
> while it's clear for me what is TARGET_INFO vs REST_OF_QOM.
I don't think we need to set our strong rules. It is just an early
startup hook to be used by classes which are a dependency of other
initialization code. Conceptually this is similar to what we did
in system/vl.c, where we have various stages for creating -object
args. What goes in each stage is simply determined by a functional
need at the point in time.
> As well, adding a INIT_QOM_EARLY implies we need to call it in all
> locations where we already call INIT_QOM for future-proofing, which
> seems very redundant. Should we had it or not?
Yep, that's true, but not the end of the world imho.
Ultimately an solution is a bit of a hack. Long term what we need
to do is follow glib's approach from GType and have "just in time"
initialization on first use which will make everything "just work"
without having to think about ordering. I didn't want to suggest
that now though, as it has potential to be a can of worms.
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main
2026-04-30 17:07 ` Daniel P. Berrangé
@ 2026-04-30 17:28 ` Pierrick Bouvier
2026-04-30 17:37 ` Pierrick Bouvier
0 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 17:28 UTC (permalink / raw)
To: Daniel P. Berrangé
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov
On 4/30/2026 10:07 AM, Daniel P. Berrangé wrote:
> On Thu, Apr 30, 2026 at 09:03:52AM -0700, Pierrick Bouvier wrote:
>> On 4/30/2026 12:12 AM, Daniel P. Berrangé wrote:
>>> On Wed, Apr 29, 2026 at 08:56:22PM -0700, 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.
>>>>
>>>> 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)
>>>
>>> IMHO this should have been done using the MODULE_INIT_QOM_EARLY
>>> approach that I suggested on v1, rather than special casing both
>>> the base classes and MODULE_INIT_TARGET_INFO
>>>
>>
>> I'm ok to follow your approach if you really prefer it.
>> However, can you specify what should be the semantic to put in comment
>> for it? I have trouble finding to explain what is early vs non early,
>> while it's clear for me what is TARGET_INFO vs REST_OF_QOM.
>
> I don't think we need to set our strong rules. It is just an early
> startup hook to be used by classes which are a dependency of other
> initialization code. Conceptually this is similar to what we did
> in system/vl.c, where we have various stages for creating -object
> args. What goes in each stage is simply determined by a functional
> need at the point in time.
>
Ok!
>> As well, adding a INIT_QOM_EARLY implies we need to call it in all
>> locations where we already call INIT_QOM for future-proofing, which
>> seems very redundant. Should we had it or not?
>
> Yep, that's true, but not the end of the world imho.
>
I'll go this route then, and initialize TYPE_OBJECT and TYPE_INTERFACE
in QOM_INIT_EARLY step along with target info.
> Ultimately an solution is a bit of a hack. Long term what we need
> to do is follow glib's approach from GType and have "just in time"
> initialization on first use which will make everything "just work"
> without having to think about ordering. I didn't want to suggest
> that now though, as it has potential to be a can of worms.
>
This is kind of what we do already. First time we access a type, it's
initialized. The only thing done statically is registering types, which
does not trigger anything except adding them to the global type table.
The current issue is more a dependency issue between target-info VS
other types, which is why I thought Marc-André suggestion was better
than a generic QOM_INIT_EARLY. But I don't mind following this approach,
my goal is just to have something that works for our need.
Regards,
Pierrick
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main
2026-04-30 17:28 ` Pierrick Bouvier
@ 2026-04-30 17:37 ` Pierrick Bouvier
0 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 17:37 UTC (permalink / raw)
To: Daniel P. Berrangé
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov
On 4/30/2026 10:28 AM, Pierrick Bouvier wrote:
> On 4/30/2026 10:07 AM, Daniel P. Berrangé wrote:
>> On Thu, Apr 30, 2026 at 09:03:52AM -0700, Pierrick Bouvier wrote:
>>> On 4/30/2026 12:12 AM, Daniel P. Berrangé wrote:
>>>> On Wed, Apr 29, 2026 at 08:56:22PM -0700, 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.
>>>>>
>>>>> 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)
>>>>
>>>> IMHO this should have been done using the MODULE_INIT_QOM_EARLY
>>>> approach that I suggested on v1, rather than special casing both
>>>> the base classes and MODULE_INIT_TARGET_INFO
>>>>
>>>
>>> I'm ok to follow your approach if you really prefer it.
>>> However, can you specify what should be the semantic to put in comment
>>> for it? I have trouble finding to explain what is early vs non early,
>>> while it's clear for me what is TARGET_INFO vs REST_OF_QOM.
>>
>> I don't think we need to set our strong rules. It is just an early
>> startup hook to be used by classes which are a dependency of other
>> initialization code. Conceptually this is similar to what we did
>> in system/vl.c, where we have various stages for creating -object
>> args. What goes in each stage is simply determined by a functional
>> need at the point in time.
>>
>
> Ok!
>
>>> As well, adding a INIT_QOM_EARLY implies we need to call it in all
>>> locations where we already call INIT_QOM for future-proofing, which
>>> seems very redundant. Should we had it or not?
>>
>> Yep, that's true, but not the end of the world imho.
>>
>
> I'll go this route then, and initialize TYPE_OBJECT and TYPE_INTERFACE
> in QOM_INIT_EARLY step along with target info.
>
>> Ultimately an solution is a bit of a hack. Long term what we need
>> to do is follow glib's approach from GType and have "just in time"
>> initialization on first use which will make everything "just work"
>> without having to think about ordering. I didn't want to suggest
>> that now though, as it has potential to be a can of worms.
>>
>
> This is kind of what we do already. First time we access a type, it's
> initialized. The only thing done statically is registering types, which
> does not trigger anything except adding them to the global type table.
>
More exactly, we statically register the function registration, and then
the module_init "orders" calling them at different chosen steps.
> The current issue is more a dependency issue between target-info VS
> other types, which is why I thought Marc-André suggestion was better
> than a generic QOM_INIT_EARLY. But I don't mind following this approach,
> my goal is just to have something that works for our need.
>
> Regards,
> Pierrick
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 4/7] target/xtensa/core: register types using type_init
2026-04-30 3:56 [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
` (2 preceding siblings ...)
2026-04-30 3:56 ` [PATCH v2 3/7] qom/object: register OBJECT and INTERFACE QOM types before main Pierrick Bouvier
@ 2026-04-30 3:56 ` Pierrick Bouvier
2026-04-30 4:48 ` Philippe Mathieu-Daudé
2026-04-30 3:56 ` [PATCH v2 5/7] system/vl: register target info types first in qom Pierrick Bouvier
` (3 subsequent siblings)
7 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 3:56 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov, Daniel P. Berrangé
Instead of using a static constructor, delay registering those types
until we call module_init(MODULE_INIT_QOM).
This is not yet a problem, but since we will start initializing
target-info types before any other, without this patch
qemu-system-xtensa* fails with:
Type 'dsp3400-xtensa-cpu' is missing its parent 'xtensa-cpu'
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
target/xtensa/overlay_tool.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/target/xtensa/overlay_tool.h b/target/xtensa/overlay_tool.h
index 701c00eed20..b9eaffa4871 100644
--- a/target/xtensa/overlay_tool.h
+++ b/target/xtensa/overlay_tool.h
@@ -451,13 +451,14 @@
#if TARGET_BIG_ENDIAN == (XCHAL_HAVE_BE != 0)
#define REGISTER_CORE(core) \
- static void __attribute__((constructor)) register_core(void) \
+ static void register_core(void) \
{ \
static XtensaConfigList node = { \
.config = &core, \
}; \
xtensa_register_core(&node); \
- }
+ } \
+ type_init(register_core)
#else
#define REGISTER_CORE(core)
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v2 4/7] target/xtensa/core: register types using type_init
2026-04-30 3:56 ` [PATCH v2 4/7] target/xtensa/core: register types using type_init Pierrick Bouvier
@ 2026-04-30 4:48 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 19+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-04-30 4:48 UTC (permalink / raw)
To: Pierrick Bouvier, qemu-devel
Cc: Richard Henderson, Markus Armbruster, Anton Johansson,
marcandre.lureau, Paolo Bonzini, Max Filippov,
Daniel P. Berrangé
On 30/4/26 05:56, Pierrick Bouvier wrote:
> Instead of using a static constructor, delay registering those types
> until we call module_init(MODULE_INIT_QOM).
>
> This is not yet a problem, but since we will start initializing
> target-info types before any other, without this patch
> qemu-system-xtensa* fails with:
> Type 'dsp3400-xtensa-cpu' is missing its parent 'xtensa-cpu'
>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> ---
> target/xtensa/overlay_tool.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 5/7] system/vl: register target info types first in qom
2026-04-30 3:56 [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
` (3 preceding siblings ...)
2026-04-30 3:56 ` [PATCH v2 4/7] target/xtensa/core: register types using type_init Pierrick Bouvier
@ 2026-04-30 3:56 ` Pierrick Bouvier
2026-04-30 7:47 ` Daniel P. Berrangé
2026-04-30 3:56 ` [PATCH v2 6/7] target-info-qom: detect target from QOM Pierrick Bouvier
` (2 subsequent siblings)
7 siblings, 1 reply; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 3:56 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov, Daniel P. Berrangé
We will introduce detection of target from QOM, so we need to make sure
those types are registered. As well, it ensure no other types are
registered yet, so we can safely call object_class_get_list.
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
include/qemu/module.h | 1 +
include/qemu/target-info-init.h | 17 +++++++++++++----
system/vl.c | 3 +++
target-info-qom.c | 18 +++++++++++-------
4 files changed, 28 insertions(+), 11 deletions(-)
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
index 1e52ad62820..859451c672e 100644
--- a/include/qemu/target-info-init.h
+++ b/include/qemu/target-info-init.h
@@ -12,6 +12,14 @@
#ifndef TARGET_INFO_DEF_H
#define TARGET_INFO_DEF_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
/*
@@ -53,17 +61,18 @@ static void target_info_qom_class_init(ObjectClass *oc, const void * data) \
klass->parent_class.target_info = &ti_var; \
} \
\
-static const TypeInfo target_info_qom_target_type_info[] = { \
-{ \
+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)
+}; \
+ \
+DEFINE_TARGET_INFO_TYPE(target_info_qom_target_type_info)
#endif /* CONFIG_USER_ONLY */
+#endif /* COMPILING_PER_TARGET */
#endif /* TARGET_INFO_DEF_H */
diff --git a/system/vl.c b/system/vl.c
index 0e1fc217b4f..dce1170203f 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2888,6 +2888,9 @@ void qemu_init(int argc, char **argv)
os_setup_limits();
+ /* ensure target-info types are registered before selecting target */
+ 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 5ce29f80301..ba2c7923760 100644
--- a/target-info-qom.c
+++ b/target-info-qom.c
@@ -10,17 +10,11 @@
#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[] = {
- {
- .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,
@@ -32,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)
--
2.43.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v2 5/7] system/vl: register target info types first in qom
2026-04-30 3:56 ` [PATCH v2 5/7] system/vl: register target info types first in qom Pierrick Bouvier
@ 2026-04-30 7:47 ` Daniel P. Berrangé
2026-04-30 18:57 ` Pierrick Bouvier
0 siblings, 1 reply; 19+ messages in thread
From: Daniel P. Berrangé @ 2026-04-30 7:47 UTC (permalink / raw)
To: Pierrick Bouvier
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov
On Wed, Apr 29, 2026 at 08:56:24PM -0700, Pierrick Bouvier wrote:
> We will introduce detection of target from QOM, so we need to make sure
> those types are registered. As well, it ensure no other types are
> registered yet, so we can safely call object_class_get_list.
>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> ---
> include/qemu/module.h | 1 +
> include/qemu/target-info-init.h | 17 +++++++++++++----
> system/vl.c | 3 +++
> target-info-qom.c | 18 +++++++++++-------
> 4 files changed, 28 insertions(+), 11 deletions(-)
>
> 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,
Please introduce a MODULE_INIT_QOM_EARLY as requested in v1. As well
as being needed for the base classes in an earlier patch, it is
inevitable that we will find module scenarios needing early init
over time.
> MODULE_INIT_QOM,
> MODULE_INIT_TRACE,
> MODULE_INIT_XEN_BACKEND,
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2 5/7] system/vl: register target info types first in qom
2026-04-30 7:47 ` Daniel P. Berrangé
@ 2026-04-30 18:57 ` Pierrick Bouvier
0 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 18:57 UTC (permalink / raw)
To: Daniel P. Berrangé
Cc: qemu-devel, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov
On 4/30/2026 12:47 AM, Daniel P. Berrangé wrote:
> On Wed, Apr 29, 2026 at 08:56:24PM -0700, Pierrick Bouvier wrote:
>> We will introduce detection of target from QOM, so we need to make sure
>> those types are registered. As well, it ensure no other types are
>> registered yet, so we can safely call object_class_get_list.
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
>> ---
>> include/qemu/module.h | 1 +
>> include/qemu/target-info-init.h | 17 +++++++++++++----
>> system/vl.c | 3 +++
>> target-info-qom.c | 18 +++++++++++-------
>> 4 files changed, 28 insertions(+), 11 deletions(-)
>>
>> 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,
>
> Please introduce a MODULE_INIT_QOM_EARLY as requested in v1. As well
> as being needed for the base classes in an earlier patch, it is
> inevitable that we will find module scenarios needing early init
> over time.
>
Done in v3 coming.
Thanks,
Pierrick
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 6/7] target-info-qom: detect target from QOM
2026-04-30 3:56 [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
` (4 preceding siblings ...)
2026-04-30 3:56 ` [PATCH v2 5/7] system/vl: register target info types first in qom Pierrick Bouvier
@ 2026-04-30 3:56 ` Pierrick Bouvier
2026-04-30 3:56 ` [PATCH v2 7/7] target-info: replace target_info() in system-mode Pierrick Bouvier
2026-04-30 20:40 ` [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
7 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 3:56 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov, Daniel P. Berrangé
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 dce1170203f..f98fa030d08 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)
/* ensure target-info types are registered before selecting target */
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] 19+ messages in thread* [PATCH v2 7/7] target-info: replace target_info() in system-mode
2026-04-30 3:56 [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
` (5 preceding siblings ...)
2026-04-30 3:56 ` [PATCH v2 6/7] target-info-qom: detect target from QOM Pierrick Bouvier
@ 2026-04-30 3:56 ` Pierrick Bouvier
2026-04-30 20:40 ` [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
7 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 3:56 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Philippe Mathieu-Daudé, Richard Henderson,
Markus Armbruster, Anton Johansson, marcandre.lureau,
Paolo Bonzini, Max Filippov, Daniel P. Berrangé
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 859451c672e..a9efd8a1e40 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] 19+ messages in thread* Re: [PATCH v2 0/7] single-binary: deduplicate target_info()
2026-04-30 3:56 [PATCH v2 0/7] single-binary: deduplicate target_info() Pierrick Bouvier
` (6 preceding siblings ...)
2026-04-30 3:56 ` [PATCH v2 7/7] target-info: replace target_info() in system-mode Pierrick Bouvier
@ 2026-04-30 20:40 ` Pierrick Bouvier
7 siblings, 0 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2026-04-30 20:40 UTC (permalink / raw)
To: qemu-devel
Cc: Philippe Mathieu-Daudé, Richard Henderson, Markus Armbruster,
Anton Johansson, marcandre.lureau, Paolo Bonzini, Max Filippov,
Daniel P. Berrangé
On 4/29/2026 8:56 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.
>
> 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 (7):
> target-info: extract target_info() definition in target-info-init.h
> target-info: introduce TargetInfo in QOM
> qom/object: register OBJECT and INTERFACE QOM types before main
> target/xtensa/core: register types using type_init
> system/vl: register target info types first in qom
> 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/module.h | 1 +
> include/qemu/target-info-init.h | 73 +++++++++++++++++++++++++++++++
> include/qemu/target-info-qom.h | 30 +++++++++++++
> qom/object.c | 4 +-
> system/vl.c | 5 +++
> target-info-qom.c | 35 +++++++++++++++
> target-info-stub.c | 6 +--
> target/xtensa/overlay_tool.h | 5 ++-
> 10 files changed, 154 insertions(+), 17 deletions(-)
> create mode 100644 include/qemu/target-info-init.h
> create mode 100644 include/qemu/target-info-qom.h
>
sent v3:
https://lore.kernel.org/qemu-devel/20260430203842.29156-1-pierrick.bouvier@oss.qualcomm.com/T/#t
Regards,
Pierrick
^ permalink raw reply [flat|nested] 19+ messages in thread