Re: Re: extern variables in .c and .h files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 05, 2003 at 17:04:15 +0100, threadhead@web.de wrote:
> Jan Hudec <bulb@ucw.cz> schrieb am 05.12.03 11:21:30:
> 
> >On Thu, Dec 04, 2003 at 21:34:43 +0100, threadhead@web.de wrote:
> >> hi!
> >> 
> >> i've been been coding a LKM that should be
> >> able to use variables, that are declared as extern.
> >> i am using a 2.4.20 kernel.
> >> 
> >> the module is based on some code of
> >> kernel/module.c.
> >> (http://lxr.linux.no/source/kernel/module.c)
> >> 
> >> well, i tried different stuff with that LKM now.
> >> take as an example:
> >> i have the tulip module loaded. with my LKM i can make use of
> >> extern const char * const medianame[];
> >> (http://lxr.linux.no/source/drivers/net/tulip/tulip.h)
> >> and display it, when using the same declaration in my LKM.
> >> 
> >> but for some strange reason i cannot use
> >> variables that were declared a similar way in .c files in the
> >> kernel source tree.
> >> for example:
> >> extern const struct exception_table_entry __start___ex_table[]; (kernel/module.c)
> >> 
> >> why can i access extern vars from header files and not
> >> from source C files, that have been compiled as
> >> part of my current kernel?
> 
> > Only symbols declared EXPROT_SYMBOL (see kernel/ksyms.c) are available
> > to modules. Symbols defined by modules are exported by default unless
> > turned off.
> 
> > -------------------------------------------------------------------------------
> > Jan 'Bulb' Hudec <bulb@ucw.cz>
> 
> 
> Is there another way of accessing the structs in kernel/module.c that have
> been declared as extern with my module?
> like:
> 
> extern struct module_symbol __start___ksymtab[];
> extern struct module_symbol __stop___ksymtab[];
> 
> extern const struct exception_table_entry __start___ex_table[];
> extern const struct exception_table_entry __stop___ex_table[];
> 
> extern const char __start___kallsyms[] __attribute__ ((weak));
> extern const char __stop___kallsyms[] __attribute__ ((weak));

No, the dynamic linker must know about them in the first place.
EXPORT_SYMBOL is necessary for that. Kernel has it's own dynamic linker
(must have if you think of it) to load modules and that that linker only
links symbols it is explicitely told about.

> --
> 
> If no, why have they been declared as extern, if modules cannot access them?

Remember, what extern and static mean with respect to individual source
files.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux