If MMU_USER_IDX or ENV_OFFSET is already defined, undefine it. The undef will cause a compile error on the ambiguous case where multiple cpu.h's are included yet either of these defs is needed. This shouldn't happen, as the multi-include should only happen in device-land system level code that need CPU defs from multiple arches - e.g. a machine model with two different arch CPUs. Such device code has no bussiness using MMU_USER_IDX or ENV_OFFSET.
ENV_GET_CPU s also multi-guarded to perform no action on second define. This is for multi-arch where target-multi provides a working implementation already Signed-off-by: Peter Crosthwaite <crosthwaite.pe...@gmail.com> --- target-arm/cpu-qom.h | 7 +++++++ target-arm/cpu.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/target-arm/cpu-qom.h b/target-arm/cpu-qom.h index ed5a644..ad742ed 100644 --- a/target-arm/cpu-qom.h +++ b/target-arm/cpu-qom.h @@ -188,9 +188,16 @@ static inline ARMCPU *arm_env_get_cpu(CPUARMState *env) return container_of(env, ARMCPU, env); } +#ifndef ENV_GET_CPU #define ENV_GET_CPU(e) CPU(arm_env_get_cpu(e)) +#endif +#ifndef ENV_OFFSET #define ENV_OFFSET offsetof(ARMCPU, env) +#else +/* Try and cause a compile bug on any (invalid) users of the multiple def */ +#undef ENV_OFFSET +#endif #ifndef CONFIG_USER_ONLY extern const struct VMStateDescription vmstate_arm_cpu; diff --git a/target-arm/cpu.h b/target-arm/cpu.h index e0363a2..53a8051 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -1627,7 +1627,12 @@ typedef enum ARMMMUIdx { ARMMMUIdx_S1NSE1 = 8, } ARMMMUIdx; +#ifdef MMU_USER_IDX +/* Try and cause a compile bug on any (invalid) users of the multiple def */ +#undef MMU_USER_IDX +#else #define MMU_USER_IDX 0 +#endif /* Return the exception level we're running at if this is our mmu_idx */ static inline int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx) -- 1.9.1