Skip to contentSkip to conversation

system: Convert qemu_arch_available() to TargetInfo API

PATCH In review Philippe Mathieu-Daudé 4 participants 10 messages Jan 8 – Jan 9 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 system: Convert qemu_arch_available() to TargetInfo API

Get the base arch_mask from the current SysEmuTarget, making qemu_arch_available() target-agnostic.

We don't need the per-target QEMU_ARCH definition anymore, remove it.

---
v3: Return directly within switch
v2: Prefer switch over array (pbo)

---
 meson.build        |  2 --
 system/arch_init.c | 30 -----------------------
 target-info.c      | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 system/meson.build |  1 -
 4 files changed, 60 insertions(+), 33 deletions(-)
 delete mode 100644 system/arch_init.c
meson.build +0 -2
index 734c801cc77..435dc6e3c8e 100644
@@ -3419,8 +3419,6 @@ foreach target : target_dirs
       config_target_data.set(k, v)
     endif
   endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
   config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                configuration: config_target_data)}
 
system/arch_init.c deleted +0 -30
deleted file mode 100644
index e85736884c9..00000000000
@@ -1,30 +0,0 @@
-/*
- * QEMU System Emulator
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-#include "qemu/osdep.h"
-#include "system/arch_init.h"
-
-bool qemu_arch_available(unsigned qemu_arch_mask)
-{
-    return qemu_arch_mask & QEMU_ARCH;
-}
target-info.c +60 -0

72 lines not on this page · raw message

system/meson.build +0 -1
index 4b69ef0f5fb..66e16db55ce 100644
@@ -1,5 +1,4 @@
 specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'arch_init.c',
   'globals-target.c',
 )])
 
Signature · 1 line
2.52.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 80 lines · Philippe Mathieu-Daudé

Get the base arch_mask from the current SysEmuTarget, making qemu_arch_available() target-agnostic.

We don't need the per-target QEMU_ARCH definition anymore, remove it.

---
v3: Return directly within switch
v2: Prefer switch over array (pbo)

---
 meson.build        |  2 --
 system/arch_init.c | 30 -----------------------
 target-info.c      | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 system/meson.build |  1 -
 4 files changed, 60 insertions(+), 33 deletions(-)
 delete mode 100644 system/arch_init.c
meson.build +0 -2
index 734c801cc77..435dc6e3c8e 100644
@@ -3419,8 +3419,6 @@ foreach target : target_dirs
       config_target_data.set(k, v)
     endif
   endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
   config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                configuration: config_target_data)}
 
system/arch_init.c deleted +0 -30
deleted file mode 100644
index e85736884c9..00000000000
@@ -1,30 +0,0 @@
-/*
- * QEMU System Emulator
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-#include "qemu/osdep.h"
-#include "system/arch_init.h"
-
-bool qemu_arch_available(unsigned qemu_arch_mask)
-{
-    return qemu_arch_mask & QEMU_ARCH;
-}
target-info.c +1 -0
index 24696ff4111..774fdcd2c46 100644
@@ -11,6 +11,7 @@
 #include "qemu/target-info-qapi.h"
 #include "qemu/target-info-impl.h"
 #include "qapi/error.h"
+#include "system/arch_init.h"
 
 const char *target_name(void)
 {

target-info.c SysEmuTarget target_arch(void) · line 36

Quoted 3 lines
target-info.c +0 -0
@@ -33,6 +34,65 @@ SysEmuTarget target_arch(void)
     return arch;
 }
 

This looks fine to me but I note the API takes a mask which implies you could potentially pass multiple arches in the mask. Not an issue now but we should probably add a kdoc to the declaration to make it clear you can only test one arch at a time for now.

Quoted 67 lines
target-info.c +59 -0
+bool qemu_arch_available(unsigned qemu_arch_mask)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_ALPHA:
+        return qemu_arch_mask & QEMU_ARCH_ALPHA;
+    case SYS_EMU_TARGET_ARM:
+    case SYS_EMU_TARGET_AARCH64:
+        return qemu_arch_mask & QEMU_ARCH_ARM;
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return qemu_arch_mask & QEMU_ARCH_I386;
+    case SYS_EMU_TARGET_M68K:
+        return qemu_arch_mask & QEMU_ARCH_M68K;
+    case SYS_EMU_TARGET_MICROBLAZE:
+    case SYS_EMU_TARGET_MICROBLAZEEL:
+        return qemu_arch_mask & QEMU_ARCH_MICROBLAZE;
+    case SYS_EMU_TARGET_MIPS:
+    case SYS_EMU_TARGET_MIPSEL:
+    case SYS_EMU_TARGET_MIPS64:
+    case SYS_EMU_TARGET_MIPS64EL:
+        return qemu_arch_mask & QEMU_ARCH_MIPS;
+    case SYS_EMU_TARGET_PPC:
+    case SYS_EMU_TARGET_PPC64:
+        return qemu_arch_mask & QEMU_ARCH_PPC;
+    case SYS_EMU_TARGET_S390X:
+        return qemu_arch_mask & QEMU_ARCH_S390X;
+    case SYS_EMU_TARGET_SH4:
+    case SYS_EMU_TARGET_SH4EB:
+        return qemu_arch_mask & QEMU_ARCH_SH4;
+    case SYS_EMU_TARGET_SPARC:
+    case SYS_EMU_TARGET_SPARC64:
+        return qemu_arch_mask & QEMU_ARCH_SPARC;
+    case SYS_EMU_TARGET_XTENSA:
+    case SYS_EMU_TARGET_XTENSAEB:
+        return qemu_arch_mask & QEMU_ARCH_XTENSA;
+    case SYS_EMU_TARGET_OR1K:
+        return qemu_arch_mask & QEMU_ARCH_OPENRISC;
+    case SYS_EMU_TARGET_TRICORE:
+        return qemu_arch_mask & QEMU_ARCH_TRICORE;
+    case SYS_EMU_TARGET_HPPA:
+        return qemu_arch_mask & QEMU_ARCH_HPPA;
+    case SYS_EMU_TARGET_RISCV32:
+    case SYS_EMU_TARGET_RISCV64:
+        return qemu_arch_mask & QEMU_ARCH_RISCV;
+    case SYS_EMU_TARGET_RX:
+        return qemu_arch_mask & QEMU_ARCH_RX;
+    case SYS_EMU_TARGET_AVR:
+        return qemu_arch_mask & QEMU_ARCH_AVR;
+    /*
+    case SYS_EMU_TARGET_HEXAGON:
+        return qemu_arch_mask & QEMU_ARCH_HEXAGON;
+    */
+    case SYS_EMU_TARGET_LOONGARCH64:
+        return qemu_arch_mask & QEMU_ARCH_LOONGARCH;
+    default:
+        g_assert_not_reached();
+    };
+}
+
 const char *target_cpu_type(void)
 {
     return target_info()->cpu_type;
system/meson.build +0 -0
index 4b69ef0f5fb..66e16db55ce 100644

system/meson.build line 3

Quoted 4 lines
system/meson.build +0 -1
@@ -1,5 +1,4 @@
 specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'arch_init.c',
   'globals-target.c',
 )])

