Skip to contentSkip to conversation

treewide: uniquify colliding helper symbols

PATCH In review Yonggang Luo 3 participants 13 messages Sep 30 – Oct 10

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover treewide: uniquify colliding helper symbols

A combined qemu-system binary cannot export the same C symbol from two targets. This revision addresses the review of the original series.

Generated TCG helper symbols are namespaced centrally in the DEF_HELPER expansions. C helper names remain generic, while target linker symbols and metadata get a prefix; core helpers keep their existing linker names.

- Set TCG_HELPER_PREFIX per target and use it to namespace generated helper linker symbols and metadata
- Retain explicit i386 and ARM raise_exception implementation prefixes, with static inline wrappers preserving the short names
- Prefix virt_acpi_setup and virt_is_acpi_enabled on ARM, RISC-V, and LoongArch virt. Leave the ARM trace event virt_acpi_setup unchanged

v1: https://patchew.org/QEMU/[email protected]/
branch: https://gitlab.com/lygstate-qemu/qemu/-/tree/global_symbol_conflict_resolve?ref_type=heads

Changes v1 -> v2:

- Drop individual helper_wait renames on RX, Hexagon, and MIPS and RISC-V crc32, crc32c, and wfi renames; generated helpers are namespaced centrally
- Add target-prefixed linker symbols and metadata in DEF_HELPER expansions, with TCG_HELPER_PREFIX; common helpers keep their existing linker names

Yonggang Luo (6):
hw/arm/virt: prefix ACPI helpers with arm_virt_ hw/riscv/virt: prefix ACPI helpers with riscv_virt_ hw/loongarch/virt: prefix ACPI helper with loongarch_virt_
tcg: namespace target helper symbols for combined builds target/i386: prefix exception helper implementations target/arm: rename raise_exception to arm_raise_exception

 hw/arm/virt-acpi-build.c           |  4 +--
 hw/arm/virt.c                      | 12 ++++----
 hw/loongarch/virt-acpi-build.c     |  6 ++--
 hw/loongarch/virt.c                |  2 +-
 hw/riscv/virt-acpi-build.c         |  2 +-
 hw/riscv/virt.c                    |  6 ++--
 include/exec/helper-gen-common.h   | 26 ++++++++++++++++
 include/exec/helper-gen.h.inc      | 48 +++++++++++++++---------------
 include/exec/helper-head.h.inc     | 25 ++++++++++++++++
 include/exec/helper-info.c.inc     | 24 ++++++++++-----
 include/exec/helper-proto-common.h | 26 ++++++++++++++++
 include/exec/helper-proto.h.inc    | 18 ++++++-----
 include/hw/arm/virt.h              |  4 +--
 include/hw/loongarch/virt.h        |  2 +-
 include/hw/riscv/virt.h            |  4 +--
 meson.build                        |  6 +++-
 target/arm/internals.h             | 27 ++++++++++++-----
 target/arm/tcg-stubs.c             |  4 +--
 target/arm/tcg/op_helper.c         | 10 +++----
 target/i386/tcg/excp_helper.c      | 17 ++++++-----
 target/i386/tcg/helper-tcg.h       | 42 +++++++++++++++++++++-----
 21 files changed, 224 insertions(+), 91 deletions(-)
Signature · 1 line
2.55.0.windows.3
#1 lore raw

PATCH v2 1/6 hw/arm/virt: prefix ACPI helpers with arm_virt_

- virt_acpi_setup and virt_is_acpi_enabled are generic names also used by RISC-V and LoongArch virt. A combined binary cannot export two functions with the same C symbol.
- Rename the ARM helpers to arm_virt_acpi_setup and arm_virt_is_acpi_enabled. Leave the trace event virt_acpi_setup unchanged; it is a separate identifier.

---
 hw/arm/virt-acpi-build.c |  4 ++--
 hw/arm/virt.c            | 12 ++++++------
 include/hw/arm/virt.h    |  4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)
hw/arm/virt-acpi-build.c +2 -2
index d368913e76..5737c3a8fa 100644
@@ -1559,7 +1559,7 @@ static const VMStateDescription vmstate_virt_acpi_build = {
     },
 };
 
-void virt_acpi_setup(VirtMachineState *vms)
+void arm_virt_acpi_setup(VirtMachineState *vms)
 {
     AcpiBuildTables tables;
     AcpiBuildState *build_state;
@@ -1570,7 +1570,7 @@ void virt_acpi_setup(VirtMachineState *vms)
         return;
     }
 
