Re: svn commit: r235777 - head/sys/kern

2012-05-22 Thread Bruce Evans

On Tue, 22 May 2012, Hartmut Brandt wrote:


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 must be there for debugging purposes and historical compatibility
(mainly other debugging uses, including kvm).  Static symbols are not
really special here.  The C standard doesn't even require a symbol table,
and it is only implementation details and debugging and historical
compatibility that require putting global symbols in symbol tables.


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?


Same as it always did.  The names are in per-object-file namespaces for
the linker, so they don't conflict for linking, but they mess up primitive
debuggers starting with nm.


If
several files declared static dumptids, which one would kldsym be supposed
to return?


libkvm and kldsym would be broken.  I don't know of any even
non-primitive debuggers that can handle this.  In gdb the only way
that I know of to print a non-unique variable is to display the source
file that declares the variable using something like `l' on a function
in that file; the variable scope is then that of the selected file.
The address "file.c:foo" only works for displaying functions.  The
latter probably depends on a full symbol table.  When there is no
symbol table, `l' of course doesn't work; `disass foo" works.  "disass
file.c:foo" of course doesn't work.  "disass file.o:foo" should work,
but doesn't, even when there is a full symbol table.  When the "file.*:"
address doesn't work, this is is initially because it misparsed as the
symbol "file".  Actually, I know of the primitive way which works even
using ddb with all symbols broken in ddb, and have had to use this several
times: you find the address of things using nm or something less
primitive on another system, and guess which address to use if several
variables have the same name, and type it in.

BTW, kernels have lots of conflicting symbols which mess up debugging
using primitive debuggers like ddb.
/usr/src/tools/tools/kernxref/kernxref.sh was supposed to be used to
find and fix these as well as finding and fixing public variables that
should be static, but it is rarely used.  uniq reports removing 382
out of 28443 (non-unique) symbols in a fairly current kernel with not
many features configured.

Bruce
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r235777 - head/sys/kern

2012-05-22 Thread Bjoern A. Zeeb

On 22. May 2012, at 07:23 , Hartmut Brandt wrote:

> Author: harti
> Date: Tue May 22 07:23:41 2012
> New Revision: 235777
> URL: http://svn.freebsd.org/changeset/base/235777
> 
> Log:
>  Make dumptid non-static. It is used by libkvm to detect whether
>  this is a VNET-kernel or not.

Just for clarifications - it's used to detect whether we are operating on
a crash dump or not in the vnet case.


> 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
> 
> 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);

-- 
Bjoern A. Zeeb You have to have visions!
   It does not matter how good you are. It matters what good you do!

___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r235777 - head/sys/kern

2012-05-22 Thread Hartmut Brandt
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>
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r235777 - head/sys/kern

2012-05-22 Thread Bruce Evans

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
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"