Otherwise:

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#2 lore raw
Quoted 79 lines · Alex Bennée
Quoted 77 lines · Philippe Mathieu-Daudé

Get the base arch_mask from the current SysEmuTarget, making qemu_arch_available() target-agnostic.

We don't need the per-target QEMU_ARCH definition anymore, remove it.

---
v3: Return directly within switch
v2: Prefer switch over array (pbo)

---
  meson.build        |  2 --
  system/arch_init.c | 30 -----------------------
  target-info.c      | 60 ++++++++++++++++++++++++++++++++++++++++++++++
  system/meson.build |  1 -
  4 files changed, 60 insertions(+), 33 deletions(-)

delete mode 100644 system/arch_init.c

meson.build +0 -2
index 734c801cc77..435dc6e3c8e 100644
@@ -3419,8 +3419,6 @@ foreach target : target_dirs
        config_target_data.set(k, v)
      endif
    endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
    config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                 configuration: config_target_data)}
 
system/arch_init.c deleted +0 -30
deleted file mode 100644
index e85736884c9..00000000000
@@ -1,30 +0,0 @@
-/*
- * QEMU System Emulator
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-#include "qemu/osdep.h"
-#include "system/arch_init.h"
-
-bool qemu_arch_available(unsigned qemu_arch_mask)
-{
-    return qemu_arch_mask & QEMU_ARCH;
-}
target-info.c +1 -0
index 24696ff4111..774fdcd2c46 100644
@@ -11,6 +11,7 @@
  #include "qemu/target-info-qapi.h"
  #include "qemu/target-info-impl.h"
  #include "qapi/error.h"
+#include "system/arch_init.h"
 
Quoted 11 lines

target-info.c SysEmuTarget target_arch(void) · line 36

Quoted 6 lines
target-info.c +0 -0
  const char *target_name(void)
  {
@@ -33,6 +34,65 @@ SysEmuTarget target_arch(void)
      return arch;
  }
 

This looks fine to me but I note the API takes a mask which implies you could potentially pass multiple arches in the mask. Not an issue now but we should probably add a kdoc to the declaration to make it clear you can only test one arch at a time for now.

There is no change in this API, your description is what is intended:
compile qemu-options once and display (-help) the relevant options for the current (read in the future, "selected") target architecture.

If we want to add a @docstring to qemu_arch_available() this can be done in parallel of this patch.

Quoted 75 lines
Quoted 68 lines
target-info.c +59 -0
+bool qemu_arch_available(unsigned qemu_arch_mask)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_ALPHA:
+        return qemu_arch_mask & QEMU_ARCH_ALPHA;
+    case SYS_EMU_TARGET_ARM:
+    case SYS_EMU_TARGET_AARCH64:
+        return qemu_arch_mask & QEMU_ARCH_ARM;
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return qemu_arch_mask & QEMU_ARCH_I386;
+    case SYS_EMU_TARGET_M68K:
+        return qemu_arch_mask & QEMU_ARCH_M68K;
+    case SYS_EMU_TARGET_MICROBLAZE:
+    case SYS_EMU_TARGET_MICROBLAZEEL:
+        return qemu_arch_mask & QEMU_ARCH_MICROBLAZE;
+    case SYS_EMU_TARGET_MIPS:
+    case SYS_EMU_TARGET_MIPSEL:
+    case SYS_EMU_TARGET_MIPS64:
+    case SYS_EMU_TARGET_MIPS64EL:
+        return qemu_arch_mask & QEMU_ARCH_MIPS;
+    case SYS_EMU_TARGET_PPC:
+    case SYS_EMU_TARGET_PPC64:
+        return qemu_arch_mask & QEMU_ARCH_PPC;
+    case SYS_EMU_TARGET_S390X:
+        return qemu_arch_mask & QEMU_ARCH_S390X;
+    case SYS_EMU_TARGET_SH4:
+    case SYS_EMU_TARGET_SH4EB:
+        return qemu_arch_mask & QEMU_ARCH_SH4;
+    case SYS_EMU_TARGET_SPARC:
+    case SYS_EMU_TARGET_SPARC64:
+        return qemu_arch_mask & QEMU_ARCH_SPARC;
+    case SYS_EMU_TARGET_XTENSA:
+    case SYS_EMU_TARGET_XTENSAEB:
+        return qemu_arch_mask & QEMU_ARCH_XTENSA;
+    case SYS_EMU_TARGET_OR1K:
+        return qemu_arch_mask & QEMU_ARCH_OPENRISC;
+    case SYS_EMU_TARGET_TRICORE:
+        return qemu_arch_mask & QEMU_ARCH_TRICORE;
+    case SYS_EMU_TARGET_HPPA:
+        return qemu_arch_mask & QEMU_ARCH_HPPA;
+    case SYS_EMU_TARGET_RISCV32:
+    case SYS_EMU_TARGET_RISCV64:
+        return qemu_arch_mask & QEMU_ARCH_RISCV;
+    case SYS_EMU_TARGET_RX:
+        return qemu_arch_mask & QEMU_ARCH_RX;
+    case SYS_EMU_TARGET_AVR:
+        return qemu_arch_mask & QEMU_ARCH_AVR;
+    /*
+    case SYS_EMU_TARGET_HEXAGON:
+        return qemu_arch_mask & QEMU_ARCH_HEXAGON;
+    */
+    case SYS_EMU_TARGET_LOONGARCH64:
+        return qemu_arch_mask & QEMU_ARCH_LOONGARCH;
+    default:
+        g_assert_not_reached();
+    };
+}
+
  const char *target_cpu_type(void)
  {
      return target_info()->cpu_type;
system/meson.build +0 -0
index 4b69ef0f5fb..66e16db55ce 100644

system/meson.build line 3

Quoted 4 lines
system/meson.build +0 -1
@@ -1,5 +1,4 @@
  specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'arch_init.c',
    'globals-target.c',
  )])

