[HEADS UP] Kernel modules don't work properly in FreeBSD 8.1-RC1

Andriy Gapon avg at icyb.net.ua
Wed Jun 23 15:40:46 UTC 2010

on 23/06/2010 18:03 Ryan Stone said the following:
> On Wed, Jun 23, 2010 at 3:10 AM, Andriy Gapon <avg at icyb.net.ua> wrote:
>> Which also brings the question - what arch(s) is affected?
>> I tested on amd64.
> This should explain it.  It looks to me like i386 uses kern/link_elf.c
> as its linker, while amd64 uses kern/link_elf_obj.c.  link_elf.c can
> only find the sections containing the sysinits(and some related
> things) via the magic symbols.  link_elf_obj.c seems to understand ELF
> objects much better and doesn't need those symbols to be present.  It
> just looks up the section that contains the sysinits directly via the
> ELF metadata that is already present.

Yes, you are absolutely correct.  This comes from the fact that amd64 uses simple
objects files (aka .o) as kernel modules and i386 uses full-blow dso.

> As far as I can tell, amd64 is the only arch in the tree that uses
> link_elf_obj.c, so all other arches may be affected.
> I have to admit that I'm more than a little surprised that this
> problem does not affect modules that in src, but maybe that's because
> I don't know all that much about FreeBSD's build infrastructure.  Are
> the src modules being linked with a linker script that is not being
> used for out-of-src modules?

No, we don't have any special linker script for modules.

> Are the people affected by this not
> using the base compiler to build ports?(I see that this affects PC-BSD
> as well, and I'd be a little surprised to learn that it wasn't using
> the base compiler).

I think that even out-of-base modules still use the same module build
infrastructure (bsd.kmod.mk).  At least this is the case for cuse4bsd.

> The link line that I gave was a hack.  The proper solution is to use a
> linker script that unconditionally puts the magic symbols in.

Module link process on i386 is like this (simplified):
1) combine object files into a single object file mod.kld
ld -r -o mod.kld 1.o 2.o
2) convert it to dso
ld -Bshareable -d -warn-common -o mod.ko mod.kld

I believe that __start/__stop symbols for sections should be automatically added
at step 2 by linker.


Andriy Gapon

More information about the freebsd-current mailing list