diff mbox series

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

Message ID 20231211212003.21686-20-philmd@linaro.org
State New
Headers show
Series exec: Rework of various headers (user focused) | expand

Commit Message

Philippe Mathieu-Daudé Dec. 11, 2023, 9:19 p.m. UTC
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(-)

Comments

Richard Henderson Dec. 11, 2023, 11:29 p.m. UTC | #1
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~
Philippe Mathieu-Daudé Dec. 12, 2023, 10:15 a.m. UTC | #2
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.
Philippe Mathieu-Daudé Dec. 12, 2023, 10:45 a.m. UTC | #3
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.
diff mbox series

Patch

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