From owner-freebsd-bugs@FreeBSD.ORG Sat Mar 15 05:07:04 2008 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3DA8E1065670 for ; Sat, 15 Mar 2008 05:07:04 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail34.syd.optusnet.com.au (mail34.syd.optusnet.com.au [211.29.133.218]) by mx1.freebsd.org (Postfix) with ESMTP id B3C248FC1A for ; Sat, 15 Mar 2008 05:07:03 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from besplex.bde.org (c220-239-252-11.carlnfd3.nsw.optusnet.com.au [220.239.252.11]) by mail34.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id m2F56wlZ028324 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 15 Mar 2008 16:07:01 +1100 Date: Sat, 15 Mar 2008 16:06:58 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Dan Lukes In-Reply-To: <200803150200.m2F206rl078586@freefall.freebsd.org> Message-ID: <20080315151246.L35251@besplex.bde.org> References: <200803150200.m2F206rl078586@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-bugs@freebsd.org, imp@freebsd.org Subject: Re: bin/71613: [PATCH] traceroute(8): cleanup of the usr.sbin/traceroute6 code X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Mar 2008 05:07:04 -0000 On Sat, 15 Mar 2008, Dan Lukes wrote: > bruce@cran.org.uk napsal/wrote, On 03/15/08 02:15: > > I'm not sure 'volatile' is correct in this case - string literals should > > be defined 'const' since they can't be changed. > > Content of array of chars can be changed unless defined 'const'. You > can't exceed the size of originally allocated space for such array, of > course. To const or not to const, it is our decision. > > To be understand correctly - I'm not against 'const', I'm against > "*since they can't be changed*". This particular string literal should > be defined 'const' *because* it's not changed. > > But back to the topic: > > > Doing this removes the warning about 'copyright' being unused. > > 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 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