Description of the size of the MDK compiled file (program size ).

Source: Internet
Author: User
Ro, RW, and Zi data section in arm Compilation

Arm program (the program being executed in the arm system, rather than the binfile stored in the ROM)
An arm program contains three parts: RO, RW, and Zi segments.
Ro is the instruction and constant in the program.
RW is the initialized variable in the program.
Zi is an uninitialized variable in the program.
The above three points can be understood:
Ro is readonly,
RW is read/write,
Zi is zero.
Arm image file Composition
The so-called arm image file refers to the binary file burned into the ROM and also becomes an image file. The following is called an image file.
The image file contains Ro and RW data.
The reason why the image file does not contain the Zi data is that the Zi data is 0 and does not need to be included. You only need to clear the region where the Zi data is located before running the program. It wastes storage space.
Q: Why must image contain Ro and RW?
A: The commands and constants in RO and the initialized variables in RW cannot be "born out of nothing" like Zi.
Arm Program Execution Process
From the above two points, we can know that the image file burned to the Rom is not exactly the same as the actual running arm program. Therefore, it is necessary to understand how the arm Program reaches the actual running state from the image in the Rom.
In fact, commands in Ro should have at least the following functions:
1. Move RW from Rom to ram. Because RW is a variable, the variable cannot exist in Rom.
2. Clear all the ram regions where Zi is located. Because the Zi region is not in the image, the program needs to clear the desired Ram region based on the Zi address and size given by the compiler. Zi is also a variable. Similarly, the variable cannot exist in Rom.
At the initial stage of the program running, the C program can access the variables normally after the commands in RO Have completed these two tasks. Otherwise, only codes without variables can be run.
After talking about what Ro, RW, and Zi are, I will give a few examples to illustrate Ro, RW, what does Zi mean in C.
1; RO
Looking at the following two programs, there is a separate statement between them. This statement declares a character constant. Therefore, as we mentioned earlier, they should be only one byte different from RO data (the character constant is 1 byte ).
Prog1:
# Include <stdio. h>
Void main (void)
{
;
}
Prog2:
# Include <stdio. h>
Const char a = 5;
Void main (void)
{
;
}
After prog1 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ==========================================================
After prog2 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 61 0 96 0 grand totals
========================================================== ==========================================================
Total Ro size (code + RO data) 1009 (0.99kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1009 (0.99kb)
========================================================== ==========================================================
The information after the above two programs are compiled can be seen:
The RO of prog1 and prog2 contains two types of data: code and Ro data. Their only difference is that prog2's Ro data is 1 byte more than prog1. This is consistent with previous speculation.
If an instruction is added instead of a constant, the result should be the code data size difference.
2; RW
Let's look at the two programs again. There is only one difference between them: "initialized variables". According to the previous instructions, initialized variables should be included in RW, therefore, the size of RW is different between two programs.
Prog3:
# Include <stdio. h>
Void main (void)
{
;
}
Prog4:
# Include <stdio. h>
Char A = 5;
Void main (void)
{
;
}
After prog3 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ==========================================================
After prog4 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 1 96 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 97 (0.09kb)
Total Rom size (code + RO Data + RW data) 1009 (0.99kb)
========================================================== ==========================================================
It can be seen that the difference between prog3 and prog4 is indeed only one byte between RW data. This byte is caused by an initialized variable ".
3; Zi
Let's look at the two programs. The difference between them is an uninitialized variable "A". From the previous understanding, we can infer that there should be only a difference in the size of Zi between the two programs.
Prog3:
# Include <stdio. h>
Void main (void)
{
;
}
Prog4:
# Include <stdio. h>
Char;
Void main (void)
{
;
}
After prog3 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ==========================================================
After prog4 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 0 97 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 97 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ==========================================================
The compiled results fully conform to the assumption that only the size of the Zi data is 1 byte different. This byte is caused by an uninitialized trans variable ".
Note: If a variable is initialized to 0, the variable will be processed in the Zi region in the same way as the volume of changes not initialized.
That is, in the arm C program, all uninitialized variables are automatically initialized to 0.
Summary:
1. commands and constants in C are compiled into Ro data.
2. The variable in C that is not initialized or initialized to 0 is compiled with Zi data.
3. Variables initialized to non-0 values in C compile the RW Type data in the future.
Appendix:
Program compilation command (assuming the name of the C program is TST. C ):
ARMCC-c-o TST. o tst. c
Armlink-noremove-elf-nodebug-Info totals-Info sizes-Map-list AA. Map-o tst. Elf TST. o
The compiled information is in the AA. Map File.
Rom mainly refers to: NAND Flash, nor flash
Ram mainly refers to psram, SDRAM, SRAM, and ddram.
To put it simply, it is written in Flash: code + RO Data + RW data. When running: Ram: RW data + Zi data, of course, there must be a stack space. Ro, RW, and Zi data section in arm Compilation

Arm program (the program being executed in the arm system, rather than the binfile stored in the ROM)
An arm program contains three parts: RO, RW, and Zi segments.
Ro is the instruction and constant in the program.
RW is the initialized variable in the program.
Zi is an uninitialized variable in the program.
The above three points can be understood:
Ro is readonly,
RW is read/write,
Zi is zero.
Arm image file Composition
The so-called arm image file refers to the binary file burned into the ROM and also becomes an image file. The following is called an image file.
The image file contains Ro and RW data.
The reason why the image file does not contain the Zi data is that the Zi data is 0 and does not need to be included. You only need to clear the region where the Zi data is located before running the program. It wastes storage space.
Q: Why must image contain Ro and RW?
A: The commands and constants in RO and the initialized variables in RW cannot be "born out of nothing" like Zi.
Arm Program Execution Process
From the above two points, we can know that the image file burned to the Rom is not exactly the same as the actual running arm program. Therefore, it is necessary to understand how the arm Program reaches the actual running state from the image in the Rom.
In fact, commands in Ro should have at least the following functions:
1. Move RW from Rom to ram. Because RW is a variable, the variable cannot exist in Rom.
2. Clear all the ram regions where Zi is located. Because the Zi region is not in the image, the program needs to clear the desired Ram region based on the Zi address and size given by the compiler. Zi is also a variable. Similarly, the variable cannot exist in Rom.
At the initial stage of the program running, the C program can access the variables normally after the commands in RO Have completed these two tasks. Otherwise, only codes without variables can be run.
After talking about what Ro, RW, and Zi are, I will give a few examples to illustrate Ro, RW, what does Zi mean in C.
1; RO
Looking at the following two programs, there is a separate statement between them. This statement declares a character constant. Therefore, as we mentioned earlier, they should be only one byte different from RO data (the character constant is 1 byte ).
Prog1:
# Include <stdio. h>
Void main (void)
{
;
}
Prog2:
# Include <stdio. h>
Const char a = 5;
Void main (void)
{
;
}
After prog1 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ==========================================================
After prog2 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 61 0 96 0 grand totals
========================================================== ==========================================================
Total Ro size (code + RO data) 1009 (0.99kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1009 (0.99kb)
========================================================== ==========================================================
The information after the above two programs are compiled can be seen:
The RO of prog1 and prog2 contains two types of data: code and Ro data. Their only difference is that prog2's Ro data is 1 byte more than prog1. This is consistent with previous speculation.
If an instruction is added instead of a constant, the result should be the code data size difference.
2; RW
Let's look at the two programs again. There is only one difference between them: "initialized variables". According to the previous instructions, initialized variables should be included in RW, therefore, the size of RW is different between two programs.
Prog3:
# Include <stdio. h>
Void main (void)
{
;
}
Prog4:
# Include <stdio. h>
Char A = 5;
Void main (void)
{
;
}
After prog3 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ==========================================================
After prog4 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 1 96 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 97 (0.09kb)
Total Rom size (code + RO Data + RW data) 1009 (0.99kb)
========================================================== ==========================================================
It can be seen that the difference between prog3 and prog4 is indeed only one byte between RW data. This byte is caused by an initialized variable ".
3; Zi
Let's look at the two programs. The difference between them is an uninitialized variable "A". From the previous understanding, we can infer that there should be only a difference in the size of Zi between the two programs.
Prog3:
# Include <stdio. h>
Void main (void)
{
;
}
Prog4:
# Include <stdio. h>
Char;
Void main (void)
{
;
}
After prog3 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ==========================================================
After prog4 is compiled, the information is as follows:
========================================================== ==========================================================
Code Ro data RW data Zi data debug
948 60 0 97 0 grand totals
========================================================== ==========================================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 97 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ==========================================================
The compiled results fully conform to the assumption that only the size of the Zi data is 1 byte different. This byte is caused by an uninitialized trans variable ".
Note: If a variable is initialized to 0, the variable will be processed in the Zi region in the same way as the volume of changes not initialized.
That is, in the arm C program, all uninitialized variables are automatically initialized to 0.
Summary:
1. commands and constants in C are compiled into Ro data.
2. The variable in C that is not initialized or initialized to 0 is compiled with Zi data.
3. Variables initialized to non-0 values in C compile the RW Type data in the future.
Appendix:
Program compilation command (assuming the name of the C program is TST. C ):
ARMCC-c-o TST. o tst. c
Armlink-noremove-elf-nodebug-Info totals-Info sizes-Map-list AA. Map-o tst. Elf TST. o
The compiled information is in the AA. Map File.
Rom mainly refers to: NAND Flash, nor flash
Ram mainly refers to psram, SDRAM, SRAM, and ddram.
To put it simply, it is written in Flash: code + RO Data + RW data. When running: Ram: RW data + Zi data, of course, there must be a stack space.

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.