In article <[EMAIL PROTECTED]>, Dan Malek  <[EMAIL PROTECTED]> wrote:
>
>This is the way the kernel used to be, with the kernel objects
>as *.a files instead of *.o files.  I remember a discussion on
>some mailing lists when things changed from *.a to *.o, and I
>asked why it had changed.  The response I received was the change
>was due to loadable modules, that when you link the kernel as a
>bunch of *.a files the result is usually missing lots of functions
>that a loadable module may want to call.

You asked the wrong people.

The reason most of the Linux kernel is linked using "lr -R" instead of
creating lots of object file archives with "ar" is quite simple.

It has to be done that way in order to force-link the "unnecessary"
sections that have pointers to initialization routines etc.

In 2.3.x kernels, the Linux kernel no longer depends on having special
initialization functions that call all the initializers for stuff that
was configured in: instead the kernel uses a few special sections that
just have all init-function pointers in it, and a simple routine that
walks that section and calls all initializers.

This means, for example, that we no longer have the horribly ugly crap:

        ..
        #ifdef CONFIG_FATFS
                fatfs_init();
        #endif
        #ifdef CONFIG_EXT2FS
                ext2fs_init();
        #endif
        ... approximately 200 lines of this ...

but instead each module that needs to be explicitly initialized just
adds itself to the magic initializer section.

And thus we need to link the combination of object files with "ld -R"
instead of "ar", because if we used an archive none of the object files
would appear to be referenced from anywhere (because each object file
contains it's own "caller"). 

The new method is, btw, about a million times cleaner than the old one,
mainly because:
 - loadable modules and built-in kernel modules have 100% the same
   source code. Some simple compile-time macros will just either
   populate the initializer section or the magic "init_module()"
   function.
 - when adding a new driver or a new filesystem, no longer do we have to
   edit any shared files for initialization: just add the config option,
   add the makefile entry, and you're done. No need to edit
   fs/filesystems.c to add another new filesystem type.

So the "ld -R" is not going away, unless people can show how to maintain
these good properties..

                Linus

Reply via email to