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

Geert Stappers stappers at stappers.nl
Sun Jun 9 13:55:13 UTC 2019


On Sun, Jun 09, 2019 at 01:30:12PM +0300, Valentine Barshak wrote:
> 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.

However is  refcnt also an structure,
but that structure is not packed.


> This disables the warning to workaround the compilation issue.
 
[ ... patch saying "Compiler, don't warn me about this , I know better" ... ]


If I had GCC 9.1  I would test this:

--- a/src/include/ipxe/refcnt.h
+++ b/src/include/ipxe/refcnt.h
@@ -41,7 +41,7 @@ struct refcnt {
         * first element of your reference-counted struct.
         */
        void ( * free ) ( struct refcnt *refcnt );
-};
+} __attribute__ (( packed ));
 
 /**
  * Initialise a reference counter


And also test with

--- a/src/include/ipxe/uri.h
+++ b/src/include/ipxe/uri.h
@@ -70,7 +70,7 @@ struct uri {
        const char *fragment;
        /** Form parameters */
        struct parameters *params;
-} __attribute__ (( packed ));
+};
 
 /**
  * Access URI field


I leave this up to more knowledgable people.

It is "Patch has been seen" is what I wanted to tell    :-)




Groeten
Geert Stappers
-- 
Leven en laten leven



More information about the ipxe-devel mailing list