From dan@obluda.cz  Sun Sep 12 02:37:21 2004
Return-Path: <dan@obluda.cz>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id ED93616A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Sep 2004 02:37:21 +0000 (GMT)
Received: from kulesh.obluda.cz (kulesh.obluda.cz [193.179.22.243])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 3C7D143D45
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Sep 2004 02:37:18 +0000 (GMT)
	(envelope-from dan@obluda.cz)
Received: from kulesh.obluda.cz (localhost.eunet.cz [127.0.0.1])
	by kulesh.obluda.cz (8.13.1/8.13.1) with ESMTP id i8C2bFj0007087
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Sep 2004 04:37:16 +0200 (CEST)
	(envelope-from dan@obluda.cz)
Received: (from root@localhost)
	by kulesh.obluda.cz (8.13.1/8.13.1/Submit) id i8C2bE2D007086
	for FreeBSD-gnats-submit@freebsd.org; Sun, 12 Sep 2004 04:37:14 +0200 (CEST)
	(envelope-from dan@obluda.cz)
Message-Id: <200409120237.i8C2bE2D007086@kulesh.obluda.cz>
Date: Sun, 12 Sep 2004 04:37:14 +0200 (CEST)
From: Dan Lukes <dan@obluda.cz>
Reply-To: Dan Lukes <dan@obluda.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] cleanup of the usr.sbin/traceroute6 code
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         71613
>Category:       bin
>Synopsis:       [patch] traceroute(8): cleanup of the usr.sbin/traceroute6 code
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 12 02:40:22 GMT 2004
>Closed-Date:    Sun Dec 12 13:58:09 UTC 2010
>Last-Modified:  Sun Dec 12 13:58:09 UTC 2010
>Originator:     Dan Lukes
>Release:        FreeBSD 5.3-BETA3 i386
>Organization:
Obludarium
>Environment:
System: FreeBSD kulesh.obluda.cz 5.3-BETA3 FreeBSD 5.3-BETA3 #8: Sun Sep 5 07:06:40 CEST 2004 dan@kulesh.obluda.cz:/usr/obj/usr/src/sys/Dan i386
usr.sbin/traceroute6/traceroute6.c,v 1.16 2004/06/13 18:38:46 dwmalone

>Description:
	There are more than 5000 warnings issued during "make buildworld".
Some of them are false positives, but some of them are sign of true errors.

	Nobody is upset by warnings due it's amount, so some errors remain
uncorrected.

	I want to cleanup the code-base from warnings, so warnings will
become "attention mark" again.

usr.sbin/traceroute6/traceroute6.c:69: warning: 'copyright' defined but not used

>How-To-Repeat:
	N/A
>Fix:
*** usr.sbin/traceroute6/traceroute6.c.ORIG	Sun Sep  5 18:33:05 2004
--- usr.sbin/traceroute6/traceroute6.c	Sun Sep  5 18:33:13 2004
***************
*** 66,72 ****
   */
  
  #ifndef lint
! static char copyright[] =
  "@(#) Copyright (c) 1990, 1993\n\
  	The Regents of the University of California.  All rights reserved.\n";
  #endif /* not lint */
--- 66,72 ----
   */
  
  #ifndef lint
! volatile static char copyright[] =
  "@(#) Copyright (c) 1990, 1993\n\
  	The Regents of the University of California.  All rights reserved.\n";
  #endif /* not lint */
>Release-Note:
>Audit-Trail:

From: bruce@cran.org.uk
To: bug-followup@freebsd.org
Cc: dan@obluda.cz
Subject: Re: bin/71613: [PATCH] traceroute(8): cleanup of the usr.sbin/traceroute6 code
Date: Sat, 15 Mar 2008 01:15:44 +0000

 --4Ckj6UjgE2iN1+kY
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 I'm not sure 'volatile' is correct in this case - string literals should
 be defined 'const' since they can't be changed. Doing this removes the
 warning about 'copyright' being unused.  I've attached an updated patch.
 
 --
 Bruce
 
 --4Ckj6UjgE2iN1+kY
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="traceroute6.c.diff"
 
 --- traceroute6.c.old	2008-03-15 01:07:03.000000000 +0000
 +++ traceroute6.c	2008-03-15 01:07:36.000000000 +0000
 @@ -66,7 +66,7 @@
   */
  
  #ifndef lint
 -static char copyright[] =
 +static const char copyright[] =
  "@(#) Copyright (c) 1990, 1993\n\
  	The Regents of the University of California.  All rights reserved.\n";
  #endif /* not lint */
 
 --4Ckj6UjgE2iN1+kY--

