On 10/7/2026 7:47 AM, Yonggang Luo wrote:
> On Wed, Oct 7, 2026 at 10:29 PM Pierrick Bouvier
> <[email protected]> wrote:
>>
>> On 10/7/2026 12:48 AM, Yonggang Luo wrote:
>>> On Wed, Oct 7, 2026 at 12:03 PM Pierrick Bouvier
>>> <[email protected]> wrote:
>>>>
>>>> For now, TARGET_ARCH only contains 32 vs 64 bit arch. The variants,
>>>> based on endianness, are accessible through TARGET_NAME. However,
>>>> TARGET_NAME is a string, and thus can't be concatenated to generate code
>>>> and retrieve matching SYS_EMU_TARGET enum entry.
>>>> Thus, export this information in TARGET_ARCH_VARIANT as an unquoted
>>>> identifier.
>>>>
>>>> There is one more subtlety, user binaries have extra targets that are
>>>> not present in SYS_EMU_TARGET, like armeb.
>>>> Thus, for user binaries, simply export TARGET_ARCH.
>>>
>>>
>>>>
>>>> Signed-off-by: Pierrick Bouvier <[email protected]>
>>>> ---
>>>>  meson.build | 11 +++++++++--
>>>>  1 file changed, 9 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/meson.build b/meson.build
>>>> index cae1591cd28..9bcfe84daba 100644
>>>> --- a/meson.build
>>>> +++ b/meson.build
>>>> @@ -3288,7 +3288,14 @@ default_targets = 'CONFIG_DEFAULT_TARGETS' in 
>>>> config_host
>>>>  actual_target_dirs = []
>>>>  fdt_required = []
>>>>  foreach target : target_dirs
>>>> -  config_target = { 'TARGET_NAME': target.split('-')[0] }
>>>> +  target_name = target.split('-')[0]
>>>> +  config_target = { 'TARGET_NAME': target_name }
>>>> +  if target.endswith('linux-user')
>>>> +    config_target += { 'TARGET_ARCH_VARIANT': 'TARGET_ARCH' }
>>>
>>> If TARGET_ARCH_VARIANT or just called (TARGET_NAME_ENUM) is just a
>>> direct mapping of target_name regardless linux-user/bsd-user/softmmu,
>>> the logic would
>>> be simpler. That would need add more enum to SYS_EMU_TARGET, the
>>> current form is:
>>> ##
>>> # @SysEmuTarget:
>>> #     The comprehensive enumeration of QEMU system emulation
>>> #     ("softmmu") targets.  Run "./configure --help" in the project
>>> #     root directory, and look for the \*-softmmu targets near the
>>> #     "--target-list" option.  The individual target constants are not
>>> #     documented here, for the time being.
>>> #
>>> # @rx: since 5.0
>>> #
>>> # @avr: since 5.1
>>> #
>>> # @loongarch64: since 7.1
>>> #
>>> # @hexagon: since 11.0
>>> #
>>> # .. note:: The resulting QMP strings can be appended to the
>>> #    "qemu-system-" prefix to produce the corresponding QEMU
>>> #    executable name.  This is true even for "qemu-system-x86_64".
>>> #
>>> # Since: 3.0
>>> ##
>>> { 'enum' : 'SysEmuTarget',
>>>   'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'hexagon', 'hppa', 'i386',
>>>              'loongarch64', 'm68k', 'microblaze', 'mips', 'mips64',
>>>              'mips64el', 'mipsel', 'or1k', 'ppc',
>>>              'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
>>>              'sh4eb', 'sparc', 'sparc64', 'tricore',
>>>              'x86_64', 'xtensa', 'xtensaeb' ] }
>>>
>>>
>>> The list target names that missing from SysEmuTarget:
>>>
>>> Comparing the target-name prefixes of `configs/targets/*.mak` with the
>>> `SysEmuTarget` enum in `qapi/machine.json`, the following seven names are
>>> missing. All are Linux-user-only targets.
>>>
>>> | Target name | Config |
>>> |---|---|
>>> | `aarch64_be` | `configs/targets/aarch64_be-linux-user.mak` |
>>> | `armeb` | `configs/targets/armeb-linux-user.mak` |
>>> | `microblazeel` | `configs/targets/microblazeel-linux-user.mak` |
>>> | `mipsn32` | `configs/targets/mipsn32-linux-user.mak` |
>>> | `mipsn32el` | `configs/targets/mipsn32el-linux-user.mak` |
>>> | `ppc64le` | `configs/targets/ppc64le-linux-user.mak` |
>>> | `sparc32plus` | `configs/targets/sparc32plus-linux-user.mak` |
>>>
>>> All `*-softmmu` and `*-bsd-user` target names match enum entries.
>>>
>>> This comparison uses names derived from config filenames, not the
>>> `TARGET_ARCH` values inside those configs.
>>>
>>> By doing this I think it would be more consistent.
>>> If these target names are removed in future, then just remove it from
>>> SysEmuTarget
>>> along with. So SysEmuTarget is just a direct mapping of TARGET_NAME. Though
>>> The comment of SysEmuTarget needs updated, it's not just about softmmu, but 
>>> also
>>> for linux-user and bsd-user. But the fact is, with the current
>>> changes. *-user also
>>> used SysEmuTarget as an enum.
>>>
>>>
>>> And TARGET_ARCH should also be exported by TargetInfo for other usage.
>>> And it's enums is the subset
>>> of enum SysEmuTarget
>>>
>>
>> I tend to agree, but didn't find a real reason to do this change (yet).
>> Also, I would be in favor to rename SysEmuTarget since in EmuTarget,
>> since it would now be decoupled from system emulation only.
> 
> I think the current patch is enough at the current stage.
>

