Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Apr 2010 07:37:53 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-arch@freebsd.org
Cc:        freebsd-hackers@freebsd.org, Daniel Rodrick <daniel.rodrick@gmail.com>
Subject:   Re: Newbie question: kernel image a dynamically linked binary?
Message-ID:  <201004010737.53482.jhb@freebsd.org>
In-Reply-To: <l2r292693081004010323j42d1ef20k6bcc3ef31a8e440a@mail.gmail.com>
References:  <l2r292693081004010323j42d1ef20k6bcc3ef31a8e440a@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday 01 April 2010 6:23:50 am 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?

It's a hack that is used so that the kernel linker is able to link in kernel 
modules that are built as shared objects.  The kernel is mostly built from 
static objects, but a single dynamic object (that is empty) is linked in:

# 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

-- 
John Baldwin



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