Otherwise:

Quoted 1 line

Thanks!

Reviewed-by on v3 1/1
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 129 lines · Philippe Mathieu-Daudé

Get the base arch_mask from the current SysEmuTarget, making qemu_arch_available() target-agnostic.

We don't need the per-target QEMU_ARCH definition anymore, remove it.

---
v3: Return directly within switch
v2: Prefer switch over array (pbo)

---
  meson.build        |  2 --
  system/arch_init.c | 30 -----------------------
  target-info.c      | 60 ++++++++++++++++++++++++++++++++++++++++++++++
  system/meson.build |  1 -
  4 files changed, 60 insertions(+), 33 deletions(-)

delete mode 100644 system/arch_init.c

meson.build +0 -2
index 734c801cc77..435dc6e3c8e 100644
@@ -3419,8 +3419,6 @@ foreach target : target_dirs
        config_target_data.set(k, v)
      endif
    endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
    config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                 configuration: config_target_data)}
 
system/arch_init.c deleted +0 -30
deleted file mode 100644
index e85736884c9..00000000000
@@ -1,30 +0,0 @@
-/*
- * QEMU System Emulator
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-#include "qemu/osdep.h"
-#include "system/arch_init.h"
-
-bool qemu_arch_available(unsigned qemu_arch_mask)
-{
-    return qemu_arch_mask & QEMU_ARCH;
-}
target-info.c +47 -0
index 24696ff4111..774fdcd2c46 100644
@@ -11,6 +11,7 @@
  #include "qemu/target-info-qapi.h"
  #include "qemu/target-info-impl.h"
  #include "qapi/error.h"
+#include "system/arch_init.h"
 
  const char *target_name(void)
  {
@@ -33,6 +34,65 @@ SysEmuTarget target_arch(void)
      return arch;
  }
 
+bool qemu_arch_available(unsigned qemu_arch_mask)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_ALPHA:
+        return qemu_arch_mask & QEMU_ARCH_ALPHA;
+    case SYS_EMU_TARGET_ARM:
+    case SYS_EMU_TARGET_AARCH64:
+        return qemu_arch_mask & QEMU_ARCH_ARM;
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return qemu_arch_mask & QEMU_ARCH_I386;
+    case SYS_EMU_TARGET_M68K:
+        return qemu_arch_mask & QEMU_ARCH_M68K;
+    case SYS_EMU_TARGET_MICROBLAZE:
+    case SYS_EMU_TARGET_MICROBLAZEEL:
+        return qemu_arch_mask & QEMU_ARCH_MICROBLAZE;
+    case SYS_EMU_TARGET_MIPS:
+    case SYS_EMU_TARGET_MIPSEL:
+    case SYS_EMU_TARGET_MIPS64:
+    case SYS_EMU_TARGET_MIPS64EL:
+        return qemu_arch_mask & QEMU_ARCH_MIPS;
+    case SYS_EMU_TARGET_PPC:
+    case SYS_EMU_TARGET_PPC64:
+        return qemu_arch_mask & QEMU_ARCH_PPC;
+    case SYS_EMU_TARGET_S390X:
+        return qemu_arch_mask & QEMU_ARCH_S390X;
+    case SYS_EMU_TARGET_SH4:
+    case SYS_EMU_TARGET_SH4EB:
+        return qemu_arch_mask & QEMU_ARCH_SH4;
+    case SYS_EMU_TARGET_SPARC:
+    case SYS_EMU_TARGET_SPARC64:
+        return qemu_arch_mask & QEMU_ARCH_SPARC;
+    case SYS_EMU_TARGET_XTENSA:
+    case SYS_EMU_TARGET_XTENSAEB:
+        return qemu_arch_mask & QEMU_ARCH_XTENSA;
+    case SYS_EMU_TARGET_OR1K:
+        return qemu_arch_mask & QEMU_ARCH_OPENRISC;
+    case SYS_EMU_TARGET_TRICORE:
+        return qemu_arch_mask & QEMU_ARCH_TRICORE;
+    case SYS_EMU_TARGET_HPPA:
+        return qemu_arch_mask & QEMU_ARCH_HPPA;
+    case SYS_EMU_TARGET_RISCV32:
+    case SYS_EMU_TARGET_RISCV64:
+        return qemu_arch_mask & QEMU_ARCH_RISCV;
+    case SYS_EMU_TARGET_RX:
+        return qemu_arch_mask & QEMU_ARCH_RX;

target-info.c SysEmuTarget target_arch(void) · line 92

Quoted 10 lines
target-info.c +10 -0
+    case SYS_EMU_TARGET_AVR:
+        return qemu_arch_mask & QEMU_ARCH_AVR;
+    /*
+    case SYS_EMU_TARGET_HEXAGON:
+        return qemu_arch_mask & QEMU_ARCH_HEXAGON;
+    */
+    case SYS_EMU_TARGET_LOONGARCH64:
+        return qemu_arch_mask & QEMU_ARCH_LOONGARCH;
+    default:
+        g_assert_not_reached();

