Go to the private kitchen of laruence Linux
You can find the original connection in pdf format on this blog.
For developers who design embedded Linux systems, there is a problem that must be tested.
The blank space of the system.
We know that the embedded Linux system does not use audio disks, hard drives, zip drives, CD-Rom, or DVDs.
Some? The large-capacity, regular-purpose memory, such as Rom, compactflash, and m-systems.
Diskonchip, Sony's memorystick, IBM's microdrive and other software components are small, with the BIOS on the motherboard
The memory size is similar. Therefore, it is very important to save the space possible.
Embedded systems include internal cores, file systems, embedded systems, and self-developed programs.
This article starts with a program and uses a very simple C program? For example, you can fatalize it in three steps.
Hello. C:
# Include <stdio. h>
Int main ()
{
Printf ("Hello, world ");
Return 0;
}
We first use the normal program upload method to compile the program to see how much the generated program is.
# Gcc-O hello. c
# Ls-l Hello
-Rwxr-XR-x 1 Root 11542 Nov 13 hello
From the result, we can see that the program size after the successful failover is 11542 bytes.
Now let's start our three-step program to see how it works.
Step 1: Use GCC to compile data
The token generator is used to analyze the source token and find out the parts that have not yet been reached the maximum value. Then
The new line combination aims to improve the program's parallel line performance. GCC provides a very large number of built-in functions.
In the past, artificial intelligence election-on is used to control the generation of evolutionary tokens, where n is an integer that represents linear regression. Not
For GCC of the same version, the value of N for response encoding and the effect on response may not be exactly the same.
The failover duration is changed from 0 to 2 or 3.
When selecting-o, you can tell GCC about the length and duration of the minor generation during the same time, and the effect is equal
-O1. The optimized type that can be implemented in this category is determined by the target processor, but it generally includes
Thread jump and deferred stack pops. Select-O2
Tell GCC not only to complete all-O1 encoding, but also to perform some extra compaction work at the same time, such
Processor command degree. Selecting "-O3" includes not only completing all-O2 except regionalization, but also the development of the circle and
Other chemical work related to processing device features. Generally, the larger the number, the higher the classified value.
This means that the program runs faster. Many Linux programs prefer the-O2 option, because? It is in
The time between growth, growth, and generation has achieved an ideal balance point.
# Gcc-O2-O hello. c
# Ls-l Hello
-Rwxr-XR-x 1 Root 11534 Nov 13 hello
The size of the converted program is 11534 bytes, which is smaller than the result of the normal response.
This is the first step. Let's proceed.
Step 2: Use the Strip command
We know that binary programs contain a large number of symbol tables. Are some of them used?
GDB does not provide the necessary assistance for the division of workers. You can view these token information through readelf-s.
# Readelf-s hello
Section headers:
[Nr] Name type
[0] Null
[1]. interp progbits
[2]. Note. Abi-tag note
[3]. Hash hash
[4]. dynsym
[5]. dynstr strtab
[6]. GNU. Version versym
[7]. GNU. version_r verneed
[8]. Rel. Dyn REL
[9]. Rel. PLT REL
[10]. init progbits
[11]. PLT progbits
[12]. Text progbits
[13]. Fini progbits
[14]. rodata progbits
[15]. eh_frame progbits
[16]. Data progbits
[17]. Dynamic dynamic
[18]. ctors progbits
[19]. dtors progbits
[20]. JCR progbits
[21]. Got progbits
[22]. BSS nobits
[23]. Comment progbits
[24]. debug_aranges progbits
[25]. debug_pubnames progbits
[26]. debug_info progbits
[27]. debug_abbrev progbits
[28]. debug_line progbits
[29]. debug_frame progbits
[30]. debug_str progbits
[31]. shstrtab strtab
[32]. symtab
[33]. strtab
Similar to. debug_xxxx, it is used for GDB to remove objects. Removing them not only does not affect the login line of the program, but also
To parse the size of a small program. In this case, we can remove them through the Strip command.
# Strip hello
# Ls-l Hello
-Rwxr-XR-x 1 Root 2776 Nov 13 hello
The program immediately changes to 2776 bytes. Let's continue and proceed to the last step.
Step 3: Use the objcopy command
The strip command in the previous step can only remove the general symbol table, but some information has not been removed yet.
Which of the following statements does the program have? Shadow. For example:. comment;. Note. Abi-tag;. GNU. Version
It can be completely removed. So we can use the objcopy command to compile the program.
Extracted.
# Objcopy-R. comment-R. Note. Abi-tag-R. GNU. Version Hello hello1
# Ls-l hello1
-Rwxr-XR-x 1 Root 2316 Nov 13 hello1
In this step, the program will be completed, and we can see that the program runs from 11542 bytes of normal memory at once.
The effect is very clear when the limit is less than 2316 bytes.
Summary
A small program capacity is undoubtedly important to the design of embedded Linux systems? We have saved a lot of trouble.
Space, so that we can use this space to improve our systems, such as increasing the number of cores.
It is our ultimate goal.
Author's suggestion
Name: Raytheon
Work Unit: technical upgrade Main Board (danzhou) Development Center
Address: Department of R & D center, Ma Yun Road, danzhou 215000
E-mail: tigerleihm@yahoo.com.cn
"The author of this article is the engineering workshop of the R & D center of Record Filing Technology Board (danzhou. He is currently on the Main Board of technical promotion in danzhou, China
(Danzhou) development center work. He can communicate with him through the tigerleihm@yahoo.com.cn ."