Commit 6183ff5953 for qemu.org
commit 6183ff59530cbf1ed63020aaaabad7963062f16f
Author: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Date: Sat Oct 24 16:32:42 2026 +0000
tcg: prefix helpers with target base architecture
Now we made sure all helpers and helper_info are defined and used using
HELPER/HELPER_INFO macros, we are ready to introduce a target prefix.
We can't reuse TARGET_ARCH since it's not defined for common code, and
it's also poisoned. So introduce a new TARGET_ARCH_PREFIX which is
defined for all target code (whether it's common or target specific),
and use it as prefix.
On some hosts (found it on sparc), predefined macros exist for the base
architecture names we use, and their value is 1. (#define sparc 1). So,
we can't use them directly or it would create a illformed identifier for
function names. So to prevent any problem, use additional "target",
which gives -DTARGET_ARCH_PREFIX=target_<TARGET_ARCH>.
Finally there is one last catch: beyond target helpers, tcg also has
common helpers. For those ones, we want an empty prefix, since they are
defined on tcg side and not target side.
With this, we now have target prefixed helpers, preventing symbol
conflicts when linking targets together.
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Anton Johansson <anjo@rev.ng>
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Link: https://lore.kernel.org/qemu-devel/20261024163249.77855-5-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
diff --git a/include/exec/helper-gen-common.h b/include/exec/helper-gen-common.h
index 834590dc4e..12e220c8ce 100644
--- a/include/exec/helper-gen-common.h
+++ b/include/exec/helper-gen-common.h
@@ -7,8 +7,15 @@
#ifndef HELPER_GEN_COMMON_H
#define HELPER_GEN_COMMON_H
+#include "exec/helper-head.h.inc"
+
+/* Common helpers are built once, without a target prefix. */
+#pragma push_macro("HELPER_PREFIX")
+#undef HELPER_PREFIX
+#define HELPER_PREFIX
#define HELPER_H "accel/tcg/tcg-runtime.h"
#include "exec/helper-gen.h.inc"
#undef HELPER_H
+#pragma pop_macro("HELPER_PREFIX")
#endif /* HELPER_GEN_COMMON_H */
diff --git a/include/exec/helper-head.h.inc b/include/exec/helper-head.h.inc
index be1d79cf01..fd03b1f170 100644
--- a/include/exec/helper-head.h.inc
+++ b/include/exec/helper-head.h.inc
@@ -8,8 +8,13 @@
#include "fpu/softfloat-types.h"
-#define HELPER(name) glue(helper_, name)
-#define HELPER_INFO(name) glue(helper_info_, name)
+#ifdef TARGET_ARCH_PREFIX
+ #define HELPER_PREFIX glue(TARGET_ARCH_PREFIX, _)
+#else
+ #define HELPER_PREFIX
+#endif
+#define HELPER(name) glue(HELPER_PREFIX, glue(helper_, name))
+#define HELPER_INFO(name) glue(HELPER_PREFIX, glue(helper_info_, name))
/* Some types that make sense in C, but not for TCG. */
#define dh_alias_i32 i32
diff --git a/include/exec/helper-proto-common.h b/include/exec/helper-proto-common.h
index 76e6c25bec..4433ba47a8 100644
--- a/include/exec/helper-proto-common.h
+++ b/include/exec/helper-proto-common.h
@@ -9,9 +9,16 @@
#include "qemu/atomic128.h" /* for HAVE_CMPXCHG128 */
+#include "exec/helper-head.h.inc"
+
+/* Common helpers are built once, without a target prefix. */
+#pragma push_macro("HELPER_PREFIX")
+#undef HELPER_PREFIX
+#define HELPER_PREFIX
#define HELPER_H "accel/tcg/tcg-runtime.h"
#include "exec/helper-proto.h.inc"
#undef HELPER_H
+#pragma pop_macro("HELPER_PREFIX")
#include "accel/tcg/getpc.h"
diff --git a/meson.build b/meson.build
index 4f29bc6cc3..ad537e0c18 100644
--- a/meson.build
+++ b/meson.build
@@ -4167,6 +4167,7 @@ foreach target_base_arch, config_base_arch : config_base_arch_mak
# prevent common code to access cpu compile time definition,
# but still allow access to cpu.h
target_c_args = ['-DCPU_DEFS_H']
+ target_c_args += ['-DTARGET_ARCH_PREFIX=target_' + target_base_arch.to_lower()]
target_system_c_args = target_c_args + ['-DCOMPILING_SYSTEM_VS_USER', '-DCONFIG_SOFTMMU']
if target_base_arch in target_common_arch
@@ -4290,6 +4291,7 @@ foreach target : target_dirs
arch_deps = []
c_args = ['-DCOMPILING_PER_TARGET',
'-DCONFIG_TARGET="@0@-config-target.h"'.format(target),
+ '-DTARGET_ARCH_PREFIX=target_' + target_base_arch.to_lower(),
]
link_args = emulator_link_args