Incomplete patch to fix build with top-of-tree GCC
Commit Message
I was wondering if anyone can help me with a patch to fix the glibc
build with the latest GCC. A recent GCC patch to fix middle-end/66110
caused us to get some new strict-aliasing errors. I can do the
mechanical change to use the DIAG_* macros to allow the
non-strict-aliasing but the macros need to be accompanied by a comment
about why it is OK to ignore the warnings and I am not sure how to write
a coherent explanation of that since I am not familiar with the code in
question. Here is the patch I have so far with no comments, does any
one want to help finish it by adding some comments?
Steve Ellcey
sellcey@imgtec.com
2015-05-15 Steve Ellcey <sellcey@imgtec.com>
* inet/rcmd.c (__ivaliduser): Ignore strict-aliasing.
(iruserok_af): Ditto.
* libio/memstream.c (open_memstream): Ditto.
* libio/oldiofdopen.c (_IO_old_fdopen): Ditto.
* libio/oldiofopen.c (_IO_old_fopen): Ditto.
* libio/oldiopopen.c (_IO_old_popen): Ditto.
* resolv/res_hconf.c (_res_hconf_reorder_addrs): Ditto.
Comments
On Fri, 15 May 2015, Steve Ellcey wrote:
> I was wondering if anyone can help me with a patch to fix the glibc
> build with the latest GCC. A recent GCC patch to fix middle-end/66110
> caused us to get some new strict-aliasing errors. I can do the
> mechanical change to use the DIAG_* macros to allow the
> non-strict-aliasing but the macros need to be accompanied by a comment
> about why it is OK to ignore the warnings and I am not sure how to write
> a coherent explanation of that since I am not familiar with the code in
> question. Here is the patch I have so far with no comments, does any
> one want to help finish it by adding some comments?
The first question is: *is* it OK to ignore the warnings? In general I'd
expect -Wstrict-aliasing warnings to indicate -fno-strict-aliasing is
needed, or else the code needs to be fixed to avoid the aliasing issues -
if a warning is generated, optimizations might also miscompile the code.
The section question is: do these warnings indicate GCC bugs? Because if
they do, given it's an issue with current development GCC rather than a
release, getting the bugs fixed in GCC would be better than working around
them in glibc.
@@ -82,6 +82,7 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
#include <stdlib.h>
#include <wchar.h>
#include <sys/uio.h>
+#include <libc-internal.h>
int __ivaliduser (FILE *, u_int32_t, const char *, const char *);
@@ -382,11 +383,17 @@ rresvport_af(alport, family)
switch(family){
case AF_INET:
len = sizeof(struct sockaddr_in);
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
sport = &((struct sockaddr_in *)&ss)->sin_port;
+ DIAG_POP_NEEDS_COMMENT;
break;
case AF_INET6:
len = sizeof(struct sockaddr_in6);
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
sport = &((struct sockaddr_in6 *)&ss)->sin6_port;
+ DIAG_POP_NEEDS_COMMENT;
break;
default:
__set_errno (EAFNOSUPPORT);
@@ -611,14 +618,20 @@ iruserok_af (raddr, superuser, ruser, luser, af)
switch (af){
case AF_INET:
ra.ss_family = AF_INET;
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
memcpy (&(((struct sockaddr_in *)&ra)->sin_addr), raddr,
sizeof(struct in_addr));
+ DIAG_POP_NEEDS_COMMENT;
ralen = sizeof(struct sockaddr_in);
break;
case AF_INET6:
ra.ss_family = AF_INET6;
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
memcpy (&(((struct sockaddr_in6 *)&ra)->sin6_addr), raddr,
sizeof(struct in6_addr));
+ DIAG_POP_NEEDS_COMMENT;
ralen = sizeof(struct sockaddr_in6);
break;
default:
@@ -19,6 +19,7 @@
#include "strfile.h"
#include <stdio.h>
#include <stdlib.h>
+#include <libc-internal.h>
struct _IO_FILE_memstream
@@ -89,7 +90,10 @@ open_memstream (bufloc, sizeloc)
return NULL;
}
_IO_init (&new_f->fp._sf._sbf._f, 0);
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
_IO_JUMPS ((struct _IO_FILE_plus *) &new_f->fp._sf._sbf) = &_IO_mem_jumps;
+ DIAG_POP_NEEDS_COMMENT;
_IO_str_init_static_internal (&new_f->fp._sf, buf, _IO_BUFSIZ, buf);
new_f->fp._sf._sbf._f._flags &= ~_IO_USER_BUF;
new_f->fp._sf._s._allocate_buffer = (_IO_alloc_type) malloc;
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include "libioP.h"
#include <fcntl.h>
+#include <libc-internal.h>
#ifndef _IO_fcntl
# define _IO_fcntl __fcntl
@@ -113,7 +114,10 @@ _IO_old_fdopen (fd, mode)
new_f->fp.file._file._lock = &new_f->lock;
#endif
_IO_old_init (&new_f->fp.file._file, 0);
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
_IO_JUMPS ((struct _IO_FILE_plus *) &new_f->fp) = &_IO_old_file_jumps;
+ DIAG_POP_NEEDS_COMMENT;
_IO_old_file_init ((struct _IO_FILE_plus *) &new_f->fp);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
@@ -30,6 +30,7 @@
#define _IO_USE_OLD_IO_FILE
#include "libioP.h"
#include <stdlib.h>
+#include <libc-internal.h>
_IO_FILE *
@@ -52,7 +53,10 @@ _IO_old_fopen (filename, mode)
new_f->fp.file._file._lock = &new_f->lock;
#endif
_IO_old_init (&new_f->fp.file._file, 0);
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
_IO_JUMPS ((struct _IO_FILE_plus *) &new_f->fp) = &_IO_old_file_jumps;
+ DIAG_POP_NEEDS_COMMENT;
_IO_old_file_init ((struct _IO_FILE_plus *) &new_f->fp);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
@@ -38,6 +38,7 @@
#endif
#include <sys/types.h>
#include <sys/wait.h>
+#include <libc-internal.h>
#ifndef _IO_fork
#ifdef _LIBC
@@ -215,7 +216,10 @@ _IO_old_popen (command, mode)
#endif
fp = &new_f->fpx.file.file._file;
_IO_old_init (fp, 0);
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
_IO_JUMPS ((struct _IO_FILE_plus *) &new_f->fpx.file) = &_IO_old_proc_jumps;
+ DIAG_POP_NEEDS_COMMENT;
_IO_old_file_init ((struct _IO_FILE_plus *) &new_f->fpx.file);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fpx.file.vtable = NULL;
@@ -45,6 +45,7 @@
#include "ifreq.h"
#include "res_hconf.h"
#include <wchar.h>
+#include <libc-internal.h>
#if IS_IN (libc)
# define fgets_unlocked __fgets_unlocked
@@ -443,14 +444,20 @@ _res_hconf_reorder_addrs (struct hostent *hp)
continue;
ifaddrs[new_num_ifs].addrtype = AF_INET;
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
ifaddrs[new_num_ifs].u.ipv4.addr =
((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr;
+ DIAG_POP_NEEDS_COMMENT;
if (__ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0)
continue;
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5, "-Wstrict-aliasing");
ifaddrs[new_num_ifs].u.ipv4.mask =
((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr;
+ DIAG_POP_NEEDS_COMMENT;
/* Now we're committed to this entry. */
++new_num_ifs;