Per explaination on previous version, would be more interesting to have SYS_EMU_TARGET__MAX instead of default here, so compilation will be blocked when enum is extended.

Quoted 16 lines
target-info.c +3 -0
+    };
+}
+
  const char *target_cpu_type(void)
  {
      return target_info()->cpu_type;
system/meson.build +0 -1
index 4b69ef0f5fb..66e16db55ce 100644
@@ -1,5 +1,4 @@
  specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'arch_init.c',
    'globals-target.c',
  )])
 
#4 lore raw
Quoted 143 lines · Pierrick Bouvier
Quoted 142 lines · Philippe Mathieu-Daudé

Get the base arch_mask from the current SysEmuTarget, making qemu_arch_available() target-agnostic.

We don't need the per-target QEMU_ARCH definition anymore, remove it.

---
v3: Return directly within switch
v2: Prefer switch over array (pbo)
---
  meson.build        |  2 --
  system/arch_init.c | 30 ----------------------- target-info.c      | 60 ++++++++++++++++++++++++++++++++++++++++++++++ system/meson.build |  1 -

  4 files changed, 60 insertions(+), 33 deletions(-)

  delete mode 100644 system/arch_init.c

meson.build +0 -0
index 734c801cc77..435dc6e3c8e 100644
@@ -3419,8 +3419,6 @@ foreach target : target_dirs
         config_target_data.set(k, v)

      endif
    endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
    config_target_h += {target: configure_file(output: target + '- config-target.h',
                                                 configuration: config_target_data)}

system/arch_init.c deleted +0 -6
deleted file mode 100644
index e85736884c9..00000000000
@@ -1,30 +0,0 @@
-/*
- * QEMU System Emulator
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person 

obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/ or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */

system/arch_init.c deleted +0 -7
-#include "qemu/osdep.h"
-#include "system/arch_init.h"
-
-bool qemu_arch_available(unsigned qemu_arch_mask)
-{
-    return qemu_arch_mask & QEMU_ARCH;
-}
target-info.c +51 -0
index 24696ff4111..774fdcd2c46 100644
@@ -11,6 +11,7 @@
   #include "qemu/target-info-qapi.h"
   #include "qemu/target-info-impl.h"
   #include "qapi/error.h"
+#include "system/arch_init.h"
   const char *target_name(void)
   {
@@ -33,6 +34,65 @@ SysEmuTarget target_arch(void)
       return arch;
   }
