All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Cc: "Yonggang Luo" <luoyonggang@gmail.com>,
	qemu-devel@nongnu.org, "Xianglai Li" <lixianglai@loongson.cn>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Chinmay Rath" <rathc@linux.ibm.com>,
	"Sunil V L" <sunilvl@ventanamicro.com>,
	qemu-riscv@nongnu.org, "Alexander Bulekov" <alxndr@bu.edu>,
	"Zhao Liu" <zhao1.liu@intel.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Chao Liu" <chao.liu@processmission.com>,
	"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Song Gao" <17746591750@163.com>,
	"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
	"Glenn Miles" <milesg@linux.ibm.com>,
	"Daniel Henrique Barboza" <daniel.barboza@oss.qualcomm.com>,
	qemu-s390x@nongnu.org, "Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"David Hildenbrand" <david@kernel.org>,
	qemu-ppc@nongnu.org, qemu-arm@nongnu.org,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Aleksandar Rikalo" <arikalo@gmail.com>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Bibo Mao" <maobibo@loongson.cn>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Matthew Rosato" <mjrosato@linux.ibm.com>,
	"Weiwei Li" <liwei1518@gmail.com>,
	"Darren Kenny" <darren.kenny@oracle.com>
Subject: Re: [PATCH 12/12] meson: link ARM and RISC-V into qemu-system
Date: Wed, 26 Aug 2026 14:00:11 +0100	[thread overview]
Message-ID: <ao7jWx-zfmB9AUEb@redhat.com> (raw)
In-Reply-To: <b9f0853b-adda-457d-94e1-add9bb2a2548@oss.qualcomm.com>

On Mon, Aug 24, 2026 at 09:20:38AM -0700, Pierrick Bouvier wrote:
> On 8/23/2026 8:07 AM, Yonggang Luo wrote:
> > - Build qemu-system (and qemu-systemw on Windows) from aarch64
> >   common/system objects plus RISC-V arch objects taken from the
> >   existing riscv64 lib.
> > - Pull 32-bit TargetInfo and 32-only boards from the arm/riscv32
> >   libs so hw/arm and target/riscv are not compiled twice.
> > - Skip linking qemu-system-{arm,aarch64,riscv32,riscv64} and the
> >   Windows *w variants; symlink those names to qemu-system so
> >   argv[0] still selects TargetInfo.
> > 
> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > ---
> >  meson.build | 156 +++++++++++++++++++++++++++++++++++++++++++++++++---
> >  1 file changed, 147 insertions(+), 9 deletions(-)

I think this approach of taking common/system from aarch64
and adding in riscv specific objects only works by luck.

That's not obvious from your patch, but Pierrick's counterproposal
below will expose it with a little  tweak....


