[SeaBIOS] [PATCH] smm: Suppress gcc array-bounds warnings

Kevin O'Connor posted 1 patch 10 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/seabios tags/patchew/20220113161937.1412377-1-kevin@koconnor.net
src/fw/smm.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
[SeaBIOS] [PATCH] smm: Suppress gcc array-bounds warnings
Posted by Kevin O'Connor 10 months, 3 weeks ago
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;
-- 
2.31.1

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH] smm: Suppress gcc array-bounds warnings
Posted by Paul Menzel 10 months, 3 weeks ago
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


[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org