+bool qemu_arch_available(unsigned qemu_arch_mask)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_ALPHA:
+        return qemu_arch_mask & QEMU_ARCH_ALPHA;
+    case SYS_EMU_TARGET_ARM:
+    case SYS_EMU_TARGET_AARCH64:
+        return qemu_arch_mask & QEMU_ARCH_ARM;
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return qemu_arch_mask & QEMU_ARCH_I386;
+    case SYS_EMU_TARGET_M68K:
+        return qemu_arch_mask & QEMU_ARCH_M68K;
+    case SYS_EMU_TARGET_MICROBLAZE:
+    case SYS_EMU_TARGET_MICROBLAZEEL:
+        return qemu_arch_mask & QEMU_ARCH_MICROBLAZE;
+    case SYS_EMU_TARGET_MIPS:
+    case SYS_EMU_TARGET_MIPSEL:
+    case SYS_EMU_TARGET_MIPS64:
+    case SYS_EMU_TARGET_MIPS64EL:
+        return qemu_arch_mask & QEMU_ARCH_MIPS;
+    case SYS_EMU_TARGET_PPC:
+    case SYS_EMU_TARGET_PPC64:
+        return qemu_arch_mask & QEMU_ARCH_PPC;
+    case SYS_EMU_TARGET_S390X:
+        return qemu_arch_mask & QEMU_ARCH_S390X;
+    case SYS_EMU_TARGET_SH4:
+    case SYS_EMU_TARGET_SH4EB:
+        return qemu_arch_mask & QEMU_ARCH_SH4;
+    case SYS_EMU_TARGET_SPARC:
+    case SYS_EMU_TARGET_SPARC64:
+        return qemu_arch_mask & QEMU_ARCH_SPARC;
+    case SYS_EMU_TARGET_XTENSA:
+    case SYS_EMU_TARGET_XTENSAEB:
+        return qemu_arch_mask & QEMU_ARCH_XTENSA;
+    case SYS_EMU_TARGET_OR1K:
+        return qemu_arch_mask & QEMU_ARCH_OPENRISC;
+    case SYS_EMU_TARGET_TRICORE:
+        return qemu_arch_mask & QEMU_ARCH_TRICORE;
+    case SYS_EMU_TARGET_HPPA:
+        return qemu_arch_mask & QEMU_ARCH_HPPA;
+    case SYS_EMU_TARGET_RISCV32:
+    case SYS_EMU_TARGET_RISCV64:
+        return qemu_arch_mask & QEMU_ARCH_RISCV;
+    case SYS_EMU_TARGET_RX:
+        return qemu_arch_mask & QEMU_ARCH_RX;
+    case SYS_EMU_TARGET_AVR:
+        return qemu_arch_mask & QEMU_ARCH_AVR;
+    /*
+    case SYS_EMU_TARGET_HEXAGON:
Quoted 8 lines

target-info.c SysEmuTarget target_arch(void) · line 92

Quoted 6 lines
target-info.c +6 -0
+        return qemu_arch_mask & QEMU_ARCH_HEXAGON;
+    */
+    case SYS_EMU_TARGET_LOONGARCH64:
+        return qemu_arch_mask & QEMU_ARCH_LOONGARCH;
+    default:
+        g_assert_not_reached();

Per explaination on previous version, would be more interesting to have SYS_EMU_TARGET__MAX instead of default here, so compilation will be blocked when enum is extended.

How compilation can be blocked without using -Wswitch?

Quoted 18 lines
Quoted 15 lines
target-info.c +3 -0
+    };
+}
+
   const char *target_cpu_type(void)
   {
       return target_info()->cpu_type;
system/meson.build +0 -0
index 4b69ef0f5fb..66e16db55ce 100644
@@ -1,5 +1,4 @@

  specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files( -  'arch_init.c',
    'globals-target.c',
  )])

#5 lore raw
Quoted 157 lines · Philippe Mathieu-Daudé
Quoted 147 lines · Pierrick Bouvier
Quoted 146 lines · Philippe Mathieu-Daudé

Get the base arch_mask from the current SysEmuTarget, making qemu_arch_available() target-agnostic.

We don't need the per-target QEMU_ARCH definition anymore, remove it.

---
v3: Return directly within switch
v2: Prefer switch over array (pbo)

---
   meson.build        |  2 --
   system/arch_init.c | 30 -----------------------
   target-info.c      | 60 ++++++++++++++++++++++++++++++++++++++++++++++
   system/meson.build |  1 -
   4 files changed, 60 insertions(+), 33 deletions(-)

  delete mode 100644 system/arch_init.c

meson.build +0 -2
index 734c801cc77..435dc6e3c8e 100644
@@ -3419,8 +3419,6 @@ foreach target : target_dirs
         config_target_data.set(k, v)
       endif
     endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' +
 config_target['TARGET_BASE_ARCH'].to_upper())
     config_target_h += {target: configure_file(output: target + '-
 config-target.h',

                                                 configuration:
config_target_data)}

system/arch_init.c deleted +0 -6
deleted file mode 100644
index e85736884c9..00000000000
@@ -1,30 +0,0 @@
-/*
- * QEMU System Emulator
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person

obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/ or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */

system/arch_init.c deleted +0 -7
-#include "qemu/osdep.h"
-#include "system/arch_init.h"
-
-bool qemu_arch_available(unsigned qemu_arch_mask)
-{
-    return qemu_arch_mask & QEMU_ARCH;
-}
target-info.c +53 -0
index 24696ff4111..774fdcd2c46 100644
@@ -11,6 +11,7 @@
   #include "qemu/target-info-qapi.h"
   #include "qemu/target-info-impl.h"
   #include "qapi/error.h"
+#include "system/arch_init.h"
   const char *target_name(void)
   {
@@ -33,6 +34,65 @@ SysEmuTarget target_arch(void)
       return arch;
   }
