[PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system

Pierrick Bouvier posted 12 patches 4 days, 3 hours ago
Maintainers: Peter Maydell <peter.maydell@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>
[PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system
Posted by Pierrick Bouvier 4 days, 3 hours ago
In next commit, we'll apply same helper pattern for base helpers
remaining.

Our new helper pattern always include helper-*-common.h, which ends up
including include/tcg/tcg.h, which contains one occurrence of
CONFIG_USER_ONLY.
Thus, common files not being duplicated between system and target
relying on helpers will fail to compile. Existing occurrences are:
- target/arm/tcg/arith_helper.c
- target/arm/tcg/crypto_helper.c

There is a single occurrence of CONFIG_USER_ONLY, for defining variable
tcg_use_softmmu. The fix seemed simple, always define it.
However, it prevents some dead code elimination which ends up triggering:
include/qemu/osdep.h:283:35: error: call to 'qemu_build_not_reached_always' declared with attribute error: code path is reachable
  283 | #define qemu_build_not_reached()  qemu_build_not_reached_always()
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tcg/x86_64/tcg-target.c.inc:1907:45: note: in expansion of macro 'qemu_build_not_reached'
 1907 | # define x86_guest_base (*(HostAddress *)({ qemu_build_not_reached(); NULL; }))
      |                                             ^~~~~~~~~~~~~~~~~~~~~~
tcg/x86_64/tcg-target.c.inc:1934:14: note: in expansion of macro 'x86_guest_base'
 1934 |         *h = x86_guest_base;
      |              ^~~~~~~~~~~~~~

So, roll your eyes, then rollback code, and simply duplicate the two
files concerned. We could also do a "special include trick" to prevent
pulling helper-*-common.h but it would be sad since the whole point of
the series up to here is to have something coherent using the exact same
pattern.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 target/arm/tcg/meson.build | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/target/arm/tcg/meson.build b/target/arm/tcg/meson.build
index 1b115656c46..41cf9bad4f1 100644
--- a/target/arm/tcg/meson.build
+++ b/target/arm/tcg/meson.build
@@ -58,20 +58,20 @@ arm_user_ss.add(when: 'TARGET_AARCH64', if_false: files('cpu-v7m.c'))
 
 arm_common_ss.add(zlib)
 
-arm_common_ss.add(files(
-  'arith_helper.c',
-  'crypto_helper.c',
-))
-
 arm_common_system_ss.add(files(
+  'arith_helper.c',
+  'crypto_helper.c',
   'cpregs-at.c',
   'hflags.c',
   'neon_helper.c',
   'tlb_helper.c',
   'tlb-insns.c',
   'vfp_helper.c',
+  'crypto_helper.c',
 ))
 arm_user_ss.add(files(
+  'arith_helper.c',
+  'crypto_helper.c',
   'hflags.c',
   'neon_helper.c',
   'tlb_helper.c',
-- 
2.47.3
Re: [PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system
Posted by Richard Henderson 1 day, 2 hours ago
On 2/6/26 14:21, Pierrick Bouvier wrote:
> In next commit, we'll apply same helper pattern for base helpers
> remaining.
> 
> Our new helper pattern always include helper-*-common.h, which ends up
> including include/tcg/tcg.h, which contains one occurrence of
> CONFIG_USER_ONLY.
> Thus, common files not being duplicated between system and target
> relying on helpers will fail to compile. Existing occurrences are:
> - target/arm/tcg/arith_helper.c
> - target/arm/tcg/crypto_helper.c
> 
> There is a single occurrence of CONFIG_USER_ONLY, for defining variable
> tcg_use_softmmu. The fix seemed simple, always define it.
> However, it prevents some dead code elimination which ends up triggering:
> include/qemu/osdep.h:283:35: error: call to 'qemu_build_not_reached_always' declared with attribute error: code path is reachable
>    283 | #define qemu_build_not_reached()  qemu_build_not_reached_always()
>        |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> tcg/x86_64/tcg-target.c.inc:1907:45: note: in expansion of macro 'qemu_build_not_reached'
>   1907 | # define x86_guest_base (*(HostAddress *)({ qemu_build_not_reached(); NULL; }))
>        |                                             ^~~~~~~~~~~~~~~~~~~~~~
> tcg/x86_64/tcg-target.c.inc:1934:14: note: in expansion of macro 'x86_guest_base'
>   1934 |         *h = x86_guest_base;
>        |              ^~~~~~~~~~~~~~
> 
> So, roll your eyes, then rollback code, and simply duplicate the two
> files concerned. We could also do a "special include trick" to prevent
> pulling helper-*-common.h but it would be sad since the whole point of
> the series up to here is to have something coherent using the exact same
> pattern.

tcg_use_softmmu is a stub, waiting for softmmu to be enabled for user-only.
Which is a long way away.

It's also not used outside of tcg/, which means we should move it to tcg/tcg-internal.h.


r~
Re: [PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system
Posted by Pierrick Bouvier 1 day, 1 hour ago
On 2/8/26 9:00 PM, Richard Henderson wrote:
> On 2/6/26 14:21, Pierrick Bouvier wrote:
>> In next commit, we'll apply same helper pattern for base helpers
>> remaining.
>>
>> Our new helper pattern always include helper-*-common.h, which ends up
>> including include/tcg/tcg.h, which contains one occurrence of
>> CONFIG_USER_ONLY.
>> Thus, common files not being duplicated between system and target
>> relying on helpers will fail to compile. Existing occurrences are:
>> - target/arm/tcg/arith_helper.c
>> - target/arm/tcg/crypto_helper.c
>>
>> There is a single occurrence of CONFIG_USER_ONLY, for defining variable
>> tcg_use_softmmu. The fix seemed simple, always define it.
>> However, it prevents some dead code elimination which ends up triggering:
>> include/qemu/osdep.h:283:35: error: call to 'qemu_build_not_reached_always' declared with attribute error: code path is reachable
>>     283 | #define qemu_build_not_reached()  qemu_build_not_reached_always()
>>         |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> tcg/x86_64/tcg-target.c.inc:1907:45: note: in expansion of macro 'qemu_build_not_reached'
>>    1907 | # define x86_guest_base (*(HostAddress *)({ qemu_build_not_reached(); NULL; }))
>>         |                                             ^~~~~~~~~~~~~~~~~~~~~~
>> tcg/x86_64/tcg-target.c.inc:1934:14: note: in expansion of macro 'x86_guest_base'
>>    1934 |         *h = x86_guest_base;
>>         |              ^~~~~~~~~~~~~~
>>
>> So, roll your eyes, then rollback code, and simply duplicate the two
>> files concerned. We could also do a "special include trick" to prevent
>> pulling helper-*-common.h but it would be sad since the whole point of
>> the series up to here is to have something coherent using the exact same
>> pattern.
> 
> tcg_use_softmmu is a stub, waiting for softmmu to be enabled for user-only.
> Which is a long way away.
> 
> It's also not used outside of tcg/, which means we should move it to tcg/tcg-internal.h.
>

Thanks, I didn't think about moving it somewhere else.
This does the trick indeed.

> 
> r~

Regards,
Pierrick
Re: [PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system
Posted by Richard Henderson 1 day ago
On 2/9/26 15:52, Pierrick Bouvier wrote:
> On 2/8/26 9:00 PM, Richard Henderson wrote:
>> On 2/6/26 14:21, Pierrick Bouvier wrote:
>>> In next commit, we'll apply same helper pattern for base helpers
>>> remaining.
>>>
>>> Our new helper pattern always include helper-*-common.h, which ends up
>>> including include/tcg/tcg.h, which contains one occurrence of
>>> CONFIG_USER_ONLY.
>>> Thus, common files not being duplicated between system and target
>>> relying on helpers will fail to compile. Existing occurrences are:
>>> - target/arm/tcg/arith_helper.c
>>> - target/arm/tcg/crypto_helper.c
>>>
>>> There is a single occurrence of CONFIG_USER_ONLY, for defining variable
>>> tcg_use_softmmu. The fix seemed simple, always define it.
>>> However, it prevents some dead code elimination which ends up triggering:
>>> include/qemu/osdep.h:283:35: error: call to 'qemu_build_not_reached_always' declared 
>>> with attribute error: code path is reachable
>>>     283 | #define qemu_build_not_reached()  qemu_build_not_reached_always()
>>>         |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> tcg/x86_64/tcg-target.c.inc:1907:45: note: in expansion of macro 'qemu_build_not_reached'
>>>    1907 | # define x86_guest_base (*(HostAddress *)({ qemu_build_not_reached(); NULL; }))
>>>         |                                             ^~~~~~~~~~~~~~~~~~~~~~
>>> tcg/x86_64/tcg-target.c.inc:1934:14: note: in expansion of macro 'x86_guest_base'
>>>    1934 |         *h = x86_guest_base;
>>>         |              ^~~~~~~~~~~~~~
>>>
>>> So, roll your eyes, then rollback code, and simply duplicate the two
>>> files concerned. We could also do a "special include trick" to prevent
>>> pulling helper-*-common.h but it would be sad since the whole point of
>>> the series up to here is to have something coherent using the exact same
>>> pattern.
>>
>> tcg_use_softmmu is a stub, waiting for softmmu to be enabled for user-only.
>> Which is a long way away.
>>
>> It's also not used outside of tcg/, which means we should move it to tcg/tcg-internal.h.
>>
> 
> Thanks, I didn't think about moving it somewhere else.
> This does the trick indeed.

You can also make it always a #define.  The variable for user-only is never set to true.


r~

Re: [PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system
Posted by Pierrick Bouvier 13 hours ago
On 2/8/26 11:08 PM, Richard Henderson wrote:
> On 2/9/26 15:52, Pierrick Bouvier wrote:
>> On 2/8/26 9:00 PM, Richard Henderson wrote:
>>> On 2/6/26 14:21, Pierrick Bouvier wrote:
>>>> In next commit, we'll apply same helper pattern for base helpers
>>>> remaining.
>>>>
>>>> Our new helper pattern always include helper-*-common.h, which ends up
>>>> including include/tcg/tcg.h, which contains one occurrence of
>>>> CONFIG_USER_ONLY.
>>>> Thus, common files not being duplicated between system and target
>>>> relying on helpers will fail to compile. Existing occurrences are:
>>>> - target/arm/tcg/arith_helper.c
>>>> - target/arm/tcg/crypto_helper.c
>>>>
>>>> There is a single occurrence of CONFIG_USER_ONLY, for defining variable
>>>> tcg_use_softmmu. The fix seemed simple, always define it.
>>>> However, it prevents some dead code elimination which ends up triggering:
>>>> include/qemu/osdep.h:283:35: error: call to 'qemu_build_not_reached_always' declared
>>>> with attribute error: code path is reachable
>>>>      283 | #define qemu_build_not_reached()  qemu_build_not_reached_always()
>>>>          |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> tcg/x86_64/tcg-target.c.inc:1907:45: note: in expansion of macro 'qemu_build_not_reached'
>>>>     1907 | # define x86_guest_base (*(HostAddress *)({ qemu_build_not_reached(); NULL; }))
>>>>          |                                             ^~~~~~~~~~~~~~~~~~~~~~
>>>> tcg/x86_64/tcg-target.c.inc:1934:14: note: in expansion of macro 'x86_guest_base'
>>>>     1934 |         *h = x86_guest_base;
>>>>          |              ^~~~~~~~~~~~~~
>>>>
>>>> So, roll your eyes, then rollback code, and simply duplicate the two
>>>> files concerned. We could also do a "special include trick" to prevent
>>>> pulling helper-*-common.h but it would be sad since the whole point of
>>>> the series up to here is to have something coherent using the exact same
>>>> pattern.
>>>
>>> tcg_use_softmmu is a stub, waiting for softmmu to be enabled for user-only.
>>> Which is a long way away.
>>>
>>> It's also not used outside of tcg/, which means we should move it to tcg/tcg-internal.h.
>>>
>>
>> Thanks, I didn't think about moving it somewhere else.
>> This does the trick indeed.
> 
> You can also make it always a #define.  The variable for user-only is never set to true.
> 
> 
> r~

Sure, let's go for a define then. :)

Regards,
Pierrick

Re: [PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system
Posted by Pierrick Bouvier 13 hours ago
On 2/9/26 9:57 AM, Pierrick Bouvier wrote:
> On 2/8/26 11:08 PM, Richard Henderson wrote:
>> On 2/9/26 15:52, Pierrick Bouvier wrote:
>>> On 2/8/26 9:00 PM, Richard Henderson wrote:
>>>> On 2/6/26 14:21, Pierrick Bouvier wrote:
>>>>> In next commit, we'll apply same helper pattern for base helpers
>>>>> remaining.
>>>>>
>>>>> Our new helper pattern always include helper-*-common.h, which ends up
>>>>> including include/tcg/tcg.h, which contains one occurrence of
>>>>> CONFIG_USER_ONLY.
>>>>> Thus, common files not being duplicated between system and target
>>>>> relying on helpers will fail to compile. Existing occurrences are:
>>>>> - target/arm/tcg/arith_helper.c
>>>>> - target/arm/tcg/crypto_helper.c
>>>>>
>>>>> There is a single occurrence of CONFIG_USER_ONLY, for defining variable
>>>>> tcg_use_softmmu. The fix seemed simple, always define it.
>>>>> However, it prevents some dead code elimination which ends up triggering:
>>>>> include/qemu/osdep.h:283:35: error: call to 'qemu_build_not_reached_always' declared
>>>>> with attribute error: code path is reachable
>>>>>       283 | #define qemu_build_not_reached()  qemu_build_not_reached_always()
>>>>>           |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>> tcg/x86_64/tcg-target.c.inc:1907:45: note: in expansion of macro 'qemu_build_not_reached'
>>>>>      1907 | # define x86_guest_base (*(HostAddress *)({ qemu_build_not_reached(); NULL; }))
>>>>>           |                                             ^~~~~~~~~~~~~~~~~~~~~~
>>>>> tcg/x86_64/tcg-target.c.inc:1934:14: note: in expansion of macro 'x86_guest_base'
>>>>>      1934 |         *h = x86_guest_base;
>>>>>           |              ^~~~~~~~~~~~~~
>>>>>
>>>>> So, roll your eyes, then rollback code, and simply duplicate the two
>>>>> files concerned. We could also do a "special include trick" to prevent
>>>>> pulling helper-*-common.h but it would be sad since the whole point of
>>>>> the series up to here is to have something coherent using the exact same
>>>>> pattern.
>>>>
>>>> tcg_use_softmmu is a stub, waiting for softmmu to be enabled for user-only.
>>>> Which is a long way away.
>>>>
>>>> It's also not used outside of tcg/, which means we should move it to tcg/tcg-internal.h.
>>>>
>>>
>>> Thanks, I didn't think about moving it somewhere else.
>>> This does the trick indeed.
>>
>> You can also make it always a #define.  The variable for user-only is never set to true.
>>
>>
>> r~
> 
> Sure, let's go for a define then. :)
> 
> Regards,
> Pierrick

Does a simple #define tcg_use_softmmu false/true is enough for you, or 
do you expect to see proper ifdef blocks in all tcg-target.c.inc?

If that's the latter, I would prefer to do it out of the scope of this 
series, as it's not a priority now.

Regards,
Pierrick

Re: [PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system
Posted by Richard Henderson 8 hours ago
On 2/10/26 04:09, Pierrick Bouvier wrote:
> Does a simple #define tcg_use_softmmu false/true is enough for you, or do you expect to 
> see proper ifdef blocks in all tcg-target.c.inc?

Just the #define, so that both paths are always compiled, even if dead-code eliminated.


r~
Re: [PATCH v2 06/12] target/arm/tcg: duplicate tcg/arith_helper.c and tcg/crypto_helper.c between user/system
Posted by Pierrick Bouvier 7 hours ago
On 2/9/26 3:45 PM, Richard Henderson wrote:
> On 2/10/26 04:09, Pierrick Bouvier wrote:
>> Does a simple #define tcg_use_softmmu false/true is enough for you, or do you expect to
>> see proper ifdef blocks in all tcg-target.c.inc?
> 
> Just the #define, so that both paths are always compiled, even if dead-code eliminated.
> 
> 
> r~

Good, thanks.