Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Sep 2012 14:40:06 GMT
From:      David Marker <dmarker@gmail.com>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/167671: [libkvm] [patch] libkvm doesn&#39;t initialize vnet
Message-ID:  <201209041440.q84Ee6Bv023640@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/167671; it has been noted by GNATS.

From: David Marker <dmarker@gmail.com>
To: bug-followup@FreeBSD.org, dmarker@gmail.com
Cc:  
Subject: Re: kern/167671: [libkvm] [patch] libkvm doesn&#39;t initialize
 vnet
Date: Tue, 4 Sep 2012 08:36:34 -0600

 After further investigation, the problem is that clang(1) optimized the symbol dumptid out of kern_shutdown.c. 
 To reproduce you need "options VIMAGE" and you need to be building with clang(1) not gcc(1).
 
 I can verify this with a simple program to look for the "dumptid" symbol in the same way _kvm_nlist() does:
 
 --------------------------------------------------------------------------------
 #include <errno.h>
 #include <stdio.h>
 #include <sys/param.h>
 #include <sys/linker.h>
 int
 main()
 {
 int rc;
 char *symname = "dumptid";
 struct kld_sym_lookup lookup = {
 .version = sizeof(struct kld_sym_lookup),
 .symname = symname,
 .symvalue = 0,
 .symsize = 0
 };
 if (0 == (rc = kldsym(0, KLDSYM_LOOKUP, &lookup))) {
 (void) fprintf(stdout, "kldsym(...) -> %d\n", rc);
 (void) fprintf(stdout, "found symbol \"%s\"\n", symname);
 } else {
 (void) fprintf(stdout, "kldsym(...) -> %d, errno = %d\n", rc, errno);
 perror(NULL);
 }
 return (0);
 }
 
 --------------------------------------------------------------------------------
 
 The symbol is missing. So the fix is much simpler, make dumptid volatile so clang(1) doesn't feel free to optimize it away.
 After making dumptid volatile the test program above finds the symbol and the original patch isn't needed.
 
 
 $ svn diff
 Index: sys/kern/kern_shutdown.c
 ===================================================================
 --- sys/kern/kern_shutdown.c (revision 240074)
 +++ sys/kern/kern_shutdown.c (working copy)
 @@ -148,7 +148,7 @@
 
 /* Context information for dump-debuggers. */
 static struct pcb dumppcb; /* Registers. */
 -static lwpid_t dumptid; /* Thread ID. */
 +static volatile lwpid_t dumptid; /* Thread ID. */
 
 static void poweroff_wait(void *, int);
 static void shutdown_halt(void *junk, int howto);
 
 
 
 
 



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