Commit 5aefc06403 for qemu.org

commit 5aefc06403eda4fa0e4880fe1710a48d32bf3916
Author: Kohei Tokunaga <ktokunaga.mail@gmail.com>
Date:   Mon Aug 4 21:57:14 2025 +0900

    meson: Add wasm64 support to the --cpu flag

    wasm64 target enables 64bit pointers using Emscripten's -sMEMORY64=1
    flag[1]. This enables QEMU to run 64bit guests.

    Although the configure script uses "uname -m" as the fallback value when
    "cpu" is empty, this can't be used for Emscripten which targets to Wasm.
    So, in wasm build, this commit fixes configure to require --cpu flag to be
    explicitly specified by the user.

    [1] https://emscripten.org/docs/tools_reference/settings_reference.html#memory64

    Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
    Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
    Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
    Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
    Message-ID: <91f16f0e9ae6b36fbf0c2caac510dcf855120400.1768308374.git.ktokunaga.mail@gmail.com>
    Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

diff --git a/configure b/configure
index 55e0bd3425..92bfc5f976 100755
--- a/configure
+++ b/configure
@@ -365,7 +365,6 @@ elif check_define __APPLE__; then
   host_os=darwin
 elif check_define EMSCRIPTEN ; then
   host_os=emscripten
-  cpu=wasm32
   cross_compile="yes"
 else
   # This is a fatal error, but don't report it yet, because we
@@ -419,6 +418,8 @@ elif check_define __aarch64__ ; then
   cpu="aarch64"
 elif check_define __loongarch64 ; then
   cpu="loongarch64"
+elif check_define EMSCRIPTEN ; then
+  error_exit "wasm32 or wasm64 must be specified to the cpu flag"
 else
   # Using uname is really broken, but it is just a fallback for architectures
   # that are going to use TCI anyway
@@ -519,6 +520,9 @@ case "$cpu" in
   wasm32)
     CPU_CFLAGS="-m32"
     ;;
+  wasm64)
+    CPU_CFLAGS="-m64 -sMEMORY64=1"
+    ;;
 esac

 if test -n "$host_arch" && {
diff --git a/meson.build b/meson.build
index c58007291a..600c50007d 100644
--- a/meson.build
+++ b/meson.build
@@ -51,7 +51,7 @@ qapi_trace_events = []
 bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin']
 supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux', 'emscripten']
 supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
-  'arm', 'aarch64', 'loongarch64', 'mips64', 'sparc64', 'wasm32']
+  'arm', 'aarch64', 'loongarch64', 'mips64', 'sparc64', 'wasm32', 'wasm64']

 cpu = host_machine.cpu_family()

@@ -923,7 +923,7 @@ if have_tcg
     if not get_option('tcg_interpreter')
       error('Unsupported CPU @0@, try --enable-tcg-interpreter'.format(cpu))
     endif
-  elif host_arch == 'wasm32'
+  elif host_arch == 'wasm32' or host_arch == 'wasm64'
     if not get_option('tcg_interpreter')
       error('WebAssembly host requires --enable-tcg-interpreter')
     endif