+bool qemu_arch_available(unsigned qemu_arch_mask)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_ALPHA:
+        return qemu_arch_mask & QEMU_ARCH_ALPHA;
+    case SYS_EMU_TARGET_ARM:
+    case SYS_EMU_TARGET_AARCH64:
+        return qemu_arch_mask & QEMU_ARCH_ARM;
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return qemu_arch_mask & QEMU_ARCH_I386;
+    case SYS_EMU_TARGET_M68K:
+        return qemu_arch_mask & QEMU_ARCH_M68K;
+    case SYS_EMU_TARGET_MICROBLAZE:
+    case SYS_EMU_TARGET_MICROBLAZEEL:
+        return qemu_arch_mask & QEMU_ARCH_MICROBLAZE;
+    case SYS_EMU_TARGET_MIPS:
+    case SYS_EMU_TARGET_MIPSEL:
+    case SYS_EMU_TARGET_MIPS64:
+    case SYS_EMU_TARGET_MIPS64EL:
+        return qemu_arch_mask & QEMU_ARCH_MIPS;
+    case SYS_EMU_TARGET_PPC:
+    case SYS_EMU_TARGET_PPC64:
+        return qemu_arch_mask & QEMU_ARCH_PPC;
+    case SYS_EMU_TARGET_S390X:
+        return qemu_arch_mask & QEMU_ARCH_S390X;
+    case SYS_EMU_TARGET_SH4:
+    case SYS_EMU_TARGET_SH4EB:
+        return qemu_arch_mask & QEMU_ARCH_SH4;
+    case SYS_EMU_TARGET_SPARC:
+    case SYS_EMU_TARGET_SPARC64:
+        return qemu_arch_mask & QEMU_ARCH_SPARC;
+    case SYS_EMU_TARGET_XTENSA:
+    case SYS_EMU_TARGET_XTENSAEB:
+        return qemu_arch_mask & QEMU_ARCH_XTENSA;
+    case SYS_EMU_TARGET_OR1K:
+        return qemu_arch_mask & QEMU_ARCH_OPENRISC;
+    case SYS_EMU_TARGET_TRICORE:
+        return qemu_arch_mask & QEMU_ARCH_TRICORE;
+    case SYS_EMU_TARGET_HPPA:
+        return qemu_arch_mask & QEMU_ARCH_HPPA;
+    case SYS_EMU_TARGET_RISCV32:
+    case SYS_EMU_TARGET_RISCV64:
+        return qemu_arch_mask & QEMU_ARCH_RISCV;
+    case SYS_EMU_TARGET_RX:
+        return qemu_arch_mask & QEMU_ARCH_RX;
+    case SYS_EMU_TARGET_AVR:
+        return qemu_arch_mask & QEMU_ARCH_AVR;
+    /*
+    case SYS_EMU_TARGET_HEXAGON:
+        return qemu_arch_mask & QEMU_ARCH_HEXAGON;
+    */
Quoted 8 lines

target-info.c SysEmuTarget target_arch(void) · line 92

Quoted 4 lines
target-info.c +4 -0
+    case SYS_EMU_TARGET_LOONGARCH64:
+        return qemu_arch_mask & QEMU_ARCH_LOONGARCH;
+    default:
+        g_assert_not_reached();

Per explaination on previous version, would be more interesting to have SYS_EMU_TARGET__MAX instead of default here, so compilation will be blocked when enum is extended.

Quoted 2 lines

How compilation can be blocked without using -Wswitch?

See my previous answer on v1, -Wswitch is used:

Reading the thread above, the only mention I find is the 3rd commit that precisely change definition because -Wswitch is enabled with clang. And it's not only a clang thing, gcc has it in Wall also [1].

I don't mind the array approach, but maybe just add a *static* assert making sure (SYS_EMU_TARGET__MAX-1 == SYS_EMU_TARGET_XTENSAEB) so this file will break as soon as there is a new target added. It's simple and the next developer who won't have to debug this will thank you.

[1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html

Quoted 19 lines
Quoted 18 lines
Quoted 15 lines
target-info.c +3 -0
+    };
+}
+
   const char *target_cpu_type(void)
   {
       return target_info()->cpu_type;
system/meson.build +0 -1
index 4b69ef0f5fb..66e16db55ce 100644
@@ -1,5 +1,4 @@
   specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'arch_init.c',
     'globals-target.c',
   )])
#6 lore raw
Quoted 160 lines · Pierrick Bouvier
Quoted 159 lines · Philippe Mathieu-Daudé
Quoted 157 lines · Pierrick Bouvier
Quoted 142 lines · Philippe Mathieu-Daudé

Get the base arch_mask from the current SysEmuTarget, making qemu_arch_available() target-agnostic.

We don't need the per-target QEMU_ARCH definition anymore, remove it.

---
v3: Return directly within switch
v2: Prefer switch over array (pbo)
---
   meson.build        |  2 --
   system/arch_init.c | 30 ----------------------- target-info.c      | 60 +++++++++++++++++++++++++++++++++++++++++
+++++
   system/meson.build |  1 -

   4 files changed, 60 insertions(+), 33 deletions(-)

   delete mode 100644 system/arch_init.c

meson.build +0 -0
index 734c801cc77..435dc6e3c8e 100644
@@ -3419,8 +3419,6 @@ foreach target : target_dirs
          config_target_data.set(k, v)

       endif
     endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper()) config_target_h += {target: configure_file(output: target + '- config-target.h',
                                                  configuration:
config_target_data)}

system/arch_init.c deleted +0 -6
deleted file mode 100644
index e85736884c9..00000000000
@@ -1,30 +0,0 @@
-/*
- * QEMU System Emulator
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person

obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/ or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */

system/arch_init.c deleted +0 -7
-#include "qemu/osdep.h"
-#include "system/arch_init.h"
-
-bool qemu_arch_available(unsigned qemu_arch_mask)
-{
-    return qemu_arch_mask & QEMU_ARCH;
-}
target-info.c +47 -0
index 24696ff4111..774fdcd2c46 100644
@@ -11,6 +11,7 @@
    #include "qemu/target-info-qapi.h"
    #include "qemu/target-info-impl.h"
    #include "qapi/error.h"
