Date: Tue, 22 May 2012 14:46:01 +0200 From: Hartmut Brandt <hartmut.brandt@dlr.de> To: Bruce Evans <brde@optusnet.com.au> Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Hartmut Brandt <harti@FreeBSD.org> Subject: Re: svn commit: r235777 - head/sys/kern Message-ID: <alpine.BSF.2.00.1205221359070.7484@KNOP-BEAGLE.kn.op.dlr.de> In-Reply-To: <20120522212307.V1971@besplex.bde.org> References: <201205220723.q4M7Ng2I091715@svn.freebsd.org> <20120522212307.V1971@besplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 22 May 2012, Bruce Evans wrote: BE>On Tue, 22 May 2012, Hartmut Brandt wrote: BE> BE>> Log: BE>> Make dumptid non-static. It is used by libkvm to detect whether BE>> this is a VNET-kernel or not. gcc used to put the static symbol into BE>> the symbol table, clang does not. This fixes the 'netstat: no namelist' BE>> error seen on clang+VNET systems. BE>> BE>> Modified: BE>> head/sys/kern/kern_shutdown.c BE> BE>That would be a bug in clang if it were done for static symbols generally, BE>but here the bug seems to be that the symbol is not declared as __used. I don't get this. Why should a symbol declared static be in the symbol table (except for debugging purposes) ? It has internal linkage and so has a meaning only in the given file. What is the linker supposed to do with several static symbols with the same name from several object files? If several files declared static dumptids, which one would kldsym be supposed to return? harti BE> BE>gcc does the same for a file containing only "static int x;", but it BE>is apparently confused by dumptid being initialized non-statically, BE>although the initialization has no side effects. If dumptid were a BE>local variable, then clang would probably warn about the variable being BE>unused, but gcc-4.2.1 never detects such unused variables (thus code BE>that compiles with gcc -Wunused -Werror often fails with clang). Here BE>the initialization is to curthread->td_tid, so it isn't clear if the BE>compiler can tell if it has no side effects. curthread() is actually BE>__curthread(). __curthread() is now declared as __pure2, but that BE>never worked for me with older compilers (its result wasn't cached). BE>If the compilers can tell that the expression has no side effects, BE>then it is another bug that they don't warn about it having no effect BE>when it is only assigned to the apparently-unused variable dumptid. BE> BE>> Modified: head/sys/kern/kern_shutdown.c BE>> ============================================================================== BE>> --- head/sys/kern/kern_shutdown.c Tue May 22 07:04:23 2012 BE>> (r235776) BE>> +++ head/sys/kern/kern_shutdown.c Tue May 22 07:23:41 2012 BE>> (r235777) BE>> @@ -151,7 +151,7 @@ static struct dumperinfo dumper; /* our BE>> BE>> /* Context information for dump-debuggers. */ BE>> static struct pcb dumppcb; /* Registers. */ BE>> -static lwpid_t dumptid; /* Thread ID. */ BE>> +lwpid_t dumptid; /* Thread ID. */ BE>> BE>> static void poweroff_wait(void *, int); BE>> static void shutdown_halt(void *junk, int howto); BE> BE>Now there are 3 bugs instead of 1: BE>- the variable is declared (implicit) extern instead of static BE>- the extern declaration is in a section for static declaration BE>- the variable is still not declared as __used. If the compiler did BE> a more extensive usage analysis, that looked at all object files but BE> not at the libkvm API, then it should remove this variable anyway BE> when it is not declared as __used. BE> BE>Bruce BE> BE>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.00.1205221359070.7484>