bin/71613: [PATCH] traceroute(8): cleanup of the usr.sbin/traceroute6 code

Mark Linimon linimon at lonesome.com
Sat Mar 15 08:50:03 UTC 2008


The following reply was made to PR bin/71613; it has been noted by GNATS.

From: linimon at lonesome.com (Mark Linimon)
To: bug-followup at FreeBSD.org
Cc:  
Subject: Re: bin/71613: [PATCH] traceroute(8): cleanup of the usr.sbin/traceroute6 code
Date: Sat, 15 Mar 2008 03:43:02 -0500

 ----- Forwarded message from Bruce Evans <brde at optusnet.com.au> -----
 
 List-Id: Bug reports <freebsd-bugs.freebsd.org>
 
 On Sat, 15 Mar 2008, Dan Lukes wrote:
 
 >bruce at cran.org.uk napsal/wrote, On 03/15/08 02:15:
 >	I don't understand what the 'const' has to do with "variable has been
 >used" so I can't explain why it remove the warning. I'm not sure it's
 >not an unintentional interference that occur only in (that version of) gcc.
 
 Declaring unused static variables (at least for variables which are
 arrays characters is^Wwas the way guaranteed by gcc for preventing
 removal of such variables from the object file in cases where the
 variable really is unused.  The C standard of course permits removal
 of such variables, since nothing in C could tell the difference.
 However, some means of keeping apparently-unused variables in C objects
 so that things like debuggers and strings(1) can see them is needed,
 and declaring them as const is^Wwas the way.  This mechanism should
 have been used for all copyrights.
 
 Compilers which remove unused variables shouldn't be used to compile
 most of the sources in FreeBSD, since they would not put copyright
 strings in object files.  The 2/3/4 clause BSD license doesn't strictly
 require this, but the "[const] char copyright[] strings in some source
 files are clearly intended to be kept, since they just duplicate part
 of the main copyyright.  E.g., in cat.c:
 
 % /*-
 %  * Copyright (c) 1989, 1993
 %  *	The Regents of the University of California.  All rights reserved.
 %...
 %  * 2. Redistributions in binary form must reproduce the above copyright
 %  *    notice, this list of conditions and the following disclaimer in the
 %  *    documentation and/or other materials provided with the distribution.
 
 Note that this doesn't require the above copyright notice to be reporoduced
 in the excecutable...
 
 % #if 0
 % #ifndef lint
 % static char const copyright[] =
 % "@(#) Copyright (c) 1989, 1993\n\
 % 	The Regents of the University of California.  All rights 
 reserved.\n";
 % #endif /* not lint */
 % #endif
 
 but the code clearly attempts to reproduce the copyright notice in the
 executable anyway, except for previous breakage in this area (the #if 0
 -- see below).  In 4.4, the declaration is just "static char copyright[]..."
 but FreeBSD added the const qualifier to use the guarantee long ago.
 
 >	But I may not have sufficient knowledge of C details. If we are sure
 >the 'const' shall have required effect to "unused" warning by definition
 >then I have nothing against 'const' way patch.
 
 gcc broke its guarantee about "const" stopping this warning, and even
 more importantly, of the variable not being removed, in gcc-4 or
 earlier.  The #if 0 in the above was committed on 2003/04/30 with a
 log message saying (not quite in the following words :-)) that it is
 to break the warning from gcc-3.3 about the variable being unused.  It
 also breaks putting the copyright in the executable.  It seems to have
 been premature -- gcc-3.3.3 neither warns nor removes the copyright.
 gcc-4.2 always removes "static char const copyright[]...", and it warns
 about this variable being unused if WARNS > 1.  (gcc-3.3.3 never removes
 this variable; it warns at WARNS > 1 for "static char copyright[]...'
 but the const qualifier stops this warning.)
 
 gcc now supports not removing variables with a `used' attribute.  This
 attribut is supported in in a compiler-independed way in <sys/cdefs/h> 
 by the __used #define, but is not used much yet.  So many copyrights
 and rcsids are just missing in binaries in FreeBSD-7 and later.
 
 Using a volatile qualifier instead of a const qualifier gives inconsistent
 results.  gcc-4.3 always removes "static char volatile copyright[] but
 doesn't warn about this removal at WARNS > 1.  Not warning is clearly
 just a bug.  gcc-3.3.3 always keeps this variable, and warns about it
 being unused at WARNS > 1.
 
 Bruce
 
 ----- End forwarded message -----


More information about the freebsd-bugs mailing list