From owner-freebsd-bugs@FreeBSD.ORG Sat Mar 15 08:50:03 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 68D8E1065672 for ; Sat, 15 Mar 2008 08:50:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A12778FC24 for ; Sat, 15 Mar 2008 08:50:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m2F8o2fe011909 for ; Sat, 15 Mar 2008 08:50:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m2F8o2om011901; Sat, 15 Mar 2008 08:50:02 GMT (envelope-from gnats) Date: Sat, 15 Mar 2008 08:50:02 GMT Message-Id: <200803150850.m2F8o2om011901@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: linimon@lonesome.com (Mark Linimon) Cc: 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 Reply-To: Mark Linimon List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Mar 2008 08:50:03 -0000 The following reply was made to PR bin/71613; it has been noted by GNATS. From: linimon@lonesome.com (Mark Linimon) To: bug-followup@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 ----- List-Id: Bug reports On Sat, 15 Mar 2008, Dan Lukes wrote: >bruce@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 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 -----