+#include "system/arch_init.h"
    const char *target_name(void)
    {
@@ -33,6 +34,65 @@ SysEmuTarget target_arch(void)
        return arch;
    }
+bool qemu_arch_available(unsigned qemu_arch_mask)
+{
+    switch (target_arch()) {
+    case SYS_EMU_TARGET_ALPHA:
+        return qemu_arch_mask & QEMU_ARCH_ALPHA;
+    case SYS_EMU_TARGET_ARM:
+    case SYS_EMU_TARGET_AARCH64:
+        return qemu_arch_mask & QEMU_ARCH_ARM;
+    case SYS_EMU_TARGET_I386:
+    case SYS_EMU_TARGET_X86_64:
+        return qemu_arch_mask & QEMU_ARCH_I386;
+    case SYS_EMU_TARGET_M68K:
+        return qemu_arch_mask & QEMU_ARCH_M68K;
+    case SYS_EMU_TARGET_MICROBLAZE:
+    case SYS_EMU_TARGET_MICROBLAZEEL:
+        return qemu_arch_mask & QEMU_ARCH_MICROBLAZE;
+    case SYS_EMU_TARGET_MIPS:
+    case SYS_EMU_TARGET_MIPSEL:
+    case SYS_EMU_TARGET_MIPS64:
+    case SYS_EMU_TARGET_MIPS64EL:
+        return qemu_arch_mask & QEMU_ARCH_MIPS;
+    case SYS_EMU_TARGET_PPC:
+    case SYS_EMU_TARGET_PPC64:
+        return qemu_arch_mask & QEMU_ARCH_PPC;
+    case SYS_EMU_TARGET_S390X:
+        return qemu_arch_mask & QEMU_ARCH_S390X;
+    case SYS_EMU_TARGET_SH4:
+    case SYS_EMU_TARGET_SH4EB:
+        return qemu_arch_mask & QEMU_ARCH_SH4;
+    case SYS_EMU_TARGET_SPARC:
+    case SYS_EMU_TARGET_SPARC64:
+        return qemu_arch_mask & QEMU_ARCH_SPARC;
+    case SYS_EMU_TARGET_XTENSA:
+    case SYS_EMU_TARGET_XTENSAEB:
+        return qemu_arch_mask & QEMU_ARCH_XTENSA;
+    case SYS_EMU_TARGET_OR1K:
+        return qemu_arch_mask & QEMU_ARCH_OPENRISC;
+    case SYS_EMU_TARGET_TRICORE:
+        return qemu_arch_mask & QEMU_ARCH_TRICORE;
+    case SYS_EMU_TARGET_HPPA:
+        return qemu_arch_mask & QEMU_ARCH_HPPA;
+    case SYS_EMU_TARGET_RISCV32:
+    case SYS_EMU_TARGET_RISCV64:
+        return qemu_arch_mask & QEMU_ARCH_RISCV;
+    case SYS_EMU_TARGET_RX:
+        return qemu_arch_mask & QEMU_ARCH_RX;

target-info.c SysEmuTarget target_arch(void) · line 91

Quoted 10 lines
target-info.c +10 -0
+    case SYS_EMU_TARGET_AVR:
+        return qemu_arch_mask & QEMU_ARCH_AVR;
+    /*
+    case SYS_EMU_TARGET_HEXAGON:
+        return qemu_arch_mask & QEMU_ARCH_HEXAGON;
+    */
+    case SYS_EMU_TARGET_LOONGARCH64:
+        return qemu_arch_mask & QEMU_ARCH_LOONGARCH;
+    default:
+        g_assert_not_reached();

Per explaination on previous version, would be more interesting to have SYS_EMU_TARGET__MAX instead of default here, so compilation will be blocked when enum is extended.

Quoted 8 lines
Quoted 2 lines

How compilation can be blocked without using -Wswitch?

See my previous answer on v1, -Wswitch is used:

Reading the thread above, the only mention I find is the 3rd commit that precisely change definition because -Wswitch is enabled with clang. And it's not only a clang thing, gcc has it in Wall also [1].

Yes I read that, I'd really like we use -Wswitch but IIUC we can not, so with that in mind I don't understand your request. Is that for the hypothetical case we can use -Wswitch in the future? Sorry I'm not trying to be picky here, I just fail to see the problem you raised :(

Quoted 27 lines

I don't mind the array approach, but maybe just add a *static* assert making sure (SYS_EMU_TARGET__MAX-1 == SYS_EMU_TARGET_XTENSAEB) so this file will break as soon as there is a new target added. It's simple and the next developer who won't have to debug this will thank you.

[1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html

Quoted 19 lines
Quoted 18 lines
Quoted 15 lines
target-info.c +3 -0
+    };
+}
+
    const char *target_cpu_type(void)
    {
        return target_info()->cpu_type;
system/meson.build +0 -0
index 4b69ef0f5fb..66e16db55ce 100644
@@ -1,5 +1,4 @@

   specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files( -  'arch_init.c',
     'globals-target.c',
   )])

#7 lore raw
Quoted 1 line · Philippe Mathieu-Daudé

On 9/1/26 07:58, Pierrick Bouvier wrote:

[...]

Quoted 9 lines
Quoted 4 lines

See my previous answer on v1, -Wswitch is used:
Reading the thread above, the only mention I find is the 3rd commit that precisely change definition because -Wswitch is enabled with clang. And it's not only a clang thing, gcc has it in Wall also [1].

