From owner-freebsd-current@FreeBSD.ORG Thu Aug 18 17:11:06 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4E4C7106564A for ; Thu, 18 Aug 2011 17:11:06 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 26AAC8FC08 for ; Thu, 18 Aug 2011 17:11:06 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id D094846B06; Thu, 18 Aug 2011 13:11:05 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 72A0C8A037; Thu, 18 Aug 2011 13:11:05 -0400 (EDT) From: John Baldwin To: freebsd-current@freebsd.org Date: Thu, 18 Aug 2011 11:24:35 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110617; KDE/4.5.5; amd64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201108181124.35122.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Thu, 18 Aug 2011 13:11:05 -0400 (EDT) Cc: Jason Harmening Subject: Re: device_probe_and_attach() fails in kernel built w/ clang X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2011 17:11:06 -0000 On Thursday, August 18, 2011 2:03:14 am Jason Harmening wrote: > Hi everyone, > > I have a driver for PCI devices that have onboard I2C buses, so my > driver needs to create an iicbus child for the PCI device. So in my > driver I use DRIVER_MODULE(iicbus, , iicbus_driver, > iicbus_devclass, NULL, NULL). This works because iicbus_driver and > iicbus_devclass are declared extern in iicbus.h. > > Then during device attachment I create the iicbus child using: > > device_add_child(parent, "iicbus", -1); > ... > device_probe_and_attach(iicbus_dev); > > This all works fine for a kernel built w/ gcc. But if I build the > same kernel w/ clang, the device_probe_and_attach() call returns > ENXIO. I was able to debug this far enough to determine that > device_probe_child() in subr_bus.c wasn't finding any matching > drivers, so first_matching_driver() returned NULL and the matching > loops fell through. > > Interestingly enough, I have another driver for a similar class of > devices that also uses iicbus, and if I load that driver after loading > the first one, the *first* driver will be re-probed, and this time it > will successfully create its iicbus devices and attach to the PCI > devices. The *second* driver, though, will still fail to create its > iicbuses. > > I'm not sure if this is some weird problem w/ the iicbus driver, with > the kernel's probing routines, or with the module data structures and > init calls generated by DRIVER_MODULE(). Whatever it is seems to be > clang-related; removing optimization and march= from CFLAGS had no > effect. I'm using r224899/amd64. > > Any help would be really appreciated. Hmm, I would add some tracing to see if the iicbus/ is being registered at all. You might also just use kldstat -v to check for it without needing any extra tracing as a first step. However, if you dig into DRIVER_MODULE() you will see it creates a structure that is passed to a MOD_EVENT handler in sys/kern/subr_bus.c that registers new drivers. That is where I would add instrumentation to make sure the new iicbus driver is being registered correctly. -- John Baldwin