This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] bits/socket.h: Define struct sockaddr with may_alias attribute [BZ #19622]


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  <fweimer@redhat.com>

	[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 <bits/wordsize.h>
 
 #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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]