1.export_symbol
Export_symbol (My_pub_func);
The precompilation phase resolves to:
extern void *__crc_my_pub_func __attribute__ ((weak));
static const unsigned long __kcrctab_my_pub_func __attribute__ ((__used__)) __attribute__ ((Section ("__kcrctab"), Unused) = (unsigned long) &__crc_my_pub_func;
static const char __kstrtab_my_pub_func[] __attribute__ ((section ("__ksymtab_strings")) = "" My_pub_func;
static const struct Kernel_symbol __ksymtab_my_pub_func __attribute__ ((__used__)) __attribute__ ((Section ("__ksymtab" ""), unused) = {(unsigned long) &my_pub_func, __kstrtab_my_pub_func};
Obviously __ksymtab_my_pub_func stores My_pub_func address and symbolic information, which corresponds to the address
Only after the insmod will be determined;
__ksymtab_my_pub_func will link to all the contents of the __ksymtab section,__ksymtab section.
The symbol table for the kernel "export", which is used when insmod. 2./proc/kallsyms
Cat/proc/kallsyms will print out the current symbol table for the kernel, for example:
...
D8834a24 T snd_free_sgbuf_pages [Snd_page_alloc]
c0180d7a U create_proc_entry [Snd_page_alloc]
D88341d8 T snd_dma_free_pages [Snd_page_alloc]
c013d858 U __get_free_pages [Snd_page_alloc]
D8834AB5 T snd_malloc_sgbuf_pages [Snd_page_alloc]
c014f906 U Kmem_cache_alloc [Snd_page_alloc]
C0106DCD U dma_alloc_coherent [Snd_page_alloc]
...
The first column is the address of the symbol in the kernel address space, the second column is the symbol attribute, and the lowercase representation
Local symbol, uppercase denotes global symbol, specific meaning reference man nm; The third column represents the symbol string.
This shows only the symbols that EXPORT_SYMBOL,EXPROT_SYMBOL_GPL has processed. 3.system.map Kernel Symbol File
You can view a list of kernel symbols through more/boot/system.map.
You can show all the symbols in the kernel after compiling the kernel, and see the modules separately. 4. The kernel symbol list can also be viewed through NM vmlinux
You can show all the symbols in the kernel after compiling the kernel, and see the modules separately. 5. Through NM module_name can view the symbol list of the module
But the resulting is a relative address, and only after loading will the absolute address be assigned. For example: e1000 module, if the symbol in the e1000 after Export_symbol processing, and so on loaded, we can through the More/boot/system.map and NM vmlinux command to see, but no export_symbol, I don't know how to look at the moment. Another experiment:
1. Verify Export_symbol
The module HELLO.C code is as follows:
1 #include <linux/module.h>
2 #include <linux/kernel.h>
3
4 static int __init a_init_module (void)
5 {
6 unsigned long *__kcrctab_per_cpu__hrtimer_bases = 0XC02678B4;
7 unsigned char *__kstrtab_per_cpu__hrtimer_bases = 0xc026926b;
8 struct Kernel_symbol *__ksymtab_per_cpu__hrtimer_bases = 0xc0265018;
9
PRINTK ("__kcrctab_per_cpu__hrtimer_bases =%08x/n", *__kcrctab_per_cpu__hrtimer_bases);
One PRINTK ("__kstrtab_per_cpu__hrtimer_bases =%s/n", __kstrtab_per_cpu__hrtimer_bases);
PRINTK ("__ksymtab_per_cpu__hrtimer_bases value =%08x, name =%s/n", __ksymtab_per_cpu__hrtimer_bases->value,/
__ksymtab_per_cpu__hrtimer_bases->name);
14
return 0;
16}
17
static void __exit a_cleanup_module (void)
19 {
PRINTK ("Bye, bye/n");
21}
Module_init (A_init_module);
Module_exit (A_cleanup_module);
The makefile configuration file is as follows:
1 #
2 # Makefile for hello.c file
3 #
4 kdir:=/lib/modules/$ (Shell uname-r)/build
5
6 OBJ-M:=HELLO.O
7
8 Default:
9 $ (make)-C $ (Kdir) subdirs=$ (PWD) modules
Ten clean:
$ (RM). *.cmd *.mod.c *.o *.ko-r. tmp* make; Insmod Hello.ko after the DMESG operation results:
__kcrctab_per_cpu__hrtimer_bases = 1ac19564
__kstrtab_per_cpu__hrtimer_bases = per_cpu__hrtimer_bases
__ksymtab_per_cpu__hrtimer_bases value = c0279ea0, name = Per_cpu__hrtimer_bases via nm vmlinux | grep per_cpu__hrtimer_bases We can see the following correspondence:
1ac19564 A __crc_per_cpu__hrtimer_bases
C02678B4 R __kcrctab_per_cpu__hrtimer_bases
c026926b R __kstrtab_per_cpu__hrtimer_bases
c0265018 R __ksymtab_per_cpu__hrtimer_bases
C0279ea0 d per_cpu__hrtimer_bases For example the last two columns of data.
This experiment is just to verify the Exprot_symbol.
The difference between 2.1.export_symbol and EXPORT_SYMBOL_GPL
Module 1:HELLO.C
1 #include <linux/module.h>
2 #include <linux/kernel.h>
3
4 void function1 (void)
5 {
6 printk ("Hello wold/n");
7}
8 Export_symbol (function1);
9
Ten void function2 (void)
11 {
PRINTK ("Hello Wold again/n");
13}
EXPORT_SYMBOL_GPL (function2);
15
16
The static int __init a_init_module (void)
18 {
return 0;
20}
21st
static void __exit a_cleanup_module (void)
23 {
PRINTK ("<1>bye, bye/n");
25
26}
27
Module_init (A_init_module);
Module_exit (A_cleanup_module);
Module 2:hello2.c
1 #include <linux/module.h>
2 #include <linux/kernel.h>
3
4//module_license ("GPL");
5
6 static int __init a_init_module (void)
7 {
8 function1 ();
9//function2 ();
Ten return 0;
11}
12
static void __exit a_cleanup_module (void)
14 {
PRINTK ("<1>bye, bye/n");
16
17}
18
Module_init (A_init_module);
Module_exit (A_cleanup_module);
First compile the following two modules: Hello.ko, Hello2.ko
A. Comment out the module_license ("GPL") and function2 () two lines in the hello2.c, Insmod Hello.ko then Insmod Hello2.ko, all normal.
B. Insmod Hello2.ko then Insmod Hello.ko, there will be an error message, through the DMESG view shows the following: Hello2:unknown symbol function1
C. Open function2 () in hello2.c, first insmod Hello.ko then Insmod Hello2.ko, module Hello2.ko cannot load, displaying the following information: Insmod:error inserting ' Hello2.ko ':-1 File exists, DMESG view shows as follows: Hello2:unknown symbol function2. Open the Module_license ("GPL") in the hello2.c or use Module_license ("Dual BSD/GPL"), Insmod Hello.ko then Insmod Hello2.ko, all normal.
Therefore, the EXPORT_SYMBOL_GPL symbol must be used Module_license ("GPL") or Module_license ("Dual BSD/GPL") before it can be referenced in the module. Also, the Char in Module_license ("char") cannot be any character, otherwise the error is the same as without the module_license effect.
D. Without looking at the Module_license kernel code, the next step is to read the code.