Linux compiled kernel

Source: Internet
Author: User

(1): Prepare the Linux host environment, install the development toolchain (description of the installation process of the low version of GCC):

In this experiment, I used the host environment is Ubuntu10.04, its own kernel is 2.6.26. The tools needed are Gcc4.1.3,qemu and sourceinsight.

The lower version of the GCC installation process:

First, enter in the terminal: sudo apt-get install gcc-4.1 g++4.1 linux-headers-$ (uname-r)

Then run a script file

This allows you to replace the Linux default GCC version with gcc4.1.3.

(2): Download and compile Linux-2.6.38 by default, success:

The operation is as follows:

The first step is to download the 2.6.38 kernel from the https://www.kernel.org/URL and unzip it;

The second step from the terminal into the linux-2.6.38, input: Make menuconfig, but immediately there will be a missing library file error, enter: sudo apt-get install Libncurses5-dev, you can install well;

The third step is to enter the system itself in the/boot folder, using the View hidden file operation to copy one of the hidden files config-2.6.32-38-generic file into the downloaded 2.6.38/boot folder, and modify the file name to. config;

The fourth step is to enter the linux-2.6.38 in the terminal, sequentially enter: Make, make modules (compile kernel module), make Modules_install (install kernel module), Mkinitramfs-o initrd.img-2.6.38 2.6.38, last update grub, input: sudo update-grub.

(3): Install the source code reading tool, recommend Sourceinsight, and based on the compiled Linux-2.6.26 source code, the establishment of LINUX-2.6.26 code project:

      • Use Sourceinsight to create a file management function using Sourceinsight to remove the source code of other architectures that are not x86 in the Arch directory and the Include directory
      • Use other source reading tools, but you can.
      • To be able to see several makefile files
      • To be able to see several *.lds files

(4): The use of tools in the host environment to recompile test.c and disassembly, observe the function call frame formation, parameter transfer, return value of the transfer and the definition of local variables, compared with the classroom explanation of what is the difference:

Disassembly code, the first is the split zone initialization, the initialization of the data for the stack operation

After editing the program, first the register ESP is zeroed, and then into the test's main function body, first call the Add function

mov%eax,-0xc (%EBP)

MOV-0XC (%EBP),%eax

mov%eax,0x4 (%ESP)

Movl $0xb, (%ESP)

After execution, return to the main function, returning the result to the register eax, and then calling the printf function to print the result. Then assign the value to the ESP to find the code address to run below. and then call minus.

Function.

By observing disassembly, the disassembly code first initializes the data stack, then compiles the link, then executes the main function, calls the other functions within the function, forms the function call frame, and pushes the stack out of the data, returns the main function, and assigns the result to the general register. Return to the scene to continue execution.

The function framework initializes the partition, invokes the function order, and ends the processing. Parameter passing is the use of the stack operation, and the move function. The return is also passed to the register output by the move operation. Local variables are assigned to the General register, and the value of the universal register is ejected or re-assigned when the data is no longer used.

(5): Try the optimized compilation of GCC, use the time command to get their respective runtime and make a simple comparison to the executable files with different optimization compilation options:

Download $ time./m0

Real 0m18.474s

User 0m18.397s

SYS 0m0.024s

[Email protected]:~/download $ time./m1

Real 0m0.001s

User 0m0.000s

SYS 0m0.000s

[Email protected]:~/download $ time./m2

Real 0m0.001s

User 0m0.000s

SYS 0m0.000s

[Email protected]:~/download $ time./m3

Real 0m0.001s

User 0m0.000s

SYS 0m0.000

Thus, the optimization of the compiler can really give a great boost to the operating efficiency of the program, in the use of M1 optimization, is the most obvious efficiency improvement, the latter m2,m3 efficiency is not very large. I analyze the reason may be that the test program is too simple, so that system optimization can not fully play its due effect.

Linux compiled kernel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.