> From 6261b0c255e1a8f0df2b41928b8dfb365d0fa488 Mon Sep 17 00:00:00 2001
> From: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> Date: Tue, 14 Apr 2026 10:56:15 -0700
> Subject: [PATCH] meson: build single binary
> 
> This is not built by default.
> Build with: ninja -C build qemu-system
> 
> All available *-softmmu targets are aggregated, ./configure
> --target-list can be used to restrict which targets are included.
> 
> In case user has targets that are not supported, we emit an error
> message when build qemu-system target. This way, it's not necessary to
> have a custom configure flag, and qemu-system can live next to existing
> binaries without complexifying the workflow more than it is already.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> ---
>  meson.build | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)
> 
> diff --git a/meson.build b/meson.build
> index 553df3e7f053..4a31a520d9eb 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -4264,6 +4264,9 @@ if host_os == 'darwin'
>  endif
>  
>  traceable = []
> +single_binary_libs = []
> +single_binary_deps = []
> +single_binary_crates = []
>  emulators = {}
>  foreach target : target_dirs
>    config_target = config_target_mak[target]
> @@ -4419,6 +4422,10 @@ foreach target : target_dirs
>                   build_by_default: false)
>  
>    if target.endswith('-softmmu')
> +    single_binary_libs += lib
> +    single_binary_deps += arch_deps
> +    single_binary_deps += target_stubs
> +    single_binary_crates += main_rs
>      execs = [{
>        'name': 'qemu-system-' + target_name,
>        'win_subsystem': 'console',
> @@ -4500,6 +4507,47 @@ foreach target : target_dirs
>    endforeach
>  endforeach
>  
> +single_binary_objects = []
> +foreach lib: single_binary_libs
> +  single_binary_objects += lib.extract_all_objects(recursive: true)
> +endforeach
> +
> +single_binary_link_args = emulator_link_args
> +single_binary_link_args += enable_modules ? ['@block.syms', '@qemu.syms'] : []
> +
> +supported_targets = [
> +  'aarch64-softmmu',
> +  'arm-softmmu',
> +]

Adding in riscv64-softmmu to this list and building with
configure --target-list=aarch64-softmmu,riscv64-softmmu
will fail with this meson approach.

Specifically we'll hit duplicate symbols to to taking
different KConfig branches, resulting in building in
both the real impl and the stubs:

  /usr/bin/ld.bfd: libsystem.a.p/hw_pci-bridge_pci_expander_bridge_stubs.c.o: in function `pxb_cxl_hook_up_registers':
/home/berrange/src/virt/qemu/build-alt/../hw/pci-bridge/pci_expander_bridge_stubs.c:14: multiple definition of `pxb_cxl_hook_up_registers'; libsystem.a.p/hw_pci-bridge_pci_expander_bridge.c.o:/home/berrange/src/virt/qemu/build-alt/../hw/pci-bridge/pci_expander_bridge.c:214: first defined here

The problem is that aarch64 enables CONFIG_PXB and
riscv64 does not.

Yonggang's patch only worked by luck since it preferred
to the common system objects from aarch64 and thus kept
the real PXB impl. If Yonggang had instead used common
system objects from riscv64, the qemu-system would have
lost the PXB impl and got a stub.

This is unfixable if both targets have some Kconfigs
that the other target does not.

So to be able to build qemu-system, we can't simply
pull in the union of objects from each architecture
qemu-system-$TARGET binary. 

Instead we need to setup a new Kconfig specifically
for qemu-system, which is the combination of all
Kconfigs from each target. Then derive a new list
of objects from that.  This shouldn't involve building
any more .o files, just means we build an accurate
list of what .o files we need.

> +unsupported_targets = []
> +foreach target : target_dirs
> +  if target.endswith('-softmmu') and target not in supported_targets
> +    unsupported_targets += target
> +  endif
> +endforeach
> +
> +if unsupported_targets.length() == 0
> +  executable('qemu-system',
> +             sources: [single_binary_crates, files('system/main.c')],
> +             dependencies: single_binary_deps,
> +             objects: single_binary_objects,
> +             link_depends: [block_syms, qemu_syms],
> +             link_args: single_binary_link_args,
> +             build_by_default: false)
> +else
> +  error_str = f'''qemu-system only support targets:
> +@supported_targets@

With the Kconfig union problem solved, IMHO we should unconditionally
always build the 'qemu-system' binary. If there are targets that
do not yet support the single bniary concept that's fine, just ignore
them. qemu-system-$TARGET will still be built for everything, and
qemu-system only needs to include what's currently possible.


> +
> +unsupported targets:
> +@unsupported_targets@
> +
> +use ./configure --target-list= to choose list of targets'''
> +  t = custom_target(command: ['sh', '-c', 'echo "' + error_str + '" && exit 1'],
> +                    output: 'none',
> +                    build_by_default: false)
> +  alias_target('qemu-system', t)
> +endif
> +
>  # Other build targets
>  
>  if get_option('plugins')


With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



  parent reply	other threads:[~2026-08-26 13:00 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-23 15:07 [PATCH 00/12] single-binary: link ARM and RISC-V into qemu-system Yonggang Luo
2026-08-23 15:07 ` [PATCH 01/12] accel: use a shared TYPE_ACCEL_CPU parent Yonggang Luo
2026-08-23 15:07 ` [PATCH 02/12] hw/riscv/virt: use unique QOM name and target filter Yonggang Luo
2026-08-23 15:07 ` [PATCH 03/12] hw/arm/virt: " Yonggang Luo
2026-08-26 12:49   ` Daniel P. Berrangé
2026-08-23 15:07 ` [PATCH 04/12] hw/arm/virt: prefix ACPI helpers with arm_virt_ Yonggang Luo
2026-08-24  7:18   ` Philippe Mathieu-Daudé
2026-08-23 15:07 ` [PATCH 05/12] hw/riscv/virt: prefix ACPI helpers with riscv_virt_ Yonggang Luo
2026-08-24  7:19   ` Philippe Mathieu-Daudé
2026-08-23 15:07 ` [PATCH 06/12] hw/loongarch/virt: prefix ACPI helper with loongarch_virt_ Yonggang Luo
2026-08-24  1:00   ` gaosong
2026-08-24  7:20   ` Philippe Mathieu-Daudé
2026-08-23 15:07 ` [PATCH 07/12] target/riscv: uniquify TCG crc32, crc32c, and wfi helper names Yonggang Luo
2026-08-24  7:22   ` Philippe Mathieu-Daudé
2026-08-23 15:07 ` [PATCH 08/12] target/riscv: seed cfg.big_endian from TargetInfo Yonggang Luo
2026-08-26 18:37   ` Philippe Mathieu-Daudé
2026-08-23 15:07 ` [PATCH 09/12] target-info: register le and be TargetInfo variants Yonggang Luo
2026-08-24 16:22   ` Pierrick Bouvier
2026-08-24 19:01     ` Yonggang Luo
2026-08-26 18:41       ` Philippe Mathieu-Daudé
2026-08-23 15:07 ` [PATCH 10/12] target-info: add -target and program-name selection Yonggang Luo
2026-08-24 16:24   ` Pierrick Bouvier
2026-08-26 12:46   ` Daniel P. Berrangé
2026-08-26 18:13     ` Pierrick Bouvier
2026-08-27 10:13       ` Daniel P. Berrangé
2026-08-27 12:25     ` Daniel P. Berrangé
2026-08-23 15:07 ` [PATCH 11/12] target-info: dispatch CPU QMP, dump, and Angel semihosting Yonggang Luo
2026-08-23 15:07 ` [PATCH 12/12] meson: link ARM and RISC-V into qemu-system Yonggang Luo
2026-08-24 16:20   ` Pierrick Bouvier
2026-08-24 19:04     ` Yonggang Luo
2026-08-26 13:00     ` Daniel P. Berrangé [this message]
2026-08-26 17:40       ` Pierrick Bouvier
2026-08-26 18:05         ` Philippe Mathieu-Daudé
2026-08-26 18:08           ` Yonggang Luo
2026-08-24 16:36 ` [PATCH 00/12] single-binary: " Pierrick Bouvier
2026-08-25 15:42 ` Daniel P. Berrangé
2026-08-25 16:55   ` Yonggang Luo
2026-08-25 17:22     ` Daniel P. Berrangé
2026-08-25 17:11   ` Yonggang Luo
2026-08-26 12:32 ` Daniel P. Berrangé
2026-08-26 13:40   ` Mark Cave-Ayland
2026-08-26 13:58     ` Daniel P. Berrangé
2026-08-26 14:50     ` Yonggang Luo
2026-08-26 20:41     ` Daniel Henrique Barboza
2026-08-27  9:58       ` Daniel P. Berrangé
2026-08-26 18:35   ` Pierrick Bouvier
2026-08-26 18:53     ` Pierrick Bouvier
2026-08-27  9:44     ` Daniel P. Berrangé
2026-08-27 16:32       ` Pierrick Bouvier
2026-08-27 17:42         ` Peter Maydell
2026-08-27 17:48         ` Paolo Bonzini
2026-08-27 19:58           ` Pierrick Bouvier
2026-09-04 12:47             ` Paolo Bonzini
2026-09-14  5:46               ` Pierrick Bouvier
2026-08-27 10:22     ` Daniel P. Berrangé
2026-08-27 17:59   ` Paolo Bonzini
2026-08-28  5:44     ` Yonggang Luo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ao7jWx-zfmB9AUEb@redhat.com \
    --to=berrange@redhat.com \
    --cc=17746591750@163.com \
    --cc=alex.bennee@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=alxndr@bu.edu \
    --cc=anisinha@redhat.com \
    --cc=arikalo@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=chao.liu@processmission.com \
    --cc=cohuck@redhat.com \
    --cc=daniel.barboza@oss.qualcomm.com \
    --cc=darren.kenny@oracle.com \
    --cc=david@kernel.org \
    --cc=farman@linux.ibm.com \
    --cc=farosas@suse.de \
    --cc=harshpb@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=imammedo@redhat.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=liwei1518@gmail.com \
    --cc=lixianglai@loongson.cn \
    --cc=luoyonggang@gmail.com \
    --cc=lvivier@redhat.com \
    --cc=maobibo@loongson.cn \
    --cc=marcandre.lureau@redhat.com \
    --cc=milesg@linux.ibm.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=mst@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@mailo.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=rathc@linux.ibm.com \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    --cc=sunilvl@ventanamicro.com \
    --cc=zhao1.liu@intel.com \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.