From owner-freebsd-drivers@FreeBSD.ORG Thu Apr 1 10:51:56 2010 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 753E3106564A; Thu, 1 Apr 2010 10:51:56 +0000 (UTC) (envelope-from daniel.rodrick@gmail.com) Received: from mail-pz0-f191.google.com (mail-pz0-f191.google.com [209.85.222.191]) by mx1.freebsd.org (Postfix) with ESMTP id 3E6F28FC21; Thu, 1 Apr 2010 10:51:56 +0000 (UTC) Received: by pzk29 with SMTP id 29so968452pzk.27 for ; Thu, 01 Apr 2010 03:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:received:message-id :subject:from:to:content-type; bh=F5qurhc6roRcVBsEHj4D3HjHdvJKzQvvZrDvikPcj+k=; b=uBmEoWUZou9ZBe9y3cx2ZAvBs4wK5tHv2kR0qUDAJU+eStOm/yzwtNcRl3/ZZbRDIX jfl9OyQu+KjP64xqaKEC9yO0uUefgFRIq3T4hZ8YlfbEmeDvlnTjaaQzIfWtGxpdvigq scvgAUnr4n/qTJbIJrbitJc+SAG8i/igX+dng= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=UocfQB/Q1bT/3Z8a3Wf29w5MiD5DyJBQpHBv0Uuam6lb4utKQ12WAp+SAS/BpSVbns ZKHlA8rziwnRAmor4Z+JYhfwRXmsNk1paOTvYRzQ8nnp2qu++Yy5Xq4DdEpQnvkyUFXd n/d9ZKJms++RjByP2CKiYAAuapqKNmvd9LlUg= MIME-Version: 1.0 Received: by 10.142.165.10 with HTTP; Thu, 1 Apr 2010 03:23:50 -0700 (PDT) Date: Thu, 1 Apr 2010 15:53:50 +0530 Received: by 10.143.24.15 with SMTP id b15mr116786wfj.147.1270117430542; Thu, 01 Apr 2010 03:23:50 -0700 (PDT) Message-ID: From: Daniel Rodrick To: freebsd-hackers@freebsd.org, freebsd-drivers@freebsd.org, freebsd-arch@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Cc: Subject: Newbie question: kernel image a dynamically linked binary? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2010 10:51:56 -0000 Hello List, I'm a newbie and coming from Linux background, and am trying to learn FreeBSD now. The first thing I find a little confusing is that the final FreeBSD kernel image is shown as a DYNAMICALLY LINKED binary: $ $ pwd /boot/kernel $ $ file kernel kernel: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped $ How can the kernel image use shared libraries? And which ones does it use, if any? Also, I cannot find out the libraries the image uses using the traditional ldd command: $ ldd kernel kernel: kernel: signal 6 $ Can some please throw some light? Thanks, Dan From owner-freebsd-drivers@FreeBSD.ORG Thu Apr 1 11:36:36 2010 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AD1A3106564A; Thu, 1 Apr 2010 11:36:36 +0000 (UTC) (envelope-from gary.jennejohn@freenet.de) Received: from mout0.freenet.de (mout0.freenet.de [IPv6:2001:748:100:40::2:2]) by mx1.freebsd.org (Postfix) with ESMTP id 427A28FC0A; Thu, 1 Apr 2010 11:36:36 +0000 (UTC) Received: from [195.4.92.25] (helo=15.mx.freenet.de) by mout0.freenet.de with esmtpa (ID gary.jennejohn@freenet.de) (port 25) (Exim 4.72 #3) id 1NxIhP-0001O0-2b; Thu, 01 Apr 2010 13:36:35 +0200 Received: from p57ae1282.dip0.t-ipconnect.de ([87.174.18.130]:44475 helo=ernst.jennejohn.org) by 15.mx.freenet.de with esmtpa (ID gary.jennejohn@freenet.de) (port 25) (Exim 4.72 #3) id 1NxIhO-00050d-R9; Thu, 01 Apr 2010 13:36:35 +0200 Date: Thu, 1 Apr 2010 13:36:33 +0200 From: Gary Jennejohn To: Daniel Rodrick Message-ID: <20100401133633.23c7b1fd@ernst.jennejohn.org> In-Reply-To: References: X-Mailer: Claws Mail 3.7.5 (GTK+ 2.18.7; amd64-portbld-freebsd9.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org, freebsd-drivers@freebsd.org, freebsd-arch@freebsd.org Subject: Re: Newbie question: kernel image a dynamically linked binary? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: gary.jennejohn@freenet.de List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2010 11:36:36 -0000 On Thu, 1 Apr 2010 15:53:50 +0530 Daniel Rodrick wrote: > Hello List, > > I'm a newbie and coming from Linux background, and am trying to learn > FreeBSD now. The first thing I find a little confusing is that the > final FreeBSD kernel image is shown as a DYNAMICALLY LINKED binary: > > $ > $ pwd > /boot/kernel > $ > $ file kernel > kernel: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), > dynamically linked (uses shared libs), not stripped > $ > > How can the kernel image use shared libraries? And which ones does it > use, if any? > > Also, I cannot find out the libraries the image uses using the > traditional ldd command: > > $ ldd kernel > kernel: > kernel: signal 6 > $ > > Can some please throw some light? > file is confused. FreeBSD uses a monolithic kernel and no shared libraries are involved. However, it is possible to dynamically load modules using kldload. See the appropriate man page. -- Gary Jennejohn From owner-freebsd-drivers@FreeBSD.ORG Thu Apr 1 12:01:47 2010 Return-Path: Delivered-To: freebsd-drivers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E06171065678; Thu, 1 Apr 2010 12:01:46 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 5BB688FC22; Thu, 1 Apr 2010 12:01:46 +0000 (UTC) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id o31C1TZ6045279; Thu, 1 Apr 2010 14:01:44 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id o31C1TRm045278; Thu, 1 Apr 2010 14:01:29 +0200 (CEST) (envelope-from olli) Date: Thu, 1 Apr 2010 14:01:29 +0200 (CEST) Message-Id: <201004011201.o31C1TRm045278@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG, daniel.rodrick@gmail.com, freebsd-drivers@FreeBSD.ORG, freebsd-arch@FreeBSD.ORG In-Reply-To: X-Newsgroups: list.freebsd-arch User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Thu, 01 Apr 2010 14:01:45 +0200 (CEST) Cc: Subject: Re: Newbie question: kernel image a dynamically linked binary? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-hackers@FreeBSD.ORG, daniel.rodrick@gmail.com List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2010 12:01:47 -0000 Hi, Please don't crosspost to many lists. This topic is probably suitable for hackers@ but not for the other lists. Daniel Rodrick wrote: > I'm a newbie and coming from Linux background, and am trying to learn > FreeBSD now. The first thing I find a little confusing is that the > final FreeBSD kernel image is shown as a DYNAMICALLY LINKED binary: > > $ > $ pwd > /boot/kernel > $ > $ file kernel > kernel: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), > dynamically linked (uses shared libs), not stripped > $ > > How can the kernel image use shared libraries? And which ones does it > use, if any? > > Also, I cannot find out the libraries the image uses using the > traditional ldd command: > > $ ldd kernel > kernel: > kernel: signal 6 > $ ldd works by actually executing the binary with a special flag for rtld(1). Compare: $ ldd /bin/sh /bin/sh: libedit.so.7 => /lib/libedit.so.7 (0x280a8000) libncurses.so.8 => /lib/libncurses.so.8 (0x280bd000) libc.so.7 => /lib/libc.so.7 (0x280fc000) $ LD_TRACE_LOADED_OBJECTS=1 /bin/sh libedit.so.7 => /lib/libedit.so.7 (0x280a8000) libncurses.so.8 => /lib/libncurses.so.8 (0x280bd000) libc.so.7 => /lib/libc.so.7 (0x280fc000) Of course you cannot execute the kernel (only the boot loader knows how to load and boot the kernel), so ldd fails on the kernel. But you can use objdump(1) to list dynamic dependencies. $ objdump -p /bin/sh | grep NEEDED NEEDED libedit.so.7 NEEDED libncurses.so.8 NEEDED libc.so.7 $ objdump -p /boot/kernel/kernel | grep NEEDED NEEDED hack.So As far as I know, the kernel and all kernel modules need to be dynamic binaries so the kernel linker works, which is required for dynamically loading kernel modules. So what is that "hack.So" object? It's just a dummy that's required for technical reasons. You can see the details in /sys/conf/kern.post.mk which contains this paragraph: # This is a hack. BFD "optimizes" away dynamic mode if there are no # dynamic references. We could probably do a '-Bforcedynamic' mode like # in the a.out ld. For now, this works. HACK_EXTRA_FLAGS?= -shared hack.So: Makefile :> hack.c ${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So rm -f hack.c > Can some please throw some light? I hope I did. :-) Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "Unix gives you just enough rope to hang yourself -- and then a couple of more feet, just to be sure." -- Eric Allman From owner-freebsd-drivers@FreeBSD.ORG Thu Apr 1 21:42:16 2010 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 78A65106566C for ; Thu, 1 Apr 2010 21:42:16 +0000 (UTC) (envelope-from des@des.no) Received: from smtp.des.no (smtp.des.no [194.63.250.102]) by mx1.freebsd.org (Postfix) with ESMTP id 3988C8FC0C for ; Thu, 1 Apr 2010 21:42:16 +0000 (UTC) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 5AEDD1FFC77; Thu, 1 Apr 2010 21:22:43 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 0BED784852; Thu, 1 Apr 2010 14:03:50 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: gary.jennejohn@freenet.de References: <20100401133633.23c7b1fd@ernst.jennejohn.org> Date: Thu, 01 Apr 2010 14:03:49 +0200 In-Reply-To: <20100401133633.23c7b1fd@ernst.jennejohn.org> (Gary Jennejohn's message of "Thu, 1 Apr 2010 13:36:33 +0200") Message-ID: <8639zftm56.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org, freebsd-drivers@freebsd.org, freebsd-arch@freebsd.org Subject: Re: Newbie question: kernel image a dynamically linked binary? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2010 21:42:16 -0000 Gary Jennejohn writes: > Daniel Rodrick writes: > > $ file kernel > > kernel: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), > > dynamically linked (uses shared libs), not stripped > file is confused. FreeBSD uses a monolithic kernel and no shared > libraries are involved. However, it is possible to dynamically load > modules using kldload. See the appropriate man page. File is right. The kernel contains relocation entries so kernel modules can be linked against it. "monolithic" means something else entirely. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no From owner-freebsd-drivers@FreeBSD.ORG Thu Apr 1 21:42:16 2010 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 78F531065672 for ; Thu, 1 Apr 2010 21:42:16 +0000 (UTC) (envelope-from des@des.no) Received: from smtp.des.no (smtp.des.no [194.63.250.102]) by mx1.freebsd.org (Postfix) with ESMTP id 398418FC0A for ; Thu, 1 Apr 2010 21:42:16 +0000 (UTC) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 6ADCD1FFC7B; Thu, 1 Apr 2010 21:22:43 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id A838E84854; Thu, 1 Apr 2010 14:05:01 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: gary.jennejohn@freenet.de References: <20100401133633.23c7b1fd@ernst.jennejohn.org> <8639zftm56.fsf@ds4.des.no> Date: Thu, 01 Apr 2010 14:05:01 +0200 In-Reply-To: <8639zftm56.fsf@ds4.des.no> ("Dag-Erling =?utf-8?Q?Sm=C3=B8rg?= =?utf-8?Q?rav=22's?= message of "Thu, 01 Apr 2010 14:03:49 +0200") Message-ID: <86y6h7s7iq.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org, freebsd-drivers@freebsd.org, freebsd-arch@freebsd.org Subject: Re: Newbie question: kernel image a dynamically linked binary? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2010 21:42:16 -0000 Dag-Erling Sm=C3=B8rgrav writes: > File is right. The kernel contains relocation entries so kernel modules > can be linked against it. "relocation entries" is possibly not the right term, someone with better knowledge of ELF will have to correct me. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no