From: Dan Lukes <dan@obluda.cz>
To: bruce@cran.org.uk
Cc: bug-followup@freebsd.org
Subject: Re: bin/71613: [PATCH] traceroute(8): cleanup of the usr.sbin/traceroute6
 code
Date: Sat, 15 Mar 2008 02:50:12 +0100

 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.
 
 	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.
 
 						Dan
 

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 <brde@optusnet.com.au> -----
 
 List-Id: Bug reports <freebsd-bugs.freebsd.org>
 
 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 <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 -----

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:26:13 -0500

 ----- Forwarded message from Dan Lukes <dan@obluda.cz> -----
 
 List-Id: Bug reports <freebsd-bugs.freebsd.org>
 
 Bruce Evans napsal/wrote, On 03/15/08 06:06:
 >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.
 
 	Hm. It seems the GCCs are not consistent between versions. In 
 	advance, we didn't speak about intel's icc for now.
 
 	I found something that make both proposed patches void. There is 
 defined __COPYRIGHT macro in sys/cdef.h exactly just for such purpose. 
 The cdefs.h logic tried to deal with icc/gcc and gcc.x/gcc.y differences.
 
 	Even new gcc versions or brand new compiler can be handled in one 
 	place.
 
 	So all the 'copyright' places shall be patched using __COPYRIGHT 
 	macro.
 
 						Dan
 
 ----- End forwarded message -----


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: Sun, 16 Mar 2008 02:32:55 -0500

 ----- Forwarded message from Dan Lukes <dan@obluda.cz> -----
 
 From: Dan Lukes <dan@obluda.cz>
 To: Bruce Evans <brde@optusnet.com.au>
 Cc: freebsd-bugs@FreeBSD.org, imp@FreeBSD.org
 
 	OK
 
 	There seems to be several ways to correct the problem.
 
 	We can avoid the warning by adding "const" or "volatile" or __used 
 	or by removing "static".
 
 	The "remove static" way can't be used - non-static symbol is global 
 variable - so const char copyright[] from one source will collide with 
 the same name variable from another source. It's not problem only when 
 there are one source file only or we can guarantee unique variable name.
 
 	It seems we need 'static'. Unfortunately, static unused variable can 
 	be optimized out.
 
 	Adding 'const' and/or __used clear the warning, but doesn't prevent 
 "optimized-out" problem. The 'const' shall be used because the string is 
 constant. We can use __used, but it has limited portability.
 
 	We still have the problem the variable may be optimized out.
 
 	The 'volatile' is way to tell an ANSI C compiler "this variable may 
 	be modified via mechanism you don't know about it" - it mean "count it as 
 used" and "don't optimize it". Note, the 'const' and 'static' are ANSI C 
 keywords also, so compiler knowing 'static' shall handle 'volatile' as well.
 
 	Conclusion (for the case we can't guarantee the unique name of 
 	variable):
 static   MUST
 const    SHALL
 __used   SHALL
 volatile MUST
 
 So my recomentation is:
 0: static volatile const char __used copyright[]=...
 
 because of __unused the sys/cdefs.h must be included first.
 
 The other way to fix it is
 1: the sys/copyright.h way - e.g. plain char variable - but the variable 
 must be unique across the sources which sound not so easy for me
 
 
 2. the __COPYRIGHT way, but
 2a: IDSTRING must be corrected first
 2b: the '\n' must be removed from the source.
 
 sys/cdefs.h must be included first.
 
 	In my opinion the preference shall be 2a then 0 then 1 or 2b but 
 	it's not strict. The commiter shall select the best way.
 
 
 					Dan
 
 ----- end forwarded message -----

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: Sun, 16 Mar 2008 02:42:13 -0500

 ----- Forwarded message from Bruce Evans <brde@optusnet.com.au> -----
 
 From: Bruce Evans <brde@optusnet.com.au>
 To: Dan Lukes <dan@obluda.cz>
 Cc: freebsd-bugs@freebsd.org
 
 __COPYRIGHT() in <sys/cdefs.h> reduces this problem by concatenating
 __LINE__.  It could also concatenate a file name (but not __FILE__, since
 that is probably not an identifier).
 
 >	It seems we need 'static'. Unfortunately, static unused variable can 
 >be optimized out.
 >
 >	Adding 'const' and/or __used clear the warning, but doesn't prevent 
 >"optimized-out" problem. The 'const' shall be used because the string is 
 >constant. We can use __used, but it has limited portability.
 >
 >	We still have the problem the variable may be optimized out.
 
 __used prevents this.
 
 >	The 'volatile' is way to tell an ANSI C compiler "this variable may 
 >be modified via mechanism you don't know about it" - it mean "count it as 
 >used" and "don't optimize it". Note, the 'const' and 'static' are ANSI C 
 >keywords also, so compiler knowing 'static' shall handle 'volatile' as well.
 
 volatile doesn't prevent the variable being optimized out for gcc-4.2.
 This makes some sense -- volatile sort of means "use it carefully", but
 when it is not used no care with it is needed.
 
 >	Conclusion (for the case we can't guarantee the unique name of 
 >variable):
 >static   MUST
 >const    SHALL
 >__used   SHALL
 >volatile MUST
 >
 >So my recomentation is:
 >0: static volatile const char __used copyright[]=...
 >
 >because of __unused the sys/cdefs.h must be included first.
 
 I prefer 'static char const __used copyright[]'.  Not sure where __used
 belongs.
 
 >The other way to fix it is
 >1: the sys/copyright.h way - e.g. plain char variable - but the variable 
 >must be unique across the sources which sound not so easy for me
 
 Not too bad -- there is supposed to be only one copyright[] per executable.
 
 >2. the __COPYRIGHT way, but
 >2a: IDSTRING must be corrected first
 >2b: the '\n' must be removed from the source.
 >
 >sys/cdefs.h must be included first.
 >
 >	In my opinion the preference shall be 2a then 0 then 1 or 2b but 
 >	it's not strict. The commiter shall select the best way.
 
 2b is no good.
 
 __COPYRIGHT() of course allows putting all the unportabilities in one
 place and changing the easily.  It's just too ugly for me.  Everything in
 <sys/cdefs.h> should have gone away with __P(()).
 
 Bruce
 
 ----- End forwarded message -----

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: Sun, 16 Mar 2008 06:50:49 -0500

 ----- Forwarded message from Dan Lukes <dan@obluda.cz> -----
 
 From: Dan Lukes <dan@obluda.cz>
 To: Bruce Evans <brde@optusnet.com.au>
 Cc: freebsd-bugs@freebsd.org, imp@freebsd.org
 
 Bruce Evans napsal/wrote, On 03/15/08 18:12:
 >__COPYRIGHT() in <sys/cdefs.h> reduces this problem by concatenating
 >__LINE__.  It could also concatenate a file name (but not __FILE__, since
 >that is probably not an identifier).
 
 	It's heuristic. It may, or may not work (it may or may not create 
 unique name across all sources).
 
 >>    We still have the problem the variable may be optimized out.
 >
 >__used prevents this.
 
 	__used is nonstandard gcc extension. I tried it on gcc 3.4.6 and 
 	4.2.3. It works.
 
 	I don't know if it work for icc as I have no one.
 
 	If it works, then it's good fix.
 
 >volatile doesn't prevent the variable being optimized out for gcc-4.2.
 >This makes some sense -- volatile sort of means "use it carefully", but
 >when it is not used no care with it is needed. 
 
 The meaning of volatile shall be "use it carefully, because you can't 
 found which way the variable is used". If the gcc-4.2 optimized it out, 
 it's definitely gcc's bug. If I claim "you don't know how it's used" the 
 compiler shall never respond "I better know what I know than you".
 
 But such discussion doesn't belong there.
 
 
 >I prefer 'static char const __used copyright[]'.  Not sure where __used
 >belongs.
 
 	I have no problem with it if __used works for all relevant 
 	compilers. I prefer the form of a macro (may be other than __COPYRIGHT) for 
 further maintenance, but no problem even with non-macro form.
 
  -------------
 
 	Well, it seems we reach consensus. So what about commitment of a 
 	patch for this four year old PR ? ;-)
 
 						Dan
 
 ----- End forwarded message -----
State-Changed-From-To: open->closed 
State-Changed-By: uqs 
State-Changed-When: Sun Dec 12 13:57:28 UTC 2010 
State-Changed-Why:  
Fixed in r216185, thanks for your submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=71613 
>Unformatted:
