Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Nov 1999 11:27:57 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc:        Pierre Beyssac <beyssac@enst.fr>, Sheldon Hearn <sheldonh@uunet.co.za>, freebsd-current@FreeBSD.ORG
Subject:   Re: egcs -O breaks ping.c:in_cksum()
Message-ID:  <199911151927.LAA44755@apollo.backplane.com>
References:  <19991115174831.B30139@enst.fr> <92805.942684743@axl.noc.iafrica.com> <19991115180145.A31542@enst.fr> <199911151835.NAA07676@khavrinen.lcs.mit.edu>

next in thread | previous in thread | raw e-mail | index | archive | help

:It's not a compiler bug, it's a source code bug.
:
:The C Language specifies that pointers to distinct types can be
:assumed, under certain conditions, never to alias one another.  (This
:...
:Recent values of GCC make use of this obscure language feature to
:improve optimization.  Essentially, the optimizer can assume that
:...
:-GAWollman
:
:--
:Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same

    Someone try the patch below and tell me if it fixes the problem.  If it
    does then I'll commit it.  If someone else wants to commit a 'better'
    fix, be my guest!  (but inform the list that you've done so).  Otherwise
    this is the one that will go in.

					-Matt

Index: ping.c
===================================================================
RCS file: /home/ncvs/src/sbin/ping/ping.c,v
retrieving revision 1.45
diff -u -r1.45 ping.c
--- ping.c	1999/08/28 00:13:59	1.45
+++ ping.c	1999/11/15 19:26:23
@@ -920,6 +920,9 @@
 /*
  * in_cksum --
  *	Checksum routine for Internet Protocol family headers (C Version)
+ *
+ *	note: volatilization of 'answer' is a bad hack to work around an 
+ *	aliasing problem.
  */
 u_short
 in_cksum(addr, len)
@@ -929,7 +932,7 @@
 	register int nleft = len;
 	register u_short *w = addr;
 	register int sum = 0;
-	u_short answer = 0;
+	volatile u_short answer = 0;
 
 	/*
 	 * Our algorithm is simple, using a 32 bit accumulator (sum), we add


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199911151927.LAA44755>