From owner-freebsd-bugs@FreeBSD.ORG Tue Sep 4 14:40:06 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CB9671065670 for ; Tue, 4 Sep 2012 14:40:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 9DA4E8FC08 for ; Tue, 4 Sep 2012 14:40:06 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q84Ee6mo023657 for ; Tue, 4 Sep 2012 14:40:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q84Ee6Bv023640; Tue, 4 Sep 2012 14:40:06 GMT (envelope-from gnats) Date: Tue, 4 Sep 2012 14:40:06 GMT Message-Id: <201209041440.q84Ee6Bv023640@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: David Marker Cc: Subject: Re: kern/167671: [libkvm] [patch] libkvm doesn't initialize vnet X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: David Marker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Sep 2012 14:40:06 -0000 The following reply was made to PR kern/167671; it has been noted by GNATS. From: David Marker To: bug-followup@FreeBSD.org, dmarker@gmail.com Cc: Subject: Re: kern/167671: [libkvm] [patch] libkvm doesn'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 #include #include #include 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);