more linux kernel compile

Okyyyy, I found These information on https://www.tldp.org/LDP/lkmpg/2.4/html/x208.html.

#The problem is that these information seems a bit outdated.

“Kernel modules need to be compiled with certain gcc options to make them work. In addition, they also need to be compiled with certain symbols defined. This is because the kernel header files need to behave differently, depending on whether we’re compiling a kernel module or an executable. You can define symbols using gcc’s -D option, or with the #define preprocessor command. We’ll cover what you need to do in order to compile kernel modules in this section.

-c: A kernel module is not an independant executable, but an object file which will be linked into the kernel during runtime using insmod. As a result, modules should be compiled with the -c flag.

-O2: The kernel makes extensive use of inline functions, so modules must be compiled with the optimization flag turned on. Without optimization, some of the assembler macros calls will be mistaken by the compiler for function calls. This will cause loading the module to fail, since insmod won’t find those functions in the kernel.

-W -Wall: A programming mistake can take take your system down. You should always turn on compiler warnings, and this applies to all your compiling endeavors, not just module compilation.

-isystem /lib/modules/uname -r/build/include: You must use the kernel headers of the kernel you’re compiling against. Using the default /usr/include/linux won’t work.

-D__KERNEL__: Defining this symbol tells the header files that the code will be run in kernel mode, not as a user process.

-DMODULE: This symbol tells the header files to give the appropriate definitions for a kernel module.

We use gcc’s -isystem option instead of -I because it tells gcc to surpress some “unused variable” warnings that -W -Wall causes when you include module.h. By using -isystem under gcc-3.0, the kernel header files are treated specially, and the warnings are surpressed. If you instead use -I (or even -isystem under gcc 2.9x), the “unused variable” warnings will be printed. Just ignore them if they do.”

加载评论框需要翻墙