@samitouri / QOSamiQemu / commits / cf634dfcd8

Allow building qemu tools on 32-bit hosts

Qemu's tools like qemu-img are often needed on 32-bit platforms, although the actual qemu emulators have been discontinued on 32-bit. To allow building the tools on 32-bit this patch implements three small changes: a) The check in meson.build is changed to still error out if the user tries to build qemu-system or qemu-user on a 32-bit platform, but allows building tools (e.g. by "--enable-tools") alone. b) The compile time check in atomic.h now checks against sizeof(uint64_t) so that 32-bit environments can still build successfully, while 128-bit atomic operations are prevented to sneak in. c) Allow linking against libatomic as long as we don't build the qemu-system and qemu-user binaries. Sucessfully tested on the 32-bit big-endian powerpc architecture. Signed-off-by: Helge Deller <deller@gmx.de> Suggested-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

Helge Deller committed Apr 5, 2026 at 00:40 UTC cf634dfcd8fc5dded8849d41e2eeaa189b06feb0
2 files changed +15 -7
include/qemu/atomic.h
+3 -3
@@ -58,11 +58,11 @@
58
59 /*
60 * Sanity check that the size of an atomic operation isn't "overly large".
61 - * Despite the fact that e.g. i686 has 64-bit atomic operations, we do not
61 + * Despite the fact that e.g. x86-64 has 128-bit atomic operations, we do not
62 * want to use them because we ought not need them, and this lets us do a
63 - * bit of sanity checking that other 32-bit hosts might build.
63 + * bit of sanity checking that other 32- and 64-bit hosts might build.
64 */
65 -#define ATOMIC_REG_SIZE sizeof(void *)
65 +#define ATOMIC_REG_SIZE sizeof(uint64_t)
66
67 /* Weak atomic operations prevent the compiler moving other
68 * loads/stores past the atomic operation load/store. However there is
meson.build
+12 -4
@@ -323,8 +323,8 @@ endif
323 # Compiler flags #
324 ##################
325
326 -if cc.sizeof('void *') < 8
327 - error('QEMU requires a 64-bit CPU host architecture')
326 +if (cc.sizeof('void *') < 8) and (have_system or have_user)
327 + error('QEMU emulator requires a 64-bit CPU host architecture. Only tools may be built for 32-bit.')
328 endif
329
330 foreach lang : all_languages
@@ -423,8 +423,16 @@ endif
423 #
424 # Later checks assume we won't get atomic ops for int128 without
425 # explicitly asking for -latomic, so we must disable GCC's new
426 -# automatic linking with the new -fno-link-libatomic flag
427 -qemu_isa_flags += cc.get_supported_arguments('-fno-link-libatomic')
426 +# automatic linking with the new -fno-link-libatomic flag.
427 +#
428 +# When not building the emulators, but qemu helper tools only
429 +# (e.g. on 32-bit hosts), libatomic is sometimes required and
430 +# thus acceptable.
431 +if (have_system or have_user)
432 + qemu_isa_flags += cc.get_supported_arguments('-fno-link-libatomic')
433 +else
434 + qemu_ldflags += cc.get_supported_link_arguments('-latomic')
435 +endif
436
437 qemu_common_flags = qemu_isa_flags + qemu_common_flags
438