[PATCH v2] build: force gcc to initialize padding bits
Stephen Hemminger
stephen at networkplumber.org
Fri Jan 24 19:26:48 CET 2025
With GCC 15, the compiler has changed the default behavior when
initialization is used for aggregate variables. The new default
is to follow the standard (C23) and not initialize everything by
default. This breaks assumptions in some drivers and can be
lead to other bugs. Use the new zero initialization flag to
force of all fields to zero.
Note: other compilers always initialize to zero in these cases.
Only GCC seems to have decided to start initializing less as
a silly attempt at optimization.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Morten Brørup <mb at smartsharesystems.com>
---
config/meson.build | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/config/meson.build b/config/meson.build
index 6aaad6d8a4..b6b3558e11 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -310,7 +310,7 @@ endif
# enable extra warnings and disable any unwanted warnings
# -Wall is added by default at warning level 1, and -Wextra
# at warning level 2 (DPDK default)
-warning_flags = [
+global_cflags = [
# additional warnings in alphabetical order
'-Wcast-qual',
'-Wdeprecated',
@@ -330,19 +330,22 @@ warning_flags = [
# globally disabled warnings
'-Wno-packed-not-aligned',
'-Wno-missing-field-initializers',
+
+ # guarantee that all non-initialized parts of structure/union are zero
+ '-fzero-init-padding-bits=all',
]
if not dpdk_conf.get('RTE_ARCH_64')
# for 32-bit, don't warn about casting a 32-bit pointer to 64-bit int - it's fine!!
- warning_flags += '-Wno-pointer-to-int-cast'
+ global_cflags += '-Wno-pointer-to-int-cast'
endif
if cc.get_id() == 'intel'
warning_ids = [181, 188, 2203, 2279, 2557, 3179, 3656]
foreach i:warning_ids
- warning_flags += '-diag-disable=@0@'.format(i)
+ global_cflags += '-diag-disable=@0@'.format(i)
endforeach
endif
-foreach arg: warning_flags
+foreach arg: global_cflags
if cc.has_argument(arg)
add_project_arguments(arg, language: 'c')
endif
--
2.45.2
More information about the dev
mailing list