[ipxe-devel] [PATCH v2 2/2] [build] Workaround compilation error with gcc 9.1

Valentine Barshak gvaxon at gmail.com
Sun Jun 9 10:30:12 UTC 2019


Compiling with gcc 9.1 generates lots of "taking address of packed
member of ... may result in an unaligned pointer value" warnings:

  include/ipxe/uri.h: In function ‘uri_get’:
  include/ipxe/uri.h:178:12: error: taking address of packed member of ‘struct uri’
  may result in an unaligned pointer value [-Werror=address-of-packed-member]
    178 |  ref_get ( &uri->refcnt );
        |            ^~~~~~~~~~~~

The problem is that gcc does not check the alignment, but shows
lots of false positive warnings. For example, 'refcnt' is the first
member of the 'uri' structure, so its alignment is not affected
by the 'packed' attribute.

This disables the warning to workaround the compilation issue.

Signed-off-by: Valentine Barshak <gvaxon at gmail.com>
---
 src/Makefile.housekeeping | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping
index f8334921..3634c4b2 100644
--- a/src/Makefile.housekeeping
+++ b/src/Makefile.housekeeping
@@ -185,6 +185,13 @@ WNST_TEST = $(CC) -Wstringop-truncation -x c -c /dev/null -o /dev/null \
 		  >/dev/null 2>&1
 WNST_FLAGS := $(shell $(WNST_TEST) && $(ECHO) '-Wno-stringop-truncation')
 WORKAROUND_CFLAGS += $(WNST_FLAGS)
+
+# gcc 9.1 generates false positive warnings for taking address of a packed
+# structure member which may result in an unaligned pointer. Turn them off.
+WNST_TEST = $(CC) -Wno-address-of-packed-member -x c -c /dev/null -o /dev/null \
+		  >/dev/null 2>&1
+WNST_FLAGS := $(shell $(WNST_TEST) && $(ECHO) '-Wno-address-of-packed-member')
+WORKAROUND_CFLAGS += $(WNST_FLAGS)
 endif
 
 # Some versions of gas choke on division operators, treating them as
-- 
2.21.0




More information about the ipxe-devel mailing list