On 3/18/25 15:11, Richard Henderson wrote:
On 3/17/25 21:51, Pierrick Bouvier wrote:
Including "cpu.h" from code that is not compiled per target is ambiguous
by definition. Thus we introduce a conditional include, to allow every
architecture to set this, to point to the correct definition.

hw/X or target/X will now include directly "target/X/cpu.h", and
"target/X/cpu.h" will define CPU_INCLUDE to itself.
We already do this change for arm cpu as part of this commit.

Signed-off-by: Pierrick Bouvier <pierrick.bouv...@linaro.org>
---
   include/exec/cpu-all.h | 4 ++++
   target/arm/cpu.h       | 2 ++
   2 files changed, 6 insertions(+)

diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 7c6c47c43ed..1a756c0cfb3 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -46,7 +46,11 @@
CPUArchState *cpu_copy(CPUArchState *env); +#ifdef CPU_INCLUDE
+#include CPU_INCLUDE
+#else
   #include "cpu.h"
+#endif
#ifdef CONFIG_USER_ONLY diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index a8177c6c2e8..7aeb012428c 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -31,6 +31,8 @@
   #include "target/arm/multiprocessing.h"
   #include "target/arm/gtimer.h"
+#define CPU_INCLUDE "target/arm/cpu.h"
+
   #ifdef TARGET_AARCH64
   #define KVM_HAVE_MCE_INJECTION 1
   #endif

This doesn't make any sense to me.  CPU_INCLUDE is defined within the very file 
that
you're trying to include by avoiding "cpu.h".


Every target/X/cpu.h includes cpu-all.h, which includes "cpu.h" itself, relying on per target include path set by build system. Now we have common code, there is no "per target include path".

The other solutions are:
- build hw common libraries with per target include path, but I thought it was a good way to cleanup this, and not rely on this hidden dependency on the build system - remove cpu.h inclusion from cpu-all.h, but it requires more modifications in other places.

I'm not sure which is the more desirable, compare to having this weird CPU_INCLUDE trick.


r~


Reply via email to