On Tue, 20 Oct 2026 08:49:44 +0000
Morten Brørup <[email protected]> wrote:

> On architectures where rte_memcpy() is defined as memcpy(),
> GCC warns about source/destination overflow when copying more than the
> source/destination size, even for code paths that are not taken in cases
> where the sizes are smaller.
> 
> The relevant compiler warnings were disabled for GCC at the two
> occurrences, and comments describing the reason were added.
> 
> NB:
> It has not been investigated which GCC versions are affected.
> GCC version 10 and up was chosen because that was what the previous
> versions of x86 rte_memcpy() disabled sligthly similar warnings for.
> 
> PS:
> The alternative was to obfuscate the code, but that would make the code
> less readable, and might have unintended effects on architectures and
> compilers not suffering by this issue.
> 
> Bugzilla ID: 2061
> Fixes: ee0822a0ef41 ("stack: introduce pile")
> 
> The pile was introduce with this DPDK release, so no need to backport.

Rather than playing "what a bug with pragmas" a better solution is to disable
the warning globally if optimization is disabled.

From d79d5a1c4d7b7d43e31b26f5d5e218155f699ac0 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <[email protected]>
Date: Tue, 20 Oct 2026 07:26:42 -0700
Subject: [PATCH] build: disable GCC string op warnings when unoptimized

Without optimization GCC's -Wstringop-overflow and -Wstringop-overread
are flow-insensitive: they check a memcpy() against the object size
even on paths that are dead for the inlined arguments. This breaks
debug builds of app/test with -Werror on lib/stack/rte_stack_pile.h,
and has required local pragma workarounds elsewhere.

Disable both warnings when optimization is 0. They stay enabled for
optimized builds, where the analysis is flow-sensitive.

Bugzilla ID: 2061

Reported-by: Ali Alnubani <[email protected]>
Signed-off-by: Stephen Hemminger <[email protected]>
---
 config/meson.build | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/config/meson.build b/config/meson.build
index 745097e8aa..ac90b9d4fa 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -378,6 +378,12 @@ if cc.has_argument('-Wno-comma')
     no_comma_cflag = '-Wno-comma'
 endif
 
+# GCC's string/memory access warnings are flow-insensitive without
+# optimization and produce false positives on dead paths of inlined code.
+if get_option('optimization') == '0' and cc.get_id() == 'gcc'
+    global_cflags += ['-Wno-stringop-overflow', '-Wno-stringop-overread']
++endif
+
 foreach arg: global_cflags
     if cc.has_argument(arg)
         add_project_arguments(arg, language: 'c')
-- 
2.53.0

Reply via email to