Skip to contentSkip to conversation

slirp: Fix build with gcc 9

PATCH Applied Greg Kurz 3 participants 3 messages Mar 1, 2019 – Mar 2, 2019

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

PATCH v2 1/1 slirp: Fix build with gcc 9

Build fails with gcc 9:

CC slirp/ndp_table.o
slirp/ndp_table.c: In function ‘ndp_table_add’:
slirp/ndp_table.c:31:23: error: taking address of packed member of ‘struct ndpentry’ may result in an unaligned pointer value [-Werror=address-of-packed-member]

   31 |         if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
slirp/ndp_table.c: In function ‘ndp_table_search’:
slirp/ndp_table.c:75:23: error: taking address of packed member of ‘struct ndpentry’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
   75 |         if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

The ndpentry structure isn't used to model on-the-wire data or anything else that would care for the struct layout. It doesn't need to be packed actually. Just drop SLIRP_PACKED.

---
v2: - don't check the struct size at compile time

---
 slirp/slirp.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
slirp/slirp.h +1 -1
index 752a4cd8c81c..8068ba1d1e9e 100644
@@ -106,7 +106,7 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
 struct ndpentry {
     unsigned char   eth_addr[ETH_ALEN];     /* sender hardware address */
     struct in6_addr ip_addr;                /* sender IP address       */
-} SLIRP_PACKED;
+};
 
 #define NDP_TABLE_SIZE 16
 
Reviewed-by on v2 1/1
#1 lore raw
Quoted 30 lines · Greg Kurz

Build fails with gcc 9:

CC slirp/ndp_table.o
slirp/ndp_table.c: In function ‘ndp_table_add’:
slirp/ndp_table.c:31:23: error: taking address of packed member of ‘struct ndpentry’ may result in an unaligned pointer value [-Werror=address-of-packed-member]

   31 |         if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
slirp/ndp_table.c: In function ‘ndp_table_search’:
slirp/ndp_table.c:75:23: error: taking address of packed member of ‘struct ndpentry’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
   75 |         if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

The ndpentry structure isn't used to model on-the-wire data or anything else that would care for the struct layout. It doesn't need to be packed actually. Just drop SLIRP_PACKED.

---
v2: - don't check the struct size at compile time

---
 slirp/slirp.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
slirp/slirp.h +0 -0
index 752a4cd8c81c..8068ba1d1e9e 100644

slirp/slirp.h bool arp_table_search(Slirp *slirp, uint32_t ip_addr, · line 111

Quoted 7 lines
slirp/slirp.h +1 -1
@@ -106,7 +106,7 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
 struct ndpentry {
     unsigned char   eth_addr[ETH_ALEN];     /* sender hardware address */
     struct in6_addr ip_addr;                /* sender IP address       */
-} SLIRP_PACKED;
+};
 
 #define NDP_TABLE_SIZE 16

thanks
-- PMM

#2 lore raw

Peter Maydell, le ven. 01 mars 2019 09:49:26 +0000, a ecrit:

Quoted 37 lines · Greg Kurz
Quoted 36 lines

Build fails with gcc 9:

CC slirp/ndp_table.o
slirp/ndp_table.c: In function ‘ndp_table_add’:
slirp/ndp_table.c:31:23: error: taking address of packed member of ‘struct ndpentry’ may result in an unaligned pointer value [-Werror=address-of-packed-member]

   31 |         if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
slirp/ndp_table.c: In function ‘ndp_table_search’:
slirp/ndp_table.c:75:23: error: taking address of packed member of ‘struct ndpentry’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
   75 |         if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

The ndpentry structure isn't used to model on-the-wire data or anything else that would care for the struct layout. It doesn't need to be packed actually. Just drop SLIRP_PACKED.

---
v2: - don't check the struct size at compile time

---
 slirp/slirp.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
slirp/slirp.h +1 -1
index 752a4cd8c81c..8068ba1d1e9e 100644
@@ -106,7 +106,7 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
 struct ndpentry {
     unsigned char   eth_addr[ETH_ALEN];     /* sender hardware address */
     struct in6_addr ip_addr;                /* sender IP address       */
-} SLIRP_PACKED;
+};
 
Quoted 3 lines

slirp/slirp.h bool arp_table_search(Slirp *slirp, uint32_t ip_addr, · line 111

Quoted 1 line
slirp/slirp.h +0 -0
 #define NDP_TABLE_SIZE 16

Applied to my tree, thanks!

Samuel