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. Signed-off-by: Pierrick Bouvier <[email protected]> --- include/exec/helper-gen-common.h | 7 +++++++ include/exec/helper-head.h.inc | 9 +++++++-- include/exec/helper-proto-common.h | 7 +++++++ meson.build | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/exec/helper-gen-common.h b/include/exec/helper-gen-common.h index 834590dc4e5..12e220c8ce9 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 be1d79cf017..fd03b1f1704 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 76e6c25becb..4433ba47a82 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 bbef9d9c293..5c8ffa50ad6 100644 --- a/meson.build +++ b/meson.build @@ -4161,6 +4161,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 @@ -4284,6 +4285,7 @@ foreach target : target_dirs arch_deps = [] c_args = ['-DCOMPILING_PER_TARGET', '-DCONFIG_TARGET="@[email protected]"'.format(target), + '-DTARGET_ARCH_PREFIX=target_' + target_base_arch.to_lower(), ] link_args = emulator_link_args -- 2.43.0
