Fix strict-aliasing warning in resolv/res_hconf.c

Message ID 1432682074.28747.28.camel@ubuntu-sellcey
State Superseded
Headers

Commit Message

Steve Ellcey May 26, 2015, 11:14 p.m. UTC
  On Tue, 2015-05-26 at 14:56 -0700, Roland McGrath wrote:
> As I said before, adding the #include in that public header is not right.

In that case the two solutions I see are to compile res_hconf.c with
-fno-strict-aliasing or to put DIAG_PUSH_NEEDS_COMMENT, etc. macros
around the two casts in res_hconf.c to turn off the strict aliasing
warnings.  Using -fno-strict-aliasing seems safer as I do not know
(based on my own knowledge) that the casts in question do not cause any
problems when compiled with strict aliasing.  How about this patch?

Steve Ellcey
sellcey@imgtec.com



2015-05-26  Steve Ellcey  <sellcey@imgtec.com>

	* resolv/Makefile: Use -fno-strict-aliasing when compiling res_hconf.c.
  

Patch

diff --git a/resolv/Makefile b/resolv/Makefile
index f62eea4..453046c 100644
--- a/resolv/Makefile
+++ b/resolv/Makefile
@@ -85,7 +85,12 @@  CPPFLAGS += -Dgethostbyname=res_gethostbyname \
 ifeq (yes,$(have-ssp))
 CFLAGS-libresolv += -fstack-protector
 endif
-CFLAGS-res_hconf.c = -fexceptions
+
+# The casts of cur_ifr->ifr_addr and cur_ifr->ifr_netmask in
+# _res_hconf_reorder_addrs to pointers to sockaddr_in type break
+# GCC's strict aliasing rules and cause GCC 6 to generate a
+# warning unless -fno-strict-aliasing is used.
+CFLAGS-res_hconf.c = -fexceptions -fno-strict-aliasing
 
 # The BIND code elicits some harmless warnings.
 +cflags += -Wno-strict-prototypes -Wno-write-strings