[PATCH 19/24] exec/user: Do not include 'cpu.h' in 'abitypes.h'

Philippe Mathieu-Daudé posted 24 patches 1 year, 11 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, BALATON Zoltan <balaton@eik.bme.hu>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, David Gibson <david@gibson.dropbear.id.au>, Harsh Prateek Bora <harshpb@linux.ibm.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Peter Xu <peterx@redhat.com>, Laurent Vivier <laurent@vivier.eu>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, Brian Cain <bcain@quicinc.com>, Eduardo Habkost <eduardo@habkost.net>, Song Gao <gaosong@loongson.cn>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Huacai Chen <chenhuacai@kernel.org>, Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>, Stafford Horne <shorne@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bin.meng@windriver.com>, Weiwei Li <liwei1518@gmail.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Max Filippov <jcmvbkbc@gmail.com>
There is a newer version of this series
[PATCH 19/24] exec/user: Do not include 'cpu.h' in 'abitypes.h'
Posted by Philippe Mathieu-Daudé 1 year, 11 months ago
First, "exec/user/abitypes.h" is missing the following
includes (they are included by "cpu.h"):
 - "exec/target_long.h"
 - "exec/cpu-all.h"
 - "exec/tswap.h"
Second, it only requires the definitions from "cpu-param.h",
not the huge "cpu.h".

In order to avoid "cpu.h", pick the minimum required headers.

Assert this user-specific header is only included from user
emulation.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/exec/user/abitypes.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h
index 6178453d94..1a8cd1ac74 100644
--- a/include/exec/user/abitypes.h
+++ b/include/exec/user/abitypes.h
@@ -1,7 +1,14 @@
 #ifndef EXEC_USER_ABITYPES_H
 #define EXEC_USER_ABITYPES_H
 
-#include "cpu.h"
+#ifndef CONFIG_USER_ONLY
+#error Cannot include this header from system emulation
+#endif
+
+#include "cpu-param.h"
+#include "exec/target_long.h"
+#include "exec/cpu-all.h"
+#include "exec/tswap.h"
 
 #ifdef TARGET_ABI32
 #define TARGET_ABI_BITS 32
-- 
2.41.0


Re: [PATCH 19/24] exec/user: Do not include 'cpu.h' in 'abitypes.h'
Posted by Richard Henderson 1 year, 11 months ago
On 12/11/23 13:19, Philippe Mathieu-Daudé wrote:
> First, "exec/user/abitypes.h" is missing the following
> includes (they are included by "cpu.h"):
>   - "exec/target_long.h"
>   - "exec/cpu-all.h"
>   - "exec/tswap.h"
> Second, it only requires the definitions from "cpu-param.h",
> not the huge "cpu.h".
> 
> In order to avoid "cpu.h", pick the minimum required headers.
> 
> Assert this user-specific header is only included from user
> emulation.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Why is cpu-all.h required?


r~

Re: [PATCH 19/24] exec/user: Do not include 'cpu.h' in 'abitypes.h'
Posted by Philippe Mathieu-Daudé 1 year, 11 months ago
On 12/12/23 00:29, Richard Henderson wrote:
> On 12/11/23 13:19, Philippe Mathieu-Daudé wrote:
>> First, "exec/user/abitypes.h" is missing the following
>> includes (they are included by "cpu.h"):
>>   - "exec/target_long.h"
>>   - "exec/cpu-all.h"
>>   - "exec/tswap.h"
>> Second, it only requires the definitions from "cpu-param.h",
>> not the huge "cpu.h".
>>
>> In order to avoid "cpu.h", pick the minimum required headers.
>>
>> Assert this user-specific header is only included from user
>> emulation.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 
> Why is cpu-all.h required?

include/exec/user/abitypes.h:85:12: error: implicit declaration of 
function ‘tswapl’; did you mean ‘tswapal’? 
[-Werror=implicit-function-declaration]
    85 |     return tswapl(v);
       |            ^~~~~~
       |            tswapal

$ git grep -w tswapl include
include/exec/cpu-all.h:40:#define tswapl(s) tswap32(s)
include/exec/cpu-all.h:44:#define tswapl(s) tswap64(s)
include/exec/user/abitypes.h:85:    return tswapl(v);

OK, I'll move tswapl() declarations to exec/user/abitypes.h.

Re: [PATCH 19/24] exec/user: Do not include 'cpu.h' in 'abitypes.h'
Posted by Philippe Mathieu-Daudé 1 year, 11 months ago
On 12/12/23 11:15, Philippe Mathieu-Daudé wrote:
> On 12/12/23 00:29, Richard Henderson wrote:
>> On 12/11/23 13:19, Philippe Mathieu-Daudé wrote:
>>> First, "exec/user/abitypes.h" is missing the following
>>> includes (they are included by "cpu.h"):
>>>   - "exec/target_long.h"
>>>   - "exec/cpu-all.h"
>>>   - "exec/tswap.h"
>>> Second, it only requires the definitions from "cpu-param.h",
>>> not the huge "cpu.h".
>>>
>>> In order to avoid "cpu.h", pick the minimum required headers.
>>>
>>> Assert this user-specific header is only included from user
>>> emulation.
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>
>> Why is cpu-all.h required?
> 
> include/exec/user/abitypes.h:85:12: error: implicit declaration of 
> function ‘tswapl’; did you mean ‘tswapal’? 
> [-Werror=implicit-function-declaration]
>     85 |     return tswapl(v);
>        |            ^~~~~~
>        |            tswapal
> 
> $ git grep -w tswapl include
> include/exec/cpu-all.h:40:#define tswapl(s) tswap32(s)
> include/exec/cpu-all.h:44:#define tswapl(s) tswap64(s)
> include/exec/user/abitypes.h:85:    return tswapl(v);
> 
> OK, I'll move tswapl() declarations to exec/user/abitypes.h.

Better, to a new header.