Agree, the rest is an additional refactoring that belongs to a different
series.

> A better bsd-user/linux-user support needs much more work.
> for example:
> 
> enum {
>     QEMU_ARCH_ALPHA =       (1UL << SYS_EMU_TARGET_ALPHA),
>     QEMU_ARCH_ARM =         (1UL << SYS_EMU_TARGET_ARM) |
>                             (1UL << SYS_EMU_TARGET_AARCH64),
>     QEMU_ARCH_I386 =        (1UL << SYS_EMU_TARGET_I386) |
>                             (1UL << SYS_EMU_TARGET_X86_64),
>     QEMU_ARCH_M68K =        (1UL << SYS_EMU_TARGET_M68K),
>     QEMU_ARCH_MICROBLAZE =  (1UL << SYS_EMU_TARGET_MICROBLAZE),
>     QEMU_ARCH_MIPS =        (1UL << SYS_EMU_TARGET_MIPS) |
>                             (1UL << SYS_EMU_TARGET_MIPSEL) |
>                             (1UL << SYS_EMU_TARGET_MIPS64) |
>                             (1UL << SYS_EMU_TARGET_MIPS64EL),
>     QEMU_ARCH_PPC =         (1UL << SYS_EMU_TARGET_PPC) |
>                             (1UL << SYS_EMU_TARGET_PPC64),
>     QEMU_ARCH_S390X =       (1UL << SYS_EMU_TARGET_S390X),
>     QEMU_ARCH_SH4 =         (1UL << SYS_EMU_TARGET_SH4) |
>                             (1UL << SYS_EMU_TARGET_SH4EB),
>     QEMU_ARCH_SPARC =       (1UL << SYS_EMU_TARGET_SPARC) |
>                             (1UL << SYS_EMU_TARGET_SPARC64),
>     QEMU_ARCH_XTENSA =      (1UL << SYS_EMU_TARGET_XTENSA) |
>                             (1UL << SYS_EMU_TARGET_XTENSAEB),
>     QEMU_ARCH_OR1K =        (1UL << SYS_EMU_TARGET_OR1K),
>     QEMU_ARCH_TRICORE =     (1UL << SYS_EMU_TARGET_TRICORE),
>     QEMU_ARCH_HPPA =        (1UL << SYS_EMU_TARGET_HPPA),
>     QEMU_ARCH_RISCV =       (1UL << SYS_EMU_TARGET_RISCV32) |
>                             (1UL << SYS_EMU_TARGET_RISCV64),
>     QEMU_ARCH_RX =          (1UL << SYS_EMU_TARGET_RX),
>     QEMU_ARCH_AVR =         (1UL << SYS_EMU_TARGET_AVR),
>     QEMU_ARCH_HEXAGON =     (1UL << SYS_EMU_TARGET_HEXAGON),
>     QEMU_ARCH_LOONGARCH =   (1UL << SYS_EMU_TARGET_LOONGARCH64),
>     QEMU_ARCH_ALL =         UINT32_MAX,
> };
> 
> QEMU_BUILD_BUG_ON(SYS_EMU_TARGET__MAX > 32);
> 
> /**
>  * qemu_arch_available:
>  * @arch_bitmask: bitmask of QEMU_ARCH_* constants
>  *
>  * Return whether the current target architecture is contained in 
> @arch_bitmask
>  */
> bool qemu_arch_available(uint32_t arch_bitmask);
> 
> arch_bitmask also needs to be increased to 64bit, and currently
> SYS_EMU_TARGET__MAX is 29, very close to 32.
> 
>

I'll take a look to extend it and do the renaming.

>>
>> @Daniel: Would you be favor to see such a change? I know that
>> introspection/QAPI is related to system emulation, and I'm not
>> completely sure adding user targets is the right move at this moment.
>>
>>>
>>>
>>>> +  else
>>>> +    config_target += { 'TARGET_ARCH_VARIANT': target_name.to_upper() }
>>>> +  endif
>>>> +
>>>>    if target.endswith('linux-user')
>>>>      if host_os != 'linux'
>>>>        if default_targets
>>>> @@ -3372,7 +3379,7 @@ foreach target : target_dirs
>>>>        # do nothing
>>>>      elif ignored.contains(k)
>>>>        # do nothing
>>>> -    elif k == 'TARGET_ARCH'
>>>> +    elif k == 'TARGET_ARCH' or k == 'TARGET_ARCH_VARIANT'
>>>>        config_target_data.set(k, v.to_upper())
>>>>      elif k == 'TARGET_BASE_ARCH'
>>>>        # Note that TARGET_BASE_ARCH ends up in config-target.h but it is
>>>> --
>>>> 2.43.0
>>>>
>>>>
>>>
>>>
>>> --
>>>          此致
>>> 礼
>>> 罗勇刚
>>> Yours
>>>     sincerely,
>>> Yonggang Luo
>>
> 
> 


Reply via email to