-    if (!virt_is_acpi_enabled(vms)) {
+    if (!arm_virt_is_acpi_enabled(vms)) {
         trace_virt_acpi_setup();
         return;
     }
hw/arm/virt.c +6 -6
index bdac33a1de..87d4345411 100644
@@ -763,7 +763,7 @@ static void fdt_add_cpu_nodes(VirtMachineState *vms)
                     &bottom_node,
                     CPU_TOPOLOGY_LEVEL_SOCKET);
             if (cache_at_topo_level) {
-                if (bottom_node == 1 && !virt_is_acpi_enabled(vms))
+                if (bottom_node == 1 && !arm_virt_is_acpi_enabled(vms))
                     error_setg(
                         &error_fatal,
                         "Cannot share L1 at socket_id %d."
@@ -803,7 +803,7 @@ static void fdt_add_cpu_nodes(VirtMachineState *vms)
                                                         top_cluster,
                                                         bottom_cluster, cpu,
                                                         &cluster_offset);
-                if (bottom_cluster == 1 && !virt_is_acpi_enabled(vms)) {
+                if (bottom_cluster == 1 && !arm_virt_is_acpi_enabled(vms)) {
                     error_setg(&error_fatal,
                         "Cannot share L1 at socket_id %d, cluster_id %d. "
                         "DT limitation on sharing at cache level = 1.",
@@ -2030,7 +2030,7 @@ static void create_smmuv3_dev_dtb(VirtMachineState *vms, DeviceState *dev,
     hwaddr base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
     MachineState *ms = MACHINE(vms);
 
-    if (!(vms->bootinfo.firmware_loaded && virt_is_acpi_enabled(vms))) {
+    if (!(vms->bootinfo.firmware_loaded && arm_virt_is_acpi_enabled(vms))) {
         if (object_property_get_bool(OBJECT(dev), "accel", &error_abort)) {
             error_setg(errp, "SMMUv3 with accel=on not supported for DT");
             return;
@@ -2440,7 +2440,7 @@ void virt_machine_done(Notifier *notifier, void *data)
     pci_bus_add_fw_cfg_extra_pci_roots(vms->fw_cfg, vms->bus,
                                        &error_abort);
 
-    virt_acpi_setup(vms);
+    arm_virt_acpi_setup(vms);
     virt_build_smbios(vms);
 }
 
@@ -3204,7 +3204,7 @@ static void machvirt_init(MachineState *machine)
     create_pcie(vms);
     create_cxl_host_reg_region(vms);
 
-    if (aarch64 && firmware_loaded && virt_is_acpi_enabled(vms)) {
+    if (aarch64 && firmware_loaded && arm_virt_is_acpi_enabled(vms)) {
         vms->acpi_dev = create_acpi_ged(vms);
         vms->generic_error_notifier.notify = virt_generic_error_req;
         notifier_list_add(&acpi_generic_error_notifiers,
@@ -3554,7 +3554,7 @@ static void virt_set_oem_table_id(Object *obj, const char *value,
 }
 
 
-bool virt_is_acpi_enabled(const VirtMachineState *vms)
+bool arm_virt_is_acpi_enabled(const VirtMachineState *vms)
 {
     if (vms->acpi == ON_OFF_AUTO_OFF) {
         return false;
include/hw/arm/virt.h +2 -2
index 22e66d1a11..695e5d5728 100644
@@ -218,8 +218,8 @@ struct VirtMachineState {
 #define TYPE_VIRT_MACHINE   MACHINE_TYPE_NAME("virt")
 OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)
 
-void virt_acpi_setup(VirtMachineState *vms);
-bool virt_is_acpi_enabled(const VirtMachineState *vms);
+void arm_virt_acpi_setup(VirtMachineState *vms);
+bool arm_virt_is_acpi_enabled(const VirtMachineState *vms);
 
 #define CLIDR_CTYPE_NO_CACHE 0x00
 #define CLIDR_CTYPE_I_CACHE 0x01
Signature · 1 line
2.55.0.windows.3
#2 lore raw

PATCH v2 2/6 hw/riscv/virt: prefix ACPI helpers with riscv_virt_

In reply to Yonggang Luo

- virt_acpi_setup and virt_is_acpi_enabled collide with ARM virt when both architectures are linked into one qemu-system binary.
- Rename the RISC-V helpers to riscv_virt_acpi_setup and riscv_virt_is_acpi_enabled. Leave file-local virt_acpi_build* names unchanged.

---
 hw/riscv/virt-acpi-build.c | 2 +-
 hw/riscv/virt.c            | 6 +++---
 include/hw/riscv/virt.h    | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
hw/riscv/virt-acpi-build.c +1 -1
index 8e516ec114..de47631852 100644
@@ -1021,7 +1021,7 @@ static const VMStateDescription vmstate_virt_acpi_build = {
     },
 };
 
-void virt_acpi_setup(RISCVVirtState *s)
+void riscv_virt_acpi_setup(RISCVVirtState *s)
 {
     AcpiBuildTables tables;
     AcpiBuildState *build_state;
hw/riscv/virt.c +3 -3
index d4b501802f..9bd1274841 100644
@@ -705,8 +705,8 @@ static void virt_machine_done(Notifier *notifier, void *data)
 
     virt_build_smbios(s);
 
-    if (virt_is_acpi_enabled(s)) {
-        virt_acpi_setup(s);
+    if (riscv_virt_is_acpi_enabled(s)) {
+        riscv_virt_acpi_setup(s);
     }
 }
 
@@ -1066,7 +1066,7 @@ static void virt_set_iommu_sys(Object *obj, Visitor *v, const char *name,
     visit_type_OnOffAuto(v, name, &s->iommu_sys, errp);
 }
 
-bool virt_is_acpi_enabled(RISCVVirtState *s)
+bool riscv_virt_is_acpi_enabled(RISCVVirtState *s)
 {
     return s->acpi != ON_OFF_AUTO_OFF;
 }
include/hw/riscv/virt.h +2 -2
index e516898f9a..d8f1342e13 100644
@@ -121,9 +121,9 @@ enum {
 #define VIRT_PLIC_SIZE(__num_context) \
     (VIRT_PLIC_CONTEXT_BASE + (__num_context) * VIRT_PLIC_CONTEXT_STRIDE)
 
-bool virt_is_acpi_enabled(RISCVVirtState *s);
+bool riscv_virt_is_acpi_enabled(RISCVVirtState *s);
 bool virt_is_iommu_sys_enabled(RISCVVirtState *s);
-void virt_acpi_setup(RISCVVirtState *vms);
+void riscv_virt_acpi_setup(RISCVVirtState *vms);
 
 /*
  * The virt machine physical address space used by some of the devices
Signature · 1 line
2.55.0.windows.3
#3 lore raw

PATCH v2 3/6 hw/loongarch/virt: prefix ACPI helper with loongarch_virt_

In reply to Yonggang Luo

- virt_acpi_setup is the same C symbol used by ARM and RISC-V virt. Rename it now so a later combined binary does not need meson -D prefixes for LoongArch.
- Rename the file-local virt_is_acpi_enabled to loongarch_virt_is_acpi_enabled to match.

---
 hw/loongarch/virt-acpi-build.c | 6 +++---
 hw/loongarch/virt.c            | 2 +-
 include/hw/loongarch/virt.h    | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
hw/loongarch/virt-acpi-build.c +3 -3
index 600ef60fc5..b9df9b3a12 100644
@@ -674,7 +674,7 @@ static const VMStateDescription vmstate_acpi_build = {
     },
 };
 
-static bool virt_is_acpi_enabled(LoongArchVirtMachineState *lvms)
+static bool loongarch_virt_is_acpi_enabled(LoongArchVirtMachineState *lvms)
 {
     if (lvms->acpi == ON_OFF_AUTO_OFF) {
         return false;
@@ -682,7 +682,7 @@ static bool virt_is_acpi_enabled(LoongArchVirtMachineState *lvms)
     return true;
 }
 
-void virt_acpi_setup(LoongArchVirtMachineState *lvms)
+void loongarch_virt_acpi_setup(LoongArchVirtMachineState *lvms)
 {
     AcpiBuildTables tables;
     AcpiBuildState *build_state;
@@ -692,7 +692,7 @@ void virt_acpi_setup(LoongArchVirtMachineState *lvms)
         return;
     }
 
-    if (!virt_is_acpi_enabled(lvms)) {
+    if (!loongarch_virt_is_acpi_enabled(lvms)) {
         ACPI_BUILD_DPRINTF("ACPI disabled. Bailing out.\n");
         return;
     }
hw/loongarch/virt.c +1 -1
index 9c5371af9d..19fbf6db0d 100644
@@ -242,7 +242,7 @@ static void virt_done(Notifier *notifier, void *data)
     LoongArchVirtMachineState *lvms = container_of(notifier,
                                       LoongArchVirtMachineState, machine_done);
     virt_build_smbios(lvms);
-    virt_acpi_setup(lvms);
+    loongarch_virt_acpi_setup(lvms);
     virt_fdt_setup(lvms);
 }
 
include/hw/loongarch/virt.h +1 -1
index d39a9bbf5d..72268466de 100644
@@ -132,7 +132,7 @@ struct LoongArchVirtMachineState {
 
 #define TYPE_LOONGARCH_VIRT_MACHINE  MACHINE_TYPE_NAME("virt")
 OBJECT_DECLARE_SIMPLE_TYPE(LoongArchVirtMachineState, LOONGARCH_VIRT_MACHINE)
-void virt_acpi_setup(LoongArchVirtMachineState *lvms);
+void loongarch_virt_acpi_setup(LoongArchVirtMachineState *lvms);
 void virt_fdt_setup(LoongArchVirtMachineState *lvms);
 
 static inline bool virt_has_dmsi(LoongArchVirtMachineState *lvms)
Signature · 1 line
2.55.0.windows.3
#4 lore raw

PATCH v2 4/6 tcg: namespace target helper symbols for combined builds

In reply to Yonggang Luo

Use target-specific assembler names and helper metadata for TCG helpers when multiple targets share a binary. The generated prototype maps the generic C helper name to a target-specific linker symbol, for example:

    helper_raise_exception
        __asm__("helper_i386_raise_exception")

This lets target helper definitions keep generic C names while avoiding linker symbol collisions between targets.

---
 include/exec/helper-gen-common.h   | 26 ++++++++++++++++
 include/exec/helper-gen.h.inc      | 48 +++++++++++++++---------------
 include/exec/helper-head.h.inc     | 25 ++++++++++++++++
 include/exec/helper-info.c.inc     | 24 ++++++++++-----
 include/exec/helper-proto-common.h | 26 ++++++++++++++++
 include/exec/helper-proto.h.inc    | 18 ++++++-----
 meson.build                        |  6 +++-
 7 files changed, 132 insertions(+), 41 deletions(-)
include/exec/helper-gen-common.h +26 -0
index 834590dc4e..c05edb5f3e 100644
@@ -7,8 +7,34 @@
 #ifndef HELPER_GEN_COMMON_H
 #define HELPER_GEN_COMMON_H
 
+#undef HELPER_INFO
+#define HELPER_INFO(name) CORE_HELPER_INFO(name)
+
+#define HELPER_H "accel/tcg/cpu-exec-common.h"
+#include "exec/helper-gen.h.inc"
+#undef  HELPER_H
+
+#define HELPER_H "accel/tcg/cpu-exec.h"
+#include "exec/helper-gen.h.inc"
+#undef  HELPER_H
+
 #define HELPER_H "accel/tcg/tcg-runtime.h"
 #include "exec/helper-gen.h.inc"
 #undef  HELPER_H
 
+#define HELPER_H "accel/tcg/ldst_common.h"
+#include "exec/helper-gen.h.inc"
+#undef  HELPER_H
+
+#define HELPER_H "accel/tcg/atomic_common.h"
+#include "exec/helper-gen.h.inc"
+#undef  HELPER_H
+
+#define HELPER_H "accel/tcg/tcg-runtime-gvec.h"
+#include "exec/helper-gen.h.inc"
+#undef  HELPER_H
+
+#undef HELPER_INFO
+#define HELPER_INFO(name) TARGET_HELPER_INFO(name)
+
 #endif /* HELPER_GEN_COMMON_H */
include/exec/helper-gen.h.inc +24 -24

112 lines not on this page · raw message

include/exec/helper-head.h.inc +25 -0
index 7dec5f5b06..61e106cd56 100644
@@ -8,7 +8,32 @@
 
 #include "fpu/softfloat-types.h"
 
+#define TCG_TARGET_HELPER_INFO_I(prefix, name) helper_info_##prefix##_##name
+#define TCG_TARGET_HELPER_INFO(prefix, name) \
+    TCG_TARGET_HELPER_INFO_I(prefix, name)
+#define TCG_HELPER_STRINGIFY_I(value) #value
+#define TCG_HELPER_STRINGIFY(value) TCG_HELPER_STRINGIFY_I(value)
+
+#ifdef TCG_HELPER_PREFIX
+#define TARGET_HELPER_INFO(name) \
+    TCG_TARGET_HELPER_INFO(TCG_HELPER_PREFIX, name)
+#define TARGET_HELPER_ASM(name) \
+    __asm__("helper_" TCG_HELPER_STRINGIFY(TCG_HELPER_PREFIX) "_" #name)
+#else
+#define TARGET_HELPER_INFO(name) glue(helper_info_, name)
+#define TARGET_HELPER_ASM(name)
+#endif
+
+#define CORE_HELPER_INFO(name) glue(helper_info_, name)
+#define CORE_HELPER_ASM(name)
+
 #define HELPER(name) glue(helper_, name)
+#ifndef HELPER_INFO
+#define HELPER_INFO(name) TARGET_HELPER_INFO(name)
+#endif
+#ifndef HELPER_ASM
+#define HELPER_ASM(name) TARGET_HELPER_ASM(name)
+#endif
 
 /* Some types that make sense in C, but not for TCG.  */
 #define dh_alias_i32 i32
include/exec/helper-info.c.inc +16 -8
index c551736d49..815546c818 100644
@@ -16,21 +16,24 @@
 #define str(s) #s
 
 #define DEF_HELPER_FLAGS_0(NAME, FLAGS, RET)                            \
-    TCGHelperInfo glue(helper_info_, NAME) = {                          \
+    TCGHelperInfo HELPER_INFO(NAME) =                                   \
+    {                                                                   \
         .func = HELPER(NAME), .name = str(NAME),                        \
         .flags = FLAGS | dh_callflag(RET),                              \
         .typemask = dh_typemask(RET, 0)                                 \
     };
 
 #define DEF_HELPER_FLAGS_1(NAME, FLAGS, RET, T1)                        \
-    TCGHelperInfo glue(helper_info_, NAME) = {                          \
+    TCGHelperInfo HELPER_INFO(NAME) =                                   \
+    {                                                                   \
         .func = HELPER(NAME), .name = str(NAME),                        \
         .flags = FLAGS | dh_callflag(RET),                              \
         .typemask = dh_typemask(RET, 0) | dh_typemask(T1, 1)            \
     };
 
 #define DEF_HELPER_FLAGS_2(NAME, FLAGS, RET, T1, T2)                    \
-    TCGHelperInfo glue(helper_info_, NAME) = {                          \
+    TCGHelperInfo HELPER_INFO(NAME) =                                   \
+    {                                                                   \
         .func = HELPER(NAME), .name = str(NAME),                        \
         .flags = FLAGS | dh_callflag(RET),                              \
         .typemask = dh_typemask(RET, 0) | dh_typemask(T1, 1)            \
@@ -38,7 +41,8 @@
     };
 
 #define DEF_HELPER_FLAGS_3(NAME, FLAGS, RET, T1, T2, T3)                \
-    TCGHelperInfo glue(helper_info_, NAME) = {                          \
+    TCGHelperInfo HELPER_INFO(NAME) =                                   \
+    {                                                                   \
         .func = HELPER(NAME), .name = str(NAME),                        \
         .flags = FLAGS | dh_callflag(RET),                              \
         .typemask = dh_typemask(RET, 0) | dh_typemask(T1, 1)            \
@@ -46,7 +50,8 @@
     };
 
 #define DEF_HELPER_FLAGS_4(NAME, FLAGS, RET, T1, T2, T3, T4)            \
-    TCGHelperInfo glue(helper_info_, NAME) = {                          \
+    TCGHelperInfo HELPER_INFO(NAME) =                                   \
+    {                                                                   \
         .func = HELPER(NAME), .name = str(NAME),                        \
         .flags = FLAGS | dh_callflag(RET),                              \
         .typemask = dh_typemask(RET, 0) | dh_typemask(T1, 1)            \
@@ -55,7 +60,8 @@
     };
 
 #define DEF_HELPER_FLAGS_5(NAME, FLAGS, RET, T1, T2, T3, T4, T5)        \
-    TCGHelperInfo glue(helper_info_, NAME) = {                          \
+    TCGHelperInfo HELPER_INFO(NAME) =                                   \
+    {                                                                   \
         .func = HELPER(NAME), .name = str(NAME),                        \
         .flags = FLAGS | dh_callflag(RET),                              \
         .typemask = dh_typemask(RET, 0) | dh_typemask(T1, 1)            \
@@ -64,7 +70,8 @@
     };
 
 #define DEF_HELPER_FLAGS_6(NAME, FLAGS, RET, T1, T2, T3, T4, T5, T6)    \
-    TCGHelperInfo glue(helper_info_, NAME) = {                          \
+    TCGHelperInfo HELPER_INFO(NAME) =                                   \
+    {                                                                   \
         .func = HELPER(NAME), .name = str(NAME),                        \
         .flags = FLAGS | dh_callflag(RET),                              \
         .typemask = dh_typemask(RET, 0) | dh_typemask(T1, 1)            \
@@ -74,7 +81,8 @@
     };
 
 #define DEF_HELPER_FLAGS_7(NAME, FLAGS, RET, T1, T2, T3, T4, T5, T6, T7) \
-    TCGHelperInfo glue(helper_info_, NAME) = {                          \
+    TCGHelperInfo HELPER_INFO(NAME) =                                   \
+    {                                                                   \
         .func = HELPER(NAME), .name = str(NAME),                        \
         .flags = FLAGS | dh_callflag(RET),                              \
         .typemask = dh_typemask(RET, 0) | dh_typemask(T1, 1)            \
include/exec/helper-proto-common.h +26 -0
index 76e6c25bec..01a0be10c6 100644
@@ -9,10 +9,36 @@
 
 #include "qemu/atomic128.h"  /* for HAVE_CMPXCHG128 */
 
+#undef HELPER_ASM
+#define HELPER_ASM(name) CORE_HELPER_ASM(name)
+
+#define HELPER_H "accel/tcg/cpu-exec-common.h"
+#include "exec/helper-proto.h.inc"
+#undef  HELPER_H
+
+#define HELPER_H "accel/tcg/cpu-exec.h"
+#include "exec/helper-proto.h.inc"
+#undef  HELPER_H
+
 #define HELPER_H "accel/tcg/tcg-runtime.h"
 #include "exec/helper-proto.h.inc"
 #undef  HELPER_H
 
+#define HELPER_H "accel/tcg/ldst_common.h"
+#include "exec/helper-proto.h.inc"
+#undef  HELPER_H
+
+#define HELPER_H "accel/tcg/atomic_common.h"
+#include "exec/helper-proto.h.inc"
+#undef  HELPER_H
+
+#define HELPER_H "accel/tcg/tcg-runtime-gvec.h"
+#include "exec/helper-proto.h.inc"
+#undef  HELPER_H
+
+#undef HELPER_ASM
+#define HELPER_ASM(name) TARGET_HELPER_ASM(name)
+
 #include "accel/tcg/getpc.h"
 
 #endif /* HELPER_PROTO_COMMON_H */
include/exec/helper-proto.h.inc +10 -8
index f8e57e43ce..b7e3b10ed7 100644
@@ -21,35 +21,37 @@
 #define DEF_HELPER_ATTR  __attribute__((noinline))
 
 #define DEF_HELPER_FLAGS_0(name, flags, ret) \
-dh_ctype(ret) HELPER(name) (void) DEF_HELPER_ATTR;
+dh_ctype(ret) HELPER(name) (void) HELPER_ASM(name) DEF_HELPER_ATTR;
 
 #define DEF_HELPER_FLAGS_1(name, flags, ret, t1) \
-dh_ctype(ret) HELPER(name) (dh_ctype(t1)) DEF_HELPER_ATTR;
+dh_ctype(ret) HELPER(name) (dh_ctype(t1)) HELPER_ASM(name) DEF_HELPER_ATTR;
 
 #define DEF_HELPER_FLAGS_2(name, flags, ret, t1, t2) \
-dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2)) DEF_HELPER_ATTR;
+dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2)) \
+    HELPER_ASM(name) DEF_HELPER_ATTR;
 
 #define DEF_HELPER_FLAGS_3(name, flags, ret, t1, t2, t3) \
 dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), \
-                            dh_ctype(t3)) DEF_HELPER_ATTR;
+                            dh_ctype(t3)) HELPER_ASM(name) DEF_HELPER_ATTR;
 
 #define DEF_HELPER_FLAGS_4(name, flags, ret, t1, t2, t3, t4) \
 dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \
-                            dh_ctype(t4)) DEF_HELPER_ATTR;
+                            dh_ctype(t4)) HELPER_ASM(name) DEF_HELPER_ATTR;
 
 #define DEF_HELPER_FLAGS_5(name, flags, ret, t1, t2, t3, t4, t5) \
 dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \
-                            dh_ctype(t4), dh_ctype(t5)) DEF_HELPER_ATTR;
+                            dh_ctype(t4), dh_ctype(t5)) \
+    HELPER_ASM(name) DEF_HELPER_ATTR;
 
 #define DEF_HELPER_FLAGS_6(name, flags, ret, t1, t2, t3, t4, t5, t6) \
 dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \
                             dh_ctype(t4), dh_ctype(t5), \
-                            dh_ctype(t6)) DEF_HELPER_ATTR;
+                            dh_ctype(t6)) HELPER_ASM(name) DEF_HELPER_ATTR;
 
 #define DEF_HELPER_FLAGS_7(name, flags, ret, t1, t2, t3, t4, t5, t6, t7) \
 dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \
                             dh_ctype(t4), dh_ctype(t5), dh_ctype(t6), \
-                            dh_ctype(t7)) DEF_HELPER_ATTR;
+                            dh_ctype(t7)) HELPER_ASM(name) DEF_HELPER_ATTR;
 
 #define IN_HELPER_PROTO
 
meson.build +5 -1
index cae1591cd2..3cadf5b215 100644
@@ -4161,7 +4161,10 @@ 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 = [
+    '-DCPU_DEFS_H',
+    '-DTCG_HELPER_PREFIX=' + 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
@@ -4277,6 +4280,7 @@ foreach target : target_dirs
   arch_deps = []
   c_args = ['-DCOMPILING_PER_TARGET',
             '-DCONFIG_TARGET="@[email protected]"'.format(target),
+            '-DTCG_HELPER_PREFIX=' + target_base_arch.to_lower()
   ]
   link_args = emulator_link_args
 
Signature · 1 line
2.55.0.windows.3
#5 lore raw

Re: [PATCH v2 4/6] tcg: namespace target helper symbols for combined builds

Quoted 10 lines · Yonggang Luo

Use target-specific assembler names and helper metadata for TCG helpers when multiple targets share a binary. The generated prototype maps the generic C helper name to a target-specific linker symbol, for example:

    helper_raise_exception
        __asm__("helper_i386_raise_exception")

This lets target helper definitions keep generic C names while avoiding linker symbol collisions between targets.

Hi Richard, do you have an opinion on this patch?

We are trying to see if we do renaming per helper, or if we introduce a "generic" way to deal with it. I don't have a strong opinion, renaming things or adding more macros and build system soup are both ok on my side, so direction would depend on your culinary taste.

Regards,
Pierrick

#6 lore raw

Re: [PATCH v2 4/6] tcg: namespace target helper symbols for combined builds

Quoted 11 lines · Pierrick Bouvier
Quoted 10 lines · Yonggang Luo

Use target-specific assembler names and helper metadata for TCG helpers when multiple targets share a binary. The generated prototype maps the generic C helper name to a target-specific linker symbol, for example:

     helper_raise_exception
         __asm__("helper_i386_raise_exception")

This lets target helper definitions keep generic C names while avoiding linker symbol collisions between targets.

Quoted 6 lines

Hi Richard, do you have an opinion on this patch?

We are trying to see if we do renaming per helper, or if we introduce a "generic" way to deal with it. I don't have a strong opinion, renaming things or adding more macros and build system soup are both ok on my side, so direction would depend on your culinary taste.

I think the general direction is good. Perhaps the specifics need adjustment. In particular, using __asm__ to rename symbols is suspect and likely non-portable to non-ELF hosts like Darwin and Windows.

r~

#7 lore raw

Re: [PATCH v2 4/6] tcg: namespace target helper symbols for combined builds

Quoted 15 lines · Richard Henderson
Quoted 13 lines · Pierrick Bouvier
Quoted 10 lines · Yonggang Luo

Use target-specific assembler names and helper metadata for TCG helpers when multiple targets share a binary. The generated prototype maps the generic C helper name to a target-specific linker symbol, for example:

     helper_raise_exception
         __asm__("helper_i386_raise_exception")

This lets target helper definitions keep generic C names while avoiding linker symbol collisions between targets.

Hi Richard, do you have an opinion on this patch?

Quoted 7 lines
Quoted 4 lines

We are trying to see if we do renaming per helper, or if we introduce a "generic" way to deal with it. I don't have a strong opinion, renaming things or adding more macros and build system soup are both ok on my side, so direction would depend on your culinary taste.

I think the general direction is good. Perhaps the specifics need adjustment. In particular, using __asm__ to rename symbols is suspect and likely non-portable to non-ELF hosts like Darwin and Windows.

I have already tested on windows, only not sure about Darwin, let's me create a test on Darwin,
because I do not have a CI for Darwin to test it.

Quoted 3 lines

r~

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#8 lore raw

Re: [PATCH v2 4/6] tcg: namespace target helper symbols for combined builds

Quoted 21 lines · Yonggang Luo
Quoted 19 lines · Richard Henderson
Quoted 17 lines · Pierrick Bouvier
Quoted 10 lines · Yonggang Luo

Use target-specific assembler names and helper metadata for TCG helpers when multiple targets share a binary. The generated prototype maps the generic C helper name to a target-specific linker symbol, for example:

      helper_raise_exception
          __asm__("helper_i386_raise_exception")

This lets target helper definitions keep generic C names while avoiding linker symbol collisions between targets.

Hi Richard, do you have an opinion on this patch?

We are trying to see if we do renaming per helper, or if we introduce a "generic" way to deal with it. I don't have a strong opinion, renaming things or adding more macros and build system soup are both ok on my side, so direction would depend on your culinary taste.

Quoted 7 lines
Quoted 3 lines

I think the general direction is good. Perhaps the specifics need adjustment. In particular, using __asm__ to rename symbols is suspect and likely non-portable to non-ELF hosts like Darwin and Windows.

I have already tested on windows, only not sure about Darwin, let's me create a test on Darwin,
because I do not have a CI for Darwin to test it.

In particular, I saw no use of __USER_LABEL_PREFIX__, which is required for portability.

r~

#9 lore raw

Re: [PATCH v2 4/6] tcg: namespace target helper symbols for combined builds

Quoted 27 lines · Richard Henderson
Quoted 25 lines · Yonggang Luo
Quoted 22 lines · Richard Henderson
Quoted 11 lines · Pierrick Bouvier
Quoted 10 lines · Yonggang Luo

Use target-specific assembler names and helper metadata for TCG helpers when multiple targets share a binary. The generated prototype maps the generic C helper name to a target-specific linker symbol, for example:

      helper_raise_exception
          __asm__("helper_i386_raise_exception")

This lets target helper definitions keep generic C names while avoiding linker symbol collisions between targets.

Quoted 6 lines

Hi Richard, do you have an opinion on this patch?

We are trying to see if we do renaming per helper, or if we introduce a "generic" way to deal with it. I don't have a strong opinion, renaming things or adding more macros and build system soup are both ok on my side, so direction would depend on your culinary taste.

I think the general direction is good. Perhaps the specifics need adjustment. In particular, using __asm__ to rename symbols is suspect and likely non-portable to non-ELF hosts like Darwin and Windows.

Quoted 5 lines
Quoted 3 lines

I have already tested on windows, only not sure about Darwin, let's me create a test on Darwin,
because I do not have a CI for Darwin to test it.

In particular, I saw no use of __USER_LABEL_PREFIX__, which is required for portability.

What does this mean?
I am using TCG_HELPER_PREFIX to identify different base_arch
+ '-DTCG_HELPER_PREFIX=' + target_base_arch.to_lower()

Quoted 3 lines

r~

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#10 lore raw

Re: [PATCH v2 4/6] tcg: namespace target helper symbols for combined builds

In reply to Yonggang Luo
Quoted 21 lines · Yonggang Luo
Quoted 19 lines · Richard Henderson
Quoted 17 lines · Pierrick Bouvier
Quoted 10 lines · Yonggang Luo

Use target-specific assembler names and helper metadata for TCG helpers when multiple targets share a binary. The generated prototype maps the generic C helper name to a target-specific linker symbol, for example:

      helper_raise_exception
          __asm__("helper_i386_raise_exception")

This lets target helper definitions keep generic C names while avoiding linker symbol collisions between targets.

Hi Richard, do you have an opinion on this patch?

We are trying to see if we do renaming per helper, or if we introduce a "generic" way to deal with it. I don't have a strong opinion, renaming things or adding more macros and build system soup are both ok on my side, so direction would depend on your culinary taste.

Quoted 8 lines
Quoted 3 lines

I think the general direction is good. Perhaps the specifics need adjustment. In particular, using __asm__ to rename symbols is suspect and likely non-portable to non-ELF hosts like Darwin and Windows.

I have already tested on windows, only not sure about Darwin, let's me create a test on Darwin,
because I do not have a CI for Darwin to test it.

You can take a look at (see README):
https://github.com/p-b-o/qemu-ci#qemu-ci

It will automatically add a full GitHub CI on top of your repo, including bsd, macos, windows, linux, so it makes easy to ensure things compile correctly on all platforms.

Quoted 6 lines
Quoted 3 lines

r~

#11 lore raw

PATCH v2 5/6 target/i386: prefix exception helper implementations

In reply to Yonggang Luo

Rename the i386 exception helper implementations to i386_raise_exception* to avoid collisions with common helpers.

---
 target/i386/tcg/excp_helper.c | 17 +++++++-------
 target/i386/tcg/helper-tcg.h  | 42 +++++++++++++++++++++++++++++------
 2 files changed, 44 insertions(+), 15 deletions(-)
target/i386/tcg/excp_helper.c +9 -8
index 1eaa602c91..0576d64390 100644
@@ -34,7 +34,7 @@ G_NORETURN void helper_raise_interrupt(CPUX86State *env, int intno,
 
 G_NORETURN void helper_raise_exception(CPUX86State *env, int exception_index)
 {
-    raise_exception(env, exception_index);
+    i386_raise_exception(env, exception_index);
 }
 
 /*
@@ -120,25 +120,26 @@ G_NORETURN void raise_interrupt(CPUX86State *env, int intno, int next_eip_addend
     raise_interrupt2(env, intno, 1, 0, next_eip_addend, 0);
 }
 
-G_NORETURN void raise_exception_err(CPUX86State *env, int exception_index,
-                                    int error_code)
+G_NORETURN void i386_raise_exception_err(CPUX86State *env, int exception_index,
+                                         int error_code)
 {
     raise_interrupt2(env, exception_index, 0, error_code, 0, 0);
 }
 
-G_NORETURN void raise_exception_err_ra(CPUX86State *env, int exception_index,
-                                       int error_code, uintptr_t retaddr)
+G_NORETURN void i386_raise_exception_err_ra(CPUX86State *env,
+                                            int exception_index,
+                                            int error_code, uintptr_t retaddr)
 {
     raise_interrupt2(env, exception_index, 0, error_code, 0, retaddr);
 }
 
-G_NORETURN void raise_exception(CPUX86State *env, int exception_index)
+G_NORETURN void i386_raise_exception(CPUX86State *env, int exception_index)
 {
     raise_interrupt2(env, exception_index, 0, 0, 0, 0);
 }
 
-G_NORETURN void raise_exception_ra(CPUX86State *env, int exception_index,
-                                   uintptr_t retaddr)
+G_NORETURN void i386_raise_exception_ra(CPUX86State *env, int exception_index,
+                                        uintptr_t retaddr)
 {
     raise_interrupt2(env, exception_index, 0, 0, 0, retaddr);
 }
target/i386/tcg/helper-tcg.h +35 -7

48 lines not on this page · raw message

Signature · 1 line
2.55.0.windows.3
#12 lore raw

PATCH v2 6/6 target/arm: rename raise_exception to arm_raise_exception

In reply to Yonggang Luo

raise_exception is a global C symbol. Prefix it so one binary can keep that short name free for another target, and keep the short name as a static inline wrapper.

---
 target/arm/internals.h     | 27 ++++++++++++++++++++-------
 target/arm/tcg-stubs.c     |  4 ++--
 target/arm/tcg/op_helper.c | 10 +++++-----
 3 files changed, 27 insertions(+), 14 deletions(-)
target/arm/internals.h +20 -7
index c41fa5225c..c4d6f2d9ed 100644
@@ -333,20 +333,33 @@ FIELD(FPMR, LSCALE2, 32, 6)
 #define M_FAKE_FSR_SFAULT 0xe /* SecureFault INVTRAN, INVEP or AUVIOL */
 
 /**
- * raise_exception: Raise the specified exception.
+ * arm_raise_exception: Raise the specified exception.
  * Raise a guest exception with the specified value, syndrome register
  * and target exception level. This should be called from helper functions,
  * and never returns because we will longjump back up to the CPU main loop.
  */
-G_NORETURN void raise_exception(CPUARMState *env, uint32_t excp,
-                                uint64_t syndrome, uint32_t target_el);
-
+G_NORETURN void arm_raise_exception(CPUARMState *env, uint32_t excp,
+                                    uint64_t syndrome, uint32_t target_el);
 /*
  * Similarly, but also use unwinding to restore cpu state.
  */
-G_NORETURN void raise_exception_ra(CPUARMState *env, uint32_t excp,
-                                   uint64_t syndrome, uint32_t target_el,
-                                   uintptr_t ra);
+G_NORETURN void arm_raise_exception_ra(CPUARMState *env, uint32_t excp,
+                                       uint64_t syndrome, uint32_t target_el,
+                                       uintptr_t ra);
+
+static inline G_NORETURN
+void raise_exception(CPUARMState *env, uint32_t excp,
+                     uint64_t syndrome, uint32_t target_el)
+{
+    arm_raise_exception(env, excp, syndrome, target_el);
+}
+
+static inline G_NORETURN
+void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome,
+                        uint32_t target_el, uintptr_t ra)
+{
+    arm_raise_exception_ra(env, excp, syndrome, target_el, ra);
+}
 
 /*
  * For AArch64, map a given EL to an index in the banked_spsr array.
target/arm/tcg-stubs.c +2 -2
index aeeede8066..7f9f684ed7 100644
@@ -16,8 +16,8 @@ void write_v7m_exception(CPUARMState *env, uint32_t new_exc)
     g_assert_not_reached();
 }
 
-void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome,
-                        uint32_t target_el, uintptr_t ra)
+void arm_raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome,
+                            uint32_t target_el, uintptr_t ra)
 {
     g_assert_not_reached();
 }
target/arm/tcg/op_helper.c +5 -5
index af56eff9f1..ae48f9ab98 100644
@@ -45,8 +45,8 @@ int exception_target_el(CPUARMState *env)
     return target_el;
 }
 
-void raise_exception(CPUARMState *env, uint32_t excp,
-                     uint64_t syndrome, uint32_t target_el)
+void arm_raise_exception(CPUARMState *env, uint32_t excp,
+                         uint64_t syndrome, uint32_t target_el)
 {
     CPUState *cs = env_cpu(env);
 
@@ -70,8 +70,8 @@ void raise_exception(CPUARMState *env, uint32_t excp,
     cpu_loop_exit(cs);
 }
 
-void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome,
-                        uint32_t target_el, uintptr_t ra)
+void arm_raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome,
+                            uint32_t target_el, uintptr_t ra)
 {
     CPUState *cs = env_cpu(env);
 
@@ -81,7 +81,7 @@ void raise_exception_ra(CPUARMState *env, uint32_t excp, uint64_t syndrome,
      * the caller passed us, and cannot use cpu_loop_exit_restore().
      */
     cpu_restore_state(cs, ra);
-    raise_exception(env, excp, syndrome, target_el);
+    arm_raise_exception(env, excp, syndrome, target_el);
 }
 
 uint64_t HELPER(neon_tbl)(CPUARMState *env, uint32_t desc,
Signature · 1 line
2.55.0.windows.3