Add a hack to suppress spurious gcc array-bounds warning.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/fw/smm.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/fw/smm.c b/src/fw/smm.c index d90e43a..a0b50b2 100644 --- a/src/fw/smm.c +++ b/src/fw/smm.c @@ -59,6 +59,14 @@ struct smm_layout { struct smm_state cpu; };
+// Hack to supress some gcc array-bounds warnings +static void +memcpy_nowarn(void *d, const void *s, size_t len) +{ + asm("" : "+r"(d), "+r"(s)); + memcpy(d, s, len); +} + void VISIBLE32FLAT handle_smi(u16 cs) { @@ -85,8 +93,8 @@ handle_smi(u16 cs) if (CONFIG_CALL32_SMM) { // Backup current cpu state for SMM trampolining struct smm_layout *newsmm = (void*)BUILD_SMM_ADDR; - memcpy(&newsmm->backup1, &smm->cpu, sizeof(newsmm->backup1)); - memcpy(&newsmm->backup2, &smm->cpu, sizeof(newsmm->backup2)); + memcpy_nowarn(&newsmm->backup1, &smm->cpu, sizeof(newsmm->backup1)); + memcpy_nowarn(&newsmm->backup2, &smm->cpu, sizeof(newsmm->backup2)); HaveSmmCall32 = 1; }
@@ -145,8 +153,8 @@ smm_save_and_copy(void) // save original memory content struct smm_layout *initsmm = (void*)BUILD_SMM_INIT_ADDR; struct smm_layout *smm = (void*)BUILD_SMM_ADDR; - memcpy(&smm->cpu, &initsmm->cpu, sizeof(smm->cpu)); - memcpy(&smm->codeentry, &initsmm->codeentry, sizeof(smm->codeentry)); + memcpy_nowarn(&smm->cpu, &initsmm->cpu, sizeof(smm->cpu)); + memcpy_nowarn(&smm->codeentry, &initsmm->codeentry, sizeof(smm->codeentry));
// Setup code entry point. initsmm->codeentry = SMI_INSN; @@ -168,8 +176,9 @@ smm_relocate_and_restore(void) /* restore original memory content */ struct smm_layout *initsmm = (void*)BUILD_SMM_INIT_ADDR; struct smm_layout *smm = (void*)BUILD_SMM_ADDR; - memcpy(&initsmm->cpu, &smm->cpu, sizeof(initsmm->cpu)); - memcpy(&initsmm->codeentry, &smm->codeentry, sizeof(initsmm->codeentry)); + memcpy_nowarn(&initsmm->cpu, &smm->cpu, sizeof(initsmm->cpu)); + memcpy_nowarn(&initsmm->codeentry, &smm->codeentry + , sizeof(initsmm->codeentry));
// Setup code entry point. smm->codeentry = SMI_INSN;
Dear Kevin,
Am 13.01.22 um 17:19 schrieb Kevin O'Connor:
Add a hack to suppress spurious gcc array-bounds warning.
Wow, thank you for fixing it. Maybe elaborate a little, what version it started with, and reference the GCC bug report [1].
Signed-off-by: Kevin O'Connor kevin@koconnor.net
Tested-by: Paul Menzel (gcc (Debian 11.2.0-14) 11.2.0)
Kind regards,
Paul
On Thu, Jan 13, 2022 at 05:27:11PM +0100, Paul Menzel wrote:
Dear Kevin,
Am 13.01.22 um 17:19 schrieb Kevin O'Connor:
Add a hack to suppress spurious gcc array-bounds warning.
Wow, thank you for fixing it. Maybe elaborate a little, what version it started with, and reference the GCC bug report [1].
Signed-off-by: Kevin O'Connor kevin@koconnor.net
Tested-by: Paul Menzel (gcc (Debian 11.2.0-14) 11.2.0)
Thanks. I pushed this change. I did add a comment to the commit message about gcc version. I didn't include the bug report - http urls tend to age and it's not clear if that bug is directly related.
-Kevin
Kind regards,
Paul