This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Fix strict-aliasing warning in resolv/res_hconf.c
- From: Steve Ellcey <sellcey at imgtec dot com>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: Florian Weimer <fweimer at redhat dot com>, Andreas Schwab <schwab at suse dot de>, "Paul Eggert" <eggert at cs dot ucla dot edu>, <libc-alpha at sourceware dot org>
- Date: Tue, 26 May 2015 16:14:34 -0700
- Subject: Re: [PATCH] Fix strict-aliasing warning in resolv/res_hconf.c
- Authentication-results: sourceware.org; auth=none
- References: <5bfa6373-3817-4d31-a5ee-a8676e79b723 at BAMAIL02 dot ba dot imgtec dot org> <555BB55E dot 3050304 at cs dot ucla dot edu> <1432075989 dot 16668 dot 62 dot camel at ubuntu-sellcey> <555BC19B dot 90001 at cs dot ucla dot edu> <1432077972 dot 16668 dot 65 dot camel at ubuntu-sellcey> <20150519235817 dot 9516F2C3A73 at topped-with-meat dot com> <555C3E0B dot 2040404 at redhat dot com> <mvma8wzbqsv dot fsf at hawking dot suse dot de> <555C48F0 dot 2030208 at redhat dot com> <1432139240 dot 16668 dot 77 dot camel at ubuntu-sellcey> <555F1430 dot 5050301 at redhat dot com> <1432666068 dot 28747 dot 19 dot camel at ubuntu-sellcey> <5564C0AC dot 40708 at redhat dot com> <20150526215601 dot 197BC2C39FC at topped-with-meat dot com>
- Reply-to: <sellcey at imgtec dot com>
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.
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