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

Valentine Barshak gvaxon at gmail.com
Thu May 30 17:38:44 UTC 2019


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

For example:

  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 );
        |            ^~~~~~~~~~~~
  include/ipxe/refcnt.h:95:18: note: in definition of macro ‘ref_get’
     95 |  ref_increment ( refcnt );     \
        |                  ^~~~~~
  include/ipxe/uri.h: In function ‘uri_put’:
  include/ipxe/uri.h:189:12: error: taking address of packed member of ‘struct uri’
  may result in an unaligned pointer value [-Werror=address-of-packed-member]
    189 |  ref_put ( &uri->refcnt );
        |            ^~~~~~~~~~~~
  include/ipxe/refcnt.h:109:18: note: in definition of macro ‘ref_put’
    109 |  ref_decrement ( refcnt );     \
        |                  ^~~~~~

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..ad9644c2 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 warnings for taking address of packed member which
+# may result in an unaligned pointer value. Inhibit the warnings.
+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