From patchwork Fri Feb 12 13:15:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 10837 Received: (qmail 44569 invoked by alias); 12 Feb 2016 13:15:33 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 38882 invoked by uid 89); 12 Feb 2016 13:15:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2446, 1547, 154, 7, 1527 X-HELO: mx1.redhat.com To: GNU C Library From: Florian Weimer Subject: [PATCH] bits/socket.h: Define struct sockaddr with may_alias attribute [BZ #19622] X-Enigmail-Draft-Status: N1110 Message-ID: <56BDDAE2.70308@redhat.com> Date: Fri, 12 Feb 2016 14:15:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 It is quite common to use struct sockaddr * as an opaque, void *-like type for socket addresses. The POSIX API encourages to some degree. Marek Polacek suggested to add the may_alias attribute to the definition of struct sockaddr. Support for that was introduced in GCC 4.0, so I added a conditional to cdefs.h. Florian 2016-02-12 Florian Weimer [BZ #19622] * misc/sys/cdefs.h (__attribute_may_alias__): Define macro. * bits/socket.h (struct sockaddr): Use it. * sysdeps/mach/hurd/bits/socket.h (struct sockaddr): Likewise. * sysdeps/unix/sysv/linux/bits/socket.h (struct sockaddr): Likewise. diff --git a/bits/socket.h b/bits/socket.h index ab9f242..e090c65 100644 --- a/bits/socket.h +++ b/bits/socket.h @@ -148,7 +148,7 @@ struct sockaddr { __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */ char sa_data[14]; /* Address data. */ - }; + } __attribute_may_alias__; /* Structure large enough to hold any socket address (with the historical diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 7fd4154..aee6ae3 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -407,6 +407,12 @@ [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })] #endif +#if __GNUC_PREREQ (4,0) +# define __attribute_may_alias__ __attribute__ ((__may_alias__)) +#else +# define __attribute_may_alias__ +#endif + #include #if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h index 02c5dac..d0dc1a3 100644 --- a/sysdeps/mach/hurd/bits/socket.h +++ b/sysdeps/mach/hurd/bits/socket.h @@ -152,7 +152,7 @@ struct sockaddr { __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */ char sa_data[14]; /* Address data. */ - }; + } __attribute_may_alias__; /* Structure large enough to hold any socket address (with the historical diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h index 0581c79..420c0d3 100644 --- a/sysdeps/unix/sysv/linux/bits/socket.h +++ b/sysdeps/unix/sysv/linux/bits/socket.h @@ -154,7 +154,7 @@ struct sockaddr { __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */ char sa_data[14]; /* Address data. */ - }; + } __attribute_may_alias__; /* Structure large enough to hold any socket address (with the historical