On 12/01/2022 07:56, Peng Fan (OSS) wrote:
From: Peng Fan <[email protected]>

With gcc 5.15, met the following error

hypervisor/arch/arm64/control.c:33:9:
error: ‘memset’ offset [0, 255] is out of the bounds [0, 0] 
[-Werror=array-bounds]
    33 |         memset(&this_cpu_data()->guest_regs, 0, sizeof(union 
registers));
       |         
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I see the same error on gcc-11.1.

My local workaround is to add -ffreestanding to hypervisor/Makefile, as this avoids builtin gcc-magic such as undesired inlining of memsets with constant size.

We already use -ffreestanding for inmates, and I guess we should do it for the hypervisor as well.

  Ralf

cc1: all warnings being treated as errors

Fix this by use a volatile pointer to keep GCC from determining its value

Signed-off-by: Peng Fan <[email protected]>
---
  hypervisor/arch/arm/control.c   | 3 ++-
  hypervisor/arch/arm64/control.c | 3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hypervisor/arch/arm/control.c b/hypervisor/arch/arm/control.c
index 46125e1a..c9c93982 100644
--- a/hypervisor/arch/arm/control.c
+++ b/hypervisor/arch/arm/control.c
@@ -23,9 +23,10 @@
  void arm_cpu_reset(unsigned long pc, bool aarch32)
  {
        u32 sctlr;
+       union registers * volatile guest_regs = &this_cpu_data()->guest_regs;
/* Wipe all banked and usr regs */
-       memset(&this_cpu_data()->guest_regs, 0, sizeof(union registers));
+       memset(guest_regs, 0, sizeof(union registers));
arm_write_banked_reg(SP_usr, 0);
        arm_write_banked_reg(SP_svc, 0);
diff --git a/hypervisor/arch/arm64/control.c b/hypervisor/arch/arm64/control.c
index 5b41b393..2c33c5f7 100644
--- a/hypervisor/arch/arm64/control.c
+++ b/hypervisor/arch/arm64/control.c
@@ -22,6 +22,7 @@ void arm_cpu_reset(unsigned long pc, bool aarch32)
  {
        u64 hcr_el2;
        u64 fpexc32_el2;
+       union registers * volatile guest_regs = &this_cpu_data()->guest_regs;
/* put the cpu in a reset state */
        /* AARCH64_TODO: handle big endian support */
@@ -30,7 +31,7 @@ void arm_cpu_reset(unsigned long pc, bool aarch32)
        arm_write_sysreg(PMCR_EL0, 0);
/* wipe any other state to avoid leaking information accross cells */
-       memset(&this_cpu_data()->guest_regs, 0, sizeof(union registers));
+       memset(guest_regs, 0, sizeof(union registers));
/* AARCH64_TODO: wipe floating point registers */

--
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/b96280bc-3f0c-c959-ed29-e23e7b07108f%40oth-regensburg.de.

Reply via email to