Newbie question: kernel image a dynamically linked binary?

John Baldwin jhb at freebsd.org
Thu Apr 1 12:51:40 UTC 2010


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


More information about the freebsd-arch mailing list