From: Kohei Tokunaga <ktokunaga.mail@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Thomas Huth" <thuth@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"WANG Xuerui" <git@xen0n.name>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Huacai Chen" <chenhuacai@kernel.org>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Aleksandar Rikalo" <arikalo@gmail.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Alistair Francis" <Alistair.Francis@wdc.com>,
"Stefan Weil" <sw@weilnetz.de>,
qemu-arm@nongnu.org, qemu-riscv@nongnu.org,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
ktokunaga.mail@gmail.com
Subject: [PATCH v3 33/35] meson.build: enable to build Wasm backend
Date: Mon, 1 Sep 2025 20:44:35 +0900 [thread overview]
Message-ID: <e7333cfd991ce89b4003417eba0c8bdec927fa0b.1756724464.git.ktokunaga.mail@gmail.com> (raw)
In-Reply-To: <cover.1756724464.git.ktokunaga.mail@gmail.com>
Enable to use tcg/wasm as the TCG backend for the WebAssembly (wasm64)
build.
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
---
include/accel/tcg/getpc.h | 2 +-
include/tcg/helper-info.h | 4 ++--
include/tcg/tcg.h | 2 +-
meson.build | 6 ++++--
tcg/meson.build | 5 +++++
tcg/region.c | 10 +++++-----
tcg/tcg.c | 14 +++++++-------
7 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/include/accel/tcg/getpc.h b/include/accel/tcg/getpc.h
index 0fc08addcf..3901655715 100644
--- a/include/accel/tcg/getpc.h
+++ b/include/accel/tcg/getpc.h
@@ -9,7 +9,7 @@
#define ACCEL_TCG_GETPC_H
/* GETPC is the true target of the return instruction that we'll execute. */
-#ifdef CONFIG_TCG_INTERPRETER
+#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
extern __thread uintptr_t tci_tb_ptr;
# define GETPC() tci_tb_ptr
#else
diff --git a/include/tcg/helper-info.h b/include/tcg/helper-info.h
index 909fe73afa..9b4e8832a8 100644
--- a/include/tcg/helper-info.h
+++ b/include/tcg/helper-info.h
@@ -9,7 +9,7 @@
#ifndef TCG_HELPER_INFO_H
#define TCG_HELPER_INFO_H
-#ifdef CONFIG_TCG_INTERPRETER
+#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
#include <ffi.h>
#endif
#include "tcg-target-reg-bits.h"
@@ -48,7 +48,7 @@ struct TCGHelperInfo {
const char *name;
/* Used with g_once_init_enter. */
-#ifdef CONFIG_TCG_INTERPRETER
+#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
ffi_cif *cif;
#else
uintptr_t init;
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index a6d9aa50d4..b91818d982 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -963,7 +963,7 @@ static inline size_t tcg_current_code_size(TCGContext *s)
#define TB_EXIT_IDXMAX 1
#define TB_EXIT_REQUESTED 3
-#ifdef CONFIG_TCG_INTERPRETER
+#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
#else
typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
diff --git a/meson.build b/meson.build
index 5b048ea70f..42b9004a20 100644
--- a/meson.build
+++ b/meson.build
@@ -920,9 +920,9 @@ if have_tcg
if not get_option('tcg_interpreter')
error('Unsupported CPU @0@, try --enable-tcg-interpreter'.format(cpu))
endif
- elif host_arch == 'wasm32' or host_arch == 'wasm64'
+ elif host_arch == 'wasm32'
if not get_option('tcg_interpreter')
- error('WebAssembly host requires --enable-tcg-interpreter')
+ error('wasm32 host requires --enable-tcg-interpreter')
endif
elif get_option('tcg_interpreter')
warning('Use of the TCG interpreter is not recommended on this host')
@@ -938,6 +938,8 @@ if have_tcg
tcg_arch = 'i386'
elif host_arch == 'ppc64'
tcg_arch = 'ppc'
+ elif host_arch == 'wasm64'
+ tcg_arch = 'wasm'
endif
add_project_arguments('-iquote', meson.current_source_dir() / 'tcg' / tcg_arch,
language: all_languages)
diff --git a/tcg/meson.build b/tcg/meson.build
index 706a6eb260..1563f4fd30 100644
--- a/tcg/meson.build
+++ b/tcg/meson.build
@@ -20,6 +20,11 @@ if get_option('tcg_interpreter')
method: 'pkg-config')
tcg_ss.add(libffi)
tcg_ss.add(files('tci.c'))
+elif host_os == 'emscripten'
+ libffi = dependency('libffi', version: '>=3.0', required: true,
+ method: 'pkg-config')
+ specific_ss.add(libffi)
+ specific_ss.add(files('wasm.c'))
endif
tcg_ss.add(when: libdw, if_true: files('debuginfo.c'))
diff --git a/tcg/region.c b/tcg/region.c
index 7ea0b37a84..68cb6f18b7 100644
--- a/tcg/region.c
+++ b/tcg/region.c
@@ -94,7 +94,7 @@ bool in_code_gen_buffer(const void *p)
return (size_t)(p - region.start_aligned) <= region.total_size;
}
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
static int host_prot_read_exec(void)
{
#if defined(CONFIG_LINUX) && defined(HOST_AARCH64) && defined(PROT_BTI)
@@ -569,7 +569,7 @@ static int alloc_code_gen_buffer_anon(size_t size, int prot,
return prot;
}
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
#ifdef CONFIG_POSIX
#include "qemu/memfd.h"
@@ -667,11 +667,11 @@ static int alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp)
return PROT_READ | PROT_WRITE;
}
#endif /* CONFIG_DARWIN */
-#endif /* CONFIG_TCG_INTERPRETER */
+#endif /* !CONFIG_TCG_INTERPRETER && !EMSCRIPTEN */
static int alloc_code_gen_buffer_splitwx(size_t size, Error **errp)
{
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
# ifdef CONFIG_DARWIN
return alloc_code_gen_buffer_splitwx_vmremap(size, errp);
# endif
@@ -813,7 +813,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_threads)
* Work with the page protections set up with the initial mapping.
*/
need_prot = PROT_READ | PROT_WRITE;
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
if (tcg_splitwx_diff == 0) {
need_prot |= host_prot_read_exec();
}
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 7d3e7f8cb1..bd8f8e565f 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -256,7 +256,7 @@ TCGv_env tcg_env;
const void *tcg_code_gen_epilogue;
uintptr_t tcg_splitwx_diff;
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
tcg_prologue_fn *tcg_qemu_tb_exec;
#endif
@@ -1443,7 +1443,7 @@ static TCGHelperInfo info_helper_st128_mmu = {
| dh_typemask(ptr, 5) /* uintptr_t ra */
};
-#ifdef CONFIG_TCG_INTERPRETER
+#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
static ffi_type *typecode_to_ffi(int argmask)
{
/*
@@ -1520,7 +1520,7 @@ static ffi_cif *init_ffi_layout(TCGHelperInfo *info)
#else
#define HELPER_INFO_INIT(I) (&(I)->init)
#define HELPER_INFO_INIT_VAL(I) 1
-#endif /* CONFIG_TCG_INTERPRETER */
+#endif /* CONFIG_TCG_INTERPRETER || EMSCRIPTEN */
static inline bool arg_slot_reg_p(unsigned arg_slot)
{
@@ -1897,7 +1897,7 @@ void tcg_prologue_init(void)
s->code_buf = s->code_gen_ptr;
s->data_gen_ptr = NULL;
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
tcg_qemu_tb_exec = (tcg_prologue_fn *)tcg_splitwx_to_rx(s->code_ptr);
#endif
@@ -1916,7 +1916,7 @@ void tcg_prologue_init(void)
prologue_size = tcg_current_code_size(s);
perf_report_prologue(s->code_gen_ptr, prologue_size);
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf),
(uintptr_t)s->code_buf, prologue_size);
#endif
@@ -1953,7 +1953,7 @@ void tcg_prologue_init(void)
}
}
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
/*
* Assert that goto_ptr is implemented completely, setting an epilogue.
* For tci, we use NULL as the signal to return from the interpreter,
@@ -7055,7 +7055,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start)
return i;
}
-#ifndef CONFIG_TCG_INTERPRETER
+#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
/* flush instruction cache */
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf),
(uintptr_t)s->code_buf,
--
2.43.0
next prev parent reply other threads:[~2025-09-01 11:58 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-01 11:44 [PATCH v3 00/35] wasm: Add Wasm TCG backend based on wasm64 Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 01/35] meson: Add wasm64 support to the --cpu flag Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 02/35] configure: Enable to propagate -sMEMORY64 flag to Emscripten Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 03/35] dockerfiles: Add support for wasm64 to the wasm Dockerfile Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 04/35] .gitlab-ci.d: Add build tests for wasm64 Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 05/35] tcg/wasm: Add tcg-target.h and tcg-target-reg-bits.h Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 06/35] tcg/wasm: Add register-related definitions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 07/35] tcg/wasm: Add constraint definitions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 08/35] tcg/wasm: Add relocation callbacks Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 09/35] tcg/wasm: Add and/or/xor instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 10/35] tcg/wasm: Add add/sub/mul instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 11/35] tcg/wasm: Add shl/shr/sar instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 12/35] tcg/wasm: Add setcond/negsetcond/movcond instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 13/35] tcg/wasm: Add sextract instruction Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 14/35] tcg/wasm: Add load and store instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 15/35] tcg/wasm: Add mov/movi instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 16/35] tcg/wasm: Add ext instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 17/35] tcg/wasm: Add div/rem instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 18/35] tcg/wasm: Add neg/ctpop instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 19/35] tcg/wasm: Add rot/clz/ctz instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 20/35] tcg/wasm: Add br/brcond instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 21/35] tcg/wasm: Add exit_tb/goto_tb/goto_ptr instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 22/35] tcg/wasm: Add call instruction Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 23/35] tcg/wasm: Add qemu_ld/qemu_st instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 24/35] tcg/wasm: Add mb instruction Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 25/35] tcg/wasm: Mark unimplemented instructions Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 26/35] tcg/wasm: Add initialization of fundamental registers Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 27/35] tcg/wasm: Write wasm binary to TB Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 28/35] tcg/wasm: Implement instantiation of Wasm binary Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 29/35] tcg/wasm: Allow switching coroutine from a helper Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 30/35] tcg/wasm: Enable instantiation of TBs executed many times Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 31/35] tcg/wasm: Enable TLB lookup Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 32/35] tcg/wasm: Add tcg_target_init function Kohei Tokunaga
2025-09-01 11:44 ` Kohei Tokunaga [this message]
2025-09-01 11:44 ` [PATCH v3 34/35] meson.build: Propagate optimization flag for linking on Emscripten Kohei Tokunaga
2025-09-01 11:44 ` [PATCH v3 35/35] .gitlab-ci.d: build wasm backend in CI Kohei Tokunaga
2025-09-29 22:20 ` [PATCH v3 00/35] wasm: Add Wasm TCG backend based on wasm64 Pierrick Bouvier
2025-09-30 8:26 ` Kohei Tokunaga
2025-10-01 23:08 ` Pierrick Bouvier
2025-10-02 1:33 ` Pierrick Bouvier
2025-10-02 15:59 ` Kohei Tokunaga
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=e7333cfd991ce89b4003417eba0c8bdec927fa0b.1756724464.git.ktokunaga.mail@gmail.com \
--to=ktokunaga.mail@gmail.com \
--cc=Alistair.Francis@wdc.com \
--cc=alex.bennee@linaro.org \
--cc=arikalo@gmail.com \
--cc=aurelien@aurel32.net \
--cc=berrange@redhat.com \
--cc=chenhuacai@kernel.org \
--cc=git@xen0n.name \
--cc=jiaxun.yang@flygoat.com \
--cc=marcandre.lureau@redhat.com \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=stefanha@redhat.com \
--cc=sw@weilnetz.de \
--cc=thuth@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).