Skip to contentSkip to conversation

SLIRP warning messages displayed while compiling

Qemu-devel Programmingkid 5 participants 11 messages Aug 10, 2017 – Aug 14, 2017

lore
Share & tools
lore
#0 lore raw

Host: Mac OS 10.12.5
Compiler: Apple LLVM version 8.1.0 (clang-802.0.42)
Command used: ./configure --target-list=ppc-softmmu,i386-softmmu && make -j 4

While compiling I saw these error messages:

slirp/ip6_icmp.c:79:32: warning: taking address of packed member 'ip_src' of class or

      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) ||
                               ^~~~~~~~~~
/usr/include/netinet6/in6.h:299:36: note: expanded from macro 'IN6_IS_ADDR_MULTICAST'
#define IN6_IS_ADDR_MULTICAST(a)        ((a)->s6_addr[0] == 0xff)
                                          ^
slirp/ip6_icmp.c:80:38: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)) {
                                     ^~~~~~~~~~
/usr/include/netinet6/in6.h:238:42: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        ((*(const __uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
                                                ^
slirp/ip6_icmp.c:80:38: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)) {
                                     ^~~~~~~~~~
/usr/include/netinet6/in6.h:239:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
                                               ^
slirp/ip6_icmp.c:80:38: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)) {
                                     ^~~~~~~~~~
/usr/include/netinet6/in6.h:240:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
                                               ^
slirp/ip6_icmp.c:80:38: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)) {
                                     ^~~~~~~~~~
/usr/include/netinet6/in6.h:241:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
                                               ^
slirp/ip6_icmp.c:275:34: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    if (IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)) {
                                 ^~~~~~~~~~
/usr/include/netinet6/in6.h:238:42: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        ((*(const __uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
                                                ^
slirp/ip6_icmp.c:275:34: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    if (IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)) {
                                 ^~~~~~~~~~
/usr/include/netinet6/in6.h:239:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
                                               ^
slirp/ip6_icmp.c:275:34: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    if (IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)) {
                                 ^~~~~~~~~~
/usr/include/netinet6/in6.h:240:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
                                               ^
slirp/ip6_icmp.c:275:34: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    if (IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)) {
                                 ^~~~~~~~~~
/usr/include/netinet6/in6.h:241:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
                                               ^
slirp/ip6_icmp.c:294:50: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    ricmp->icmp6_nna.S = !IN6_IS_ADDR_MULTICAST(&rip->ip_dst);
                                                 ^~~~~~~~~~~
/usr/include/netinet6/in6.h:299:36: note: expanded from macro 'IN6_IS_ADDR_MULTICAST'
#define IN6_IS_ADDR_MULTICAST(a)        ((a)->s6_addr[0] == 0xff)
                                          ^
slirp/ip6_icmp.c:351:44: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                && !IN6_IS_ADDR_MULTICAST(&icmp->icmp6_nns.target)
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netinet6/in6.h:299:36: note: expanded from macro 'IN6_IS_ADDR_MULTICAST'
#define IN6_IS_ADDR_MULTICAST(a)        ((a)->s6_addr[0] == 0xff)
                                          ^
slirp/ip6_icmp.c:353:47: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                && (!IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)
                                              ^~~~~~~~~~
/usr/include/netinet6/in6.h:238:42: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        ((*(const __uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
                                                ^
slirp/ip6_icmp.c:353:47: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                && (!IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)
                                              ^~~~~~~~~~
/usr/include/netinet6/in6.h:239:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
                                               ^
slirp/ip6_icmp.c:353:47: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                && (!IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)
                                              ^~~~~~~~~~
/usr/include/netinet6/in6.h:240:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
                                               ^
slirp/ip6_icmp.c:353:47: warning: taking address of packed member 'ip_src' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                && (!IN6_IS_ADDR_UNSPECIFIED(&ip->ip_src)
                                              ^~~~~~~~~~
/usr/include/netinet6/in6.h:241:41: note: expanded from macro 'IN6_IS_ADDR_UNSPECIFIED'
        (*(const __uint32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
                                               ^
slirp/ip6_icmp.c:354:53: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                    || in6_solicitednode_multicast(&ip->ip_dst))) {
                                                    ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:91:20: note: 
      expanded from macro 'in6_solicitednode_multicast'
    (in6_equal_net(a, &(struct in6_addr)SOLICITED_NODE_PREFIX, 104))
                   ^
slirp/ip6_icmp.c:355:33: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            if (in6_equal_host(&icmp->icmp6_nns.target)) {
                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:23: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
     ~~~~~~~~~~~~~~~~~^~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:76:21: note: 
      expanded from macro 'in6_equal_router'
    ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len)\
                    ^
slirp/ip6_icmp.c:355:33: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            if (in6_equal_host(&icmp->icmp6_nns.target)) {
                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:23: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
     ~~~~~~~~~~~~~~~~~^~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:77:25: note: 
      expanded from macro 'in6_equal_router'
      && in6_equal_mach(a, &slirp->vhost_addr6, slirp->vprefix_len))\
                        ^
slirp/ip6_icmp.c:355:33: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            if (in6_equal_host(&icmp->icmp6_nns.target)) {
                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:23: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
     ~~~~~~~~~~~~~~~~~^~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:78:21: note: 
      expanded from macro 'in6_equal_router'
  || (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64)\
                    ^
slirp/ip6_icmp.c:355:33: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            if (in6_equal_host(&icmp->icmp6_nns.target)) {
                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:23: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
     ~~~~~~~~~~~~~~~~~^~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:79:25: note: 
      expanded from macro 'in6_equal_router'
      && in6_equal_mach(a, &slirp->vhost_addr6, 64)))
                        ^
slirp/ip6_icmp.c:355:33: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            if (in6_equal_host(&icmp->icmp6_nns.target)) {
                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:43: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                            ~~~~~~~~~~~~~~^~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:82:21: note: 
      expanded from macro 'in6_equal_dns'
    ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len)\
                    ^
slirp/ip6_icmp.c:355:33: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            if (in6_equal_host(&icmp->icmp6_nns.target)) {
                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:43: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                            ~~~~~~~~~~~~~~^~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:83:25: note: 
      expanded from macro 'in6_equal_dns'
      && in6_equal_mach(a, &slirp->vnameserver_addr6, slirp->vprefix_len))\
                        ^
slirp/ip6_icmp.c:355:33: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            if (in6_equal_host(&icmp->icmp6_nns.target)) {
                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:43: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                            ~~~~~~~~~~~~~~^~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:84:21: note: 
      expanded from macro 'in6_equal_dns'
  || (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64)\
                    ^
slirp/ip6_icmp.c:355:33: warning: taking address of packed member 'target' of class or
      structure 'ndp_ns' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
            if (in6_equal_host(&icmp->icmp6_nns.target)) {
                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:43: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                            ~~~~~~~~~~~~~~^~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:85:25: note: 
      expanded from macro 'in6_equal_dns'
      && in6_equal_mach(a, &slirp->vnameserver_addr6, 64)))
                        ^
slirp/ip6_icmp.c:368:44: warning: taking address of packed member 'target' of class or
      structure 'ndp_na' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                && !IN6_IS_ADDR_MULTICAST(&icmp->icmp6_nna.target)
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netinet6/in6.h:299:36: note: expanded from macro 'IN6_IS_ADDR_MULTICAST'
#define IN6_IS_ADDR_MULTICAST(a)        ((a)->s6_addr[0] == 0xff)
                                          ^
slirp/ip6_icmp.c:369:45: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                && (!IN6_IS_ADDR_MULTICAST(&ip->ip_dst)
                                            ^~~~~~~~~~
/usr/include/netinet6/in6.h:299:36: note: expanded from macro 'IN6_IS_ADDR_MULTICAST'
#define IN6_IS_ADDR_MULTICAST(a)        ((a)->s6_addr[0] == 0xff)
                                          ^
slirp/ip6_icmp.c:414:29: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        if (in6_equal_host(&ip->ip_dst)) {
                            ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:23: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                      ^
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:76:21: note: 
      expanded from macro 'in6_equal_router'
    ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len)\
                    ^
slirp/ip6_icmp.c:414:29: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        if (in6_equal_host(&ip->ip_dst)) {
                            ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:23: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                      ^
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:77:25: note: 
      expanded from macro 'in6_equal_router'
      && in6_equal_mach(a, &slirp->vhost_addr6, slirp->vprefix_len))\
                        ^
slirp/ip6_icmp.c:414:29: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        if (in6_equal_host(&ip->ip_dst)) {
                            ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:23: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                      ^
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:78:21: note: 
      expanded from macro 'in6_equal_router'
  || (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64)\
                    ^
slirp/ip6_icmp.c:414:29: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        if (in6_equal_host(&ip->ip_dst)) {
                            ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:23: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                      ^
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:79:25: note: 
      expanded from macro 'in6_equal_router'
      && in6_equal_mach(a, &slirp->vhost_addr6, 64)))
                        ^
slirp/ip6_icmp.c:414:29: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        if (in6_equal_host(&ip->ip_dst)) {
                            ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:43: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                                          ^
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:82:21: note: 
      expanded from macro 'in6_equal_dns'
    ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len)\
                    ^
slirp/ip6_icmp.c:414:29: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        if (in6_equal_host(&ip->ip_dst)) {
                            ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:43: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                                          ^
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:83:25: note: 
      expanded from macro 'in6_equal_dns'
      && in6_equal_mach(a, &slirp->vnameserver_addr6, slirp->vprefix_len))\
                        ^
slirp/ip6_icmp.c:414:29: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        if (in6_equal_host(&ip->ip_dst)) {
                            ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:43: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                                          ^
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:84:21: note: 
      expanded from macro 'in6_equal_dns'
  || (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64)\
                    ^
slirp/ip6_icmp.c:414:29: warning: taking address of packed member 'ip_dst' of class or
      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
        if (in6_equal_host(&ip->ip_dst)) {
                            ^~~~~~~~~~
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:88:43: note: 
      expanded from macro 'in6_equal_host'
    (in6_equal_router(a) || in6_equal_dns(a))
                                          ^
/Users/john/Documents/Development/Projects/Qemu/qemu-git/slirp/ip6.h:85:25: note: 
      expanded from macro 'in6_equal_dns'
      && in6_equal_mach(a, &slirp->vnameserver_addr6, 64)))
                        ^

slirp/ip_input.c:159:43: warning: taking address of packed member 'ip_link' of class or

      structure 'ipq' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                for (l = slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link;
                                                        ^~~~~~~~~~~~~~~~~~
slirp/ip_input.c:441:18: warning: taking address of packed member 'ip_link' of class or
      structure 'ipq' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    while (l != &slirp->ipq.ip_link) {
                 ^~~~~~~~~~~~~~~~~~

2 warnings generated.
34 warnings generated.

slirp/slirp.c:403:19: warning: taking address of packed member 'ip_link' of class or
structure 'ipq' may result in an unaligned pointer value [-Waddress-of-packed-member]
(&slirp->ipq.ip_link != slirp->ipq.ip_link.next));

#1 lore raw

Hello,

Quoted 8 lines · Programmingkid, on jeu. 10 août 2017 16:44:19 -0400, wrote:

While compiling I saw these error messages:

slirp/ip6_icmp.c:79:32: warning: taking address of packed member 'ip_src' of class or

      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) ||
                               ^~~~~~~~~~
Quoted 5 lines

slirp/ip_input.c:159:43: warning: taking address of packed member 'ip_link' of class or

      structure 'ipq' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                for (l = slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link;
                                                        ^~~~~~~~~~~~~~~~~~

Well, if the compiler was counting well, it would notice that the structure are made so that even with packing, fields always get aligned on proper bounds.

(and no, we don't want to remove QEMU_PACKED from struct ip6, at least, since it *has* to be packed to match the ipv6 headers).

Samuel

#2 lore raw
Quoted 17 lines · Samuel Thibault

Hello,

Quoted 8 lines · Programmingkid, on jeu. 10 août 2017 16:44:19 -0400, wrote:

While compiling I saw these error messages:

slirp/ip6_icmp.c:79:32: warning: taking address of packed member 'ip_src' of class or

      structure 'ip6' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
    if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) ||
                               ^~~~~~~~~~
Quoted 5 lines

slirp/ip_input.c:159:43: warning: taking address of packed member 'ip_link' of class or

      structure 'ipq' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                for (l = slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link;
                                                        ^~~~~~~~~~~~~~~~~~
Quoted 3 lines

Well, if the compiler was counting well, it would notice that the structure are made so that even with packing, fields always get aligned on proper bounds.

The utility of the warning is that it means you get told about stuff that might break on other architectures. Eg x86's alignment restrictions are practically nonexistent but sparc is much more restrictive. It's better to get warnings on all hosts so these things can be cleaned up rather than have them only be warnings on the less commonly used hosts where nobody will notice them.

(GCC ideally ought to warn about this but doesn't:
that's a bug/missing feature in gcc.)

That said, some of these are a bit odd -- comparing a pointer value should be fine, as should using a pointer to a packed struct field inside a function -- it's only when that pointer is cast to a non-packed-pointer-type (including by passing it to another function) that the compiler loses the information that the pointer is potentially unaligned.

thanks
-- PMM

#3 lore raw
Quoted 2 lines · Peter Maydell, on sam. 12 août 2017 11:53:20 +0100, wrote:

The utility of the warning is that it means you get told about stuff that might break on other architectures.

Sure, I understand that. But here all fields are aligned on their size inside the packed structure. So there can't be alignment issues, and the compiler should be able to determine that.

Samuel

#4 lore raw
Quoted 7 lines · Samuel Thibault
Quoted 2 lines · Peter Maydell, on sam. 12 août 2017 11:53:20 +0100, wrote:

The utility of the warning is that it means you get told about stuff that might break on other architectures.

Sure, I understand that. But here all fields are aligned on their size inside the packed structure. So there can't be alignment issues, and the compiler should be able to determine that.

Alignment is architecture-dependent, and the compiler can't know the alignment requirements for every architecture. There's no rule in C that says that uint16_t only needs 2 byte alignment and not 4 on some hosts.

(Also I just noticed 'struct ip6' uses bitfields:
that's badly non-portable if it's trying to match an on-the-wire layout.)

thanks
-- PMM

#5 lore raw
Quoted 5 lines · Peter Maydell, on sam. 12 août 2017 12:18:16 +0100, wrote:
Quoted 4 lines · Samuel Thibault
Quoted 2 lines · Peter Maydell, on sam. 12 août 2017 11:53:20 +0100, wrote:

The utility of the warning is that it means you get told about stuff that might break on other architectures.

Quoted 7 lines
Quoted 3 lines

Sure, I understand that. But here all fields are aligned on their size inside the packed structure. So there can't be alignment issues, and the compiler should be able to determine that.

Alignment is architecture-dependent, and the compiler can't know the alignment requirements for every architecture.

Sure.

Quoted 2 lines

There's no rule in C that says that uint16_t only needs 2 byte alignment and not 4 on some hosts.

Are there really systems where that happens? Such systems would have to pad uint16_t arrays then, really?

Quoted 3 lines

(Also I just noticed 'struct ip6' uses bitfields:
that's badly non-portable if it's trying to
match an on-the-wire layout.)

struct ip has been doing so for so long too.

I'm not saying the code is perfectly portable, I'm just saying it's portable enough for being both practical and readable.

Samuel

#6 lore raw
Quoted 6 lines · Samuel Thibault
Quoted 4 lines

Alignment is architecture-dependent, and the compiler can't know the alignment requirements for every architecture.

Sure.

True, but we can at least guess alignments that don't require padding, and then be told by the compiler if our guess was wrong when porting to a new system, and update our guess accordingly with more ifdefs (struct ip6 is already using ifdef HOST_WORDS_BIGENDIAN for that reason).

Quoted 6 lines
Quoted 3 lines

There's no rule in C that says that uint16_t only needs 2 byte alignment and not 4 on some hosts.

Are there really systems where that happens? Such systems would have to pad uint16_t arrays then, really?

uint16_least_t occupies only 2 bytes, but C and POSIX allow systems where uint16_t is larger than 16 bits (most likely, 32 bits). I don't personally know of such a system; and it's most-likely to be a non-POSIX system (perhaps one where sizeof(int) == 1 because the smallest addressable integer is 32 bits).

Quoted 9 lines
Quoted 4 lines

(Also I just noticed 'struct ip6' uses bitfields:
that's badly non-portable if it's trying to
match an on-the-wire layout.)

struct ip has been doing so for so long too.

I'm not saying the code is perfectly portable, I'm just saying it's portable enough for being both practical and readable.

Here's an idea: Instead of using struct ip6 { ... } QEMU_PACKED, use

struct ip6 {
...
};
QEMU_BUG_ON(sizeof(struct ip6) != 32);

so that the compiler explicitly chokes if it introduced any padding, and then we know all our accesses are naturally aligned which shuts up the warning.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#7 lore raw
Quoted 6 lines · Eric Blake, on sam. 12 août 2017 06:41:30 -0500, wrote:

Here's an idea: Instead of using struct ip6 { ... } QEMU_PACKED, use

struct ip6 {
...
};
QEMU_BUG_ON(sizeof(struct ip6) != 32);

That's an interesting way indeed. I however wonder whether there may be not-so-uncommon systems where the compiler aligns some fields just for performance or such.

Samuel

#8 lore raw
Quoted 11 lines · Samuel Thibault
Quoted 6 lines · Eric Blake, on sam. 12 août 2017 06:41:30 -0500, wrote:

Here's an idea: Instead of using struct ip6 { ... } QEMU_PACKED, use

struct ip6 {
...
};
QEMU_BUG_ON(sizeof(struct ip6) != 32);

That's an interesting way indeed. I however wonder whether there may be not-so-uncommon systems where the compiler aligns some fields just for performance or such.

If it does, the BUG_ON will flag it, and we'll deal with it as needed for that platform, perhaps by adding:

...
}
#ifdef WEIRD_PLATFORM
QEMU_PACKED
#endif
;
QEMU_BUG_ON(...);

But as long as the BUG_ON doesn't flag anything, we can use the struct as-is.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#9 lore raw
In reply to Eric Blake

Hi Eric,

Quoted 10 lines · Eric Blake

Here's an idea: Instead of using struct ip6 { ... } QEMU_PACKED, use

struct ip6 {
...
};
QEMU_BUG_ON(sizeof(struct ip6) != 32);

so that the compiler explicitly chokes if it introduced any padding, and then we know all our accesses are naturally aligned which shuts up the warning.

Following your suggestion I tried:

#define QEMU_BUG_STRUCT_UNALIGNED(s) \
        QEMU_BUILD_BUG_ON(sizeof(s) != sizeof(s QEMU_PACKED))

QEMU_BUG_STRUCT_UNALIGNED(struct ip6);

but this gives:

qemu/slirp/ip6.h:157:1: warning: 'packed' attribute ignored when parsing type [-Wignored-attributes] QEMU_BUG_STRUCT_UNALIGNED(struct ip6);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qemu/slirp/ip6.h:155:49: note: expanded from macro 'QEMU_BUG_STRUCT_UNALIGNED'

        QEMU_BUILD_BUG_ON(sizeof(s) != sizeof(s QEMU_PACKED))
                                                ^~~~~~~~~~~
qemu/include/qemu/compiler.h:40:37: note: expanded from macro 'QEMU_PACKED'
# define QEMU_PACKED __attribute__((packed))
                                    ^~~~~~
1 warning generated.
#10 lore raw
Quoted 10 lines · Philippe Mathieu-Daudé

Hi Eric,

Quoted 7 lines · Eric Blake

Here's an idea: Instead of using struct ip6 { ... } QEMU_PACKED, use

struct ip6 {
...
};
QEMU_BUG_ON(sizeof(struct ip6) != 32);

Quoted 8 lines
Quoted 3 lines

so that the compiler explicitly chokes if it introduced any padding, and then we know all our accesses are naturally aligned which shuts up the warning.

Following your suggestion I tried:

#define QEMU_BUG_STRUCT_UNALIGNED(s) \
        QEMU_BUILD_BUG_ON(sizeof(s) != sizeof(s QEMU_PACKED))

I don't think gcc likes that (you can't just add attribute packed in arbitrary places, but only where the type is declared).

Quoted 9 lines

QEMU_BUG_STRUCT_UNALIGNED(struct ip6);

but this gives:

qemu/slirp/ip6.h:157:1: warning: 'packed' attribute ignored when parsing type [-Wignored-attributes]
QEMU_BUG_STRUCT_UNALIGNED(struct ip6); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Indeed, there's the evidence that your attempt at a shortcut didn't work. My proposal was to put in a hard-coded number, rather than try to make the compiler compute two variants of the type and check that they occupy the same space (although I agree with your idea that if you CAN get the compiler to do that, it's nicer than hand-computing the number to compare against).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org