Yes I read that, I'd really like we use -Wswitch but IIUC we can not, so with that in mind I don't understand your request. Is that for the hypothetical case we can use -Wswitch in the future? Sorry I'm not trying to be picky here, I just fail to see the problem you raised :(

We *are* using -Wswitch.

To see that, delete the default: case in to_json()'s outer switch (patch appended), and compile:

../qobject/qjson.c: In function ‘to_json’:
../qobject/qjson.c:154:5: warning: enumeration value ‘QTYPE_NONE’ not handled in switch [-Wswitch]
154 | switch (qobject_type(obj)) {
| ^~~~~~
../qobject/qjson.c:154:5: warning: enumeration value ‘QTYPE__MAX’ not handled in switch [-Wswitch]

We run gcc -Wall, which implies -Wswitch.

[...]

qobject/qjson.c +0 -2
index c858dafb5e..6287c93c67 100644
@@ -213,8 +213,6 @@ static void to_json(JSONWriter *writer, const char *name,
         json_writer_bool(writer, name, qbool_get_bool(val));
         break;
     }
-    default:
-        abort();
     }
 }
 
#8 lore raw
Quoted 11 lines · Markus Armbruster
Quoted 1 line · Philippe Mathieu-Daudé

On 9/1/26 07:58, Pierrick Bouvier wrote:

[...]

Quoted 5 lines
Quoted 4 lines

See my previous answer on v1, -Wswitch is used:
Reading the thread above, the only mention I find is the 3rd commit that precisely change definition because -Wswitch is enabled with clang. And it's not only a clang thing, gcc has it in Wall also [1].

Quoted 6 lines
Quoted 4 lines

Yes I read that, I'd really like we use -Wswitch but IIUC we can not, so with that in mind I don't understand your request. Is that for the hypothetical case we can use -Wswitch in the future? Sorry I'm not trying to be picky here, I just fail to see the problem you raised :(

We *are* using -Wswitch.

Oh... I guess I meant -Wswitch-enum then (which forces to handle the -- meaningless in that case -- QAPI foo__MAX enum values).

Anyway time to stop bikeshedding and call it a day (originally I just wanted to remove the duplicated qemu_arch_available symbol :) ).

Quoted 28 lines

To see that, delete the default: case in to_json()'s outer switch (patch appended), and compile:

../qobject/qjson.c: In function ‘to_json’:
../qobject/qjson.c:154:5: warning: enumeration value ‘QTYPE_NONE’ not handled in switch [-Wswitch]
154 | switch (qobject_type(obj)) {
| ^~~~~~
../qobject/qjson.c:154:5: warning: enumeration value ‘QTYPE__MAX’ not handled in switch [-Wswitch]

We run gcc -Wall, which implies -Wswitch.

[...]

qobject/qjson.c +0 -2
index c858dafb5e..6287c93c67 100644
@@ -213,8 +213,6 @@ static void to_json(JSONWriter *writer, const char *name,
          json_writer_bool(writer, name, qbool_get_bool(val));
          break;
      }
-    default:
-        abort();
      }
  }
 
#9 lore raw
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Markus Armbruster
Quoted 1 line · Philippe Mathieu-Daudé

On 9/1/26 07:58, Pierrick Bouvier wrote:

[...]

Quoted 9 lines
Quoted 4 lines

See my previous answer on v1, -Wswitch is used:
Reading the thread above, the only mention I find is the 3rd commit that precisely change definition because -Wswitch is enabled with clang. And it's not only a clang thing, gcc has it in Wall also [1].

Yes I read that, I'd really like we use -Wswitch but IIUC we can not, so with that in mind I don't understand your request. Is that for the hypothetical case we can use -Wswitch in the future? Sorry I'm not trying to be picky here, I just fail to see the problem you raised :(

Quoted 5 lines
Quoted 1 line

We *are* using -Wswitch.

Oh... I guess I meant -Wswitch-enum then (which forces to handle the -- meaningless in that case -- QAPI foo__MAX enum values).

Yes :)

Quoted 3 lines

Anyway time to stop bikeshedding and call it a day (originally I just wanted to remove the duplicated qemu_arch_available symbol :) ).

I agree, and sorry for the discussion that has been triggered.

My original point was that a switch allows to catch missing cases, but *ONLY* if it does not include a default:.
So either stick to the array, or change the switch to remove the default case. Even though I prefer the switch (without default), I don't mind if you prefer the array at this point. You had my review on first version anyway.

Quoted 11 lines
Quoted 11 lines

To see that, delete the default: case in to_json()'s outer switch (patch appended), and compile:

../qobject/qjson.c: In function ‘to_json’:
../qobject/qjson.c:154:5: warning: enumeration value ‘QTYPE_NONE’ not handled in switch [-Wswitch]
154 | switch (qobject_type(obj)) {
| ^~~~~~
../qobject/qjson.c:154:5: warning: enumeration value ‘QTYPE__MAX’ not handled in switch [-Wswitch]

We run gcc -Wall, which implies -Wswitch.

Thanks Markus, that was my point indeed.

Quoted 18 lines
Quoted 17 lines

[...]

qobject/qjson.c +0 -2
index c858dafb5e..6287c93c67 100644
@@ -213,8 +213,6 @@ static void to_json(JSONWriter *writer, const char *name,
           json_writer_bool(writer, name, qbool_get_bool(val));
           break;
       }
-    default:
-        abort();
       }
   }