From owner-svn-src-all@FreeBSD.ORG Tue May 22 11:42:23 2012 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A1B191065679; Tue, 22 May 2012 11:42:23 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail03.syd.optusnet.com.au (mail03.syd.optusnet.com.au [211.29.132.184]) by mx1.freebsd.org (Postfix) with ESMTP id 376C48FC17; Tue, 22 May 2012 11:42:23 +0000 (UTC) Received: from c122-106-171-232.carlnfd1.nsw.optusnet.com.au (c122-106-171-232.carlnfd1.nsw.optusnet.com.au [122.106.171.232]) by mail03.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id q4MBgEaD032723 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 22 May 2012 21:42:15 +1000 Date: Tue, 22 May 2012 21:42:14 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Hartmut Brandt In-Reply-To: <201205220723.q4M7Ng2I091715@svn.freebsd.org> Message-ID: <20120522212307.V1971@besplex.bde.org> References: <201205220723.q4M7Ng2I091715@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r235777 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 May 2012 11:42:23 -0000 On Tue, 22 May 2012, Hartmut Brandt wrote: > Log: > Make dumptid non-static. It is used by libkvm to detect whether > this is a VNET-kernel or not. gcc used to put the static symbol into > the symbol table, clang does not. This fixes the 'netstat: no namelist' > error seen on clang+VNET systems. > > Modified: > head/sys/kern/kern_shutdown.c That would be a bug in clang if it were done for static symbols generally, but here the bug seems to be that the symbol is not declared as __used. gcc does the same for a file containing only "static int x;", but it is apparently confused by dumptid being initialized non-statically, although the initialization has no side effects. If dumptid were a local variable, then clang would probably warn about the variable being unused, but gcc-4.2.1 never detects such unused variables (thus code that compiles with gcc -Wunused -Werror often fails with clang). Here the initialization is to curthread->td_tid, so it isn't clear if the compiler can tell if it has no side effects. curthread() is actually __curthread(). __curthread() is now declared as __pure2, but that never worked for me with older compilers (its result wasn't cached). If the compilers can tell that the expression has no side effects, then it is another bug that they don't warn about it having no effect when it is only assigned to the apparently-unused variable dumptid. > Modified: head/sys/kern/kern_shutdown.c > ============================================================================== > --- head/sys/kern/kern_shutdown.c Tue May 22 07:04:23 2012 (r235776) > +++ head/sys/kern/kern_shutdown.c Tue May 22 07:23:41 2012 (r235777) > @@ -151,7 +151,7 @@ static struct dumperinfo dumper; /* our > > /* Context information for dump-debuggers. */ > static struct pcb dumppcb; /* Registers. */ > -static lwpid_t dumptid; /* Thread ID. */ > +lwpid_t dumptid; /* Thread ID. */ > > static void poweroff_wait(void *, int); > static void shutdown_halt(void *junk, int howto); Now there are 3 bugs instead of 1: - the variable is declared (implicit) extern instead of static - the extern declaration is in a section for static declaration - the variable is still not declared as __used. If the compiler did a more extensive usage analysis, that looked at all object files but not at the libkvm API, then it should remove this variable anyway when it is not declared as __used. Bruce