Re: More linker magic..

Jakub Jelinek (jj@sunsite.ms.mff.cuni.cz)
Wed, 4 Aug 1999 10:59:07 +0200


> Not if done right. You CAN still do them differently, but I changed a few
> drivers to not have a single #ifdef MODULE, and I hope it takes off.
>
> The fact is, that modules and non-modules _are_ going to be subtly
> different, but we can make the differences as small as possible.
>
> I'll make a pre-4 so that you can comment on some of the modules (look at
> "binfmt_elf.c" for example).

I think it would be better to capitalize MODULE_INIT() and MODULE_EXIT()
macros, so they look the same as other module macros like MODULE_PARM,
MODULE_AUTHOR etc.
Second, I think it would be better for true modules to declare
init_module/cleanup_module as aliases and avoid a new function which just
calls the initialization routine.
Something like:

#ifndef MODULE
#define MODULE_INIT(x) __initcall(x)
#define MODULE_EXIT(x) /* nothing */
#else
#define MODULE_INIT(x) extern int init_module(void) __attribute__ ((alias (#x)))
#define MODULE_EXIT(x) extern void cleanup_module(void) __attribute__ ((alias (#x)))
#endif

BTW: We could simply use gcc constructors and get rid of the
MODULE_INIT/MODULE_EXIT stuff altogether.

Either write in the code just

static int __initcall init_module (void)
{
}
static void __exit cleanup_module (void)
{
}

(where

#ifndef MODULE
#define __initcall __attribute__ ((constructor))
#else
#define __initcall
#endif

)
and instead of playing with .initcall.init section kernel would examine
.ctors section. No name translation or whatever required (provided the
static keyword is there). modutils AFAIK don't care whether init_module etc.
are STB_GLOBAL or STB_LOCAL. Linker script would make sure .ctors section is
put into the segment beeing freed after bootup.
What's the purpose of __exit being put into .text.init section and not
thrown away completely for built-in modules anyway? Nobody will call them,
so why should they clutter space in the resulting vmlinux?

Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jj@sunsite.mff.cuni.cz | http://sunsite.mff.cuni.cz
Administrator of SunSITE Czech Republic, MFF, Charles University
___________________________________________________________________
UltraLinux | http://ultra.linux.cz/ | http://ultra.penguin.cz/
Linux version 2.3.13 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/