[dpdk-dev] [PATCH v2] mk: report address of packed member as warning

Reshma Pattan reshma.pattan at intel.com
Thu May 2 16:13:16 CEST 2019


gcc 9 on Fedora 30 gives an error
"taking address of packed member may result in an
unaligned pointer value" for -Waddress-of-packed-member.

Report it as warning instead of error to fix the build.

Snippet of build before fix
...lib/librte_eal/linux/eal/eal_memalloc.c: In function ‘alloc_seg_walk’:
...lib/librte_eal/linux/eal/eal_memalloc.c:768:12: error: taking address
of packed member of ‘struct rte_mem_config’ may result in an unaligned
pointer value [-Werror=address-of-packed-member]
  768 |  cur_msl = &mcfg->memsegs[msl_idx];
      |            ^~~~~~~~~~~~~~~~~~~~~~~

Snippet of build after fix
..lib/librte_eal/linux/eal/eal_memory.c: In function ‘remap_segment’:
..lib/librte_eal/linux/eal/eal_memory.c:685:9: warning: taking address
of packed member of ‘struct rte_mem_config’ may result in an unaligned
pointer value [-Waddress-of-packed-member]
  685 |   msl = &mcfg->memsegs[msl_idx];

Signed-off-by: Reshma Pattan <reshma.pattan at intel.com>
---
 mk/toolchain/gcc/rte.vars.mk | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mk/toolchain/gcc/rte.vars.mk b/mk/toolchain/gcc/rte.vars.mk
index d8b99faf6..61032bbbc 100644
--- a/mk/toolchain/gcc/rte.vars.mk
+++ b/mk/toolchain/gcc/rte.vars.mk
@@ -87,5 +87,9 @@ WERROR_FLAGS += -Wimplicit-fallthrough=2
 WERROR_FLAGS += -Wno-format-truncation
 endif
 
+#Report "taking address of packed member may result
+#in an unaligned pointer value" issues as warnings.
+WERROR_FLAGS += -Wno-error=address-of-packed-member
+
 export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
 export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
-- 
2.21.0



More information about the dev mailing list