Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 May 2012 21:42:14 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Hartmut Brandt <harti@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org
Subject:   Re: svn commit: r235777 - head/sys/kern
Message-ID:  <20120522212307.V1971@besplex.bde.org>
In-Reply-To: <201205220723.q4M7Ng2I091715@svn.freebsd.org>
References:  <201205220723.q4M7Ng2I091715@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120522212307.V1971>