ARM compilation Space Properties

Source: Internet
Author: User

Original address: http://www.cnblogs.com/hongzg1982/articles/2205093.html

1. Spatial properties of the program

In general, a program is essentially composed of BSS, data, text three-the concept of the current computer programming is a very important basic concept. It is also very important in the design of embedded system, which involves the allocation of memory size and the size of storage unit in the runtime of embedded system.

BSS segment : BSS segment (BSS segment) usually refers to an area of memory that is used to store uninitialized global variables in the program. BSS is the abbreviation for English block Started by symbol. BSS segments belong to static memory allocations.

Data Segment : Data segment usually refers to an area of memory that is used to hold the initialized global variables in the program. The data segment belongs to static memory allocation.

Code Snippets: Code segment/text segment usually refers to an area of memory that is used to store program execution code. The size of this area is determined before the program runs, and the memory area is usually read-only, and some schemas allow the code snippet to be writable, which allows the program to be modified. In a code snippet, it is also possible to include some read-only constant variables, such as String constants.

Heap : A heap is used to store a dynamically allocated memory segment in a process run, which is not fixed in size and can be dynamically expanded or scaled down. When a process calls a function such as malloc to allocate memory, the newly allocated memory is dynamically added to the heap (heap is expanded), and freed memory is removed from the heap when memory is freed (heap is scaled down).

Stack Stack: Stacks are also known as stacks, which are local variables that are temporarily created by the user's stored program, that is, the variables defined in the parentheses "{}" (but not the static declared variables, static means that the variables are stored in the data segment). In addition, when a function is called, its arguments are also pressed into the process stack that initiates the call, and the return value of the function is stored back to the stack when the call ends. Due to the advanced first-out features of the stack, the stack is particularly handy for saving/recovering call sites. In this sense, we can think of the stack as a memory area where temporary data is stored and exchanged.

Both the text and data fields are in the executable file (typically cured in an embedded system in an image file) and are loaded from the executable file by the system. The BSS segment is not in the executable file and is initialized by the system.

A BSS segment (data that is not manually initialized) does not allocate space to the data for that segment, but only the amount of space required to record the data. Data (data that has been manually initialized) segments are allocated space and the data is saved in the destination file. The data segment contains the initialized global variables and their values. The size of the BSS section is obtained from the executable file, and then the linker gets a block of memory of that size, immediately following the data segment. When this memory area enters the program's address space, it is all zeroed out. The entire segment that contains data and BSS segments is often referred to as the data area.

2. Arm's Image property

The composition of the ARM program
The "arm program" here refers to the program being executed in the arm system, not the bin image (image) file that is stored in the ROM, which is a clear note of the difference.
An arm program consists of 3 parts: Ro,rw and Zi
RO is the instruction and constant in the program
RW is an initialized variable in the program
Zi is an uninitialized variable in the program
The image file contains RO and RW data. But does not contain the Zi data, because the Zi data are all 0, does not need to contain, as long as the program runs before the Zi data in the area of the clear 0. Instead, it wastes storage space.

The image file burned to ROM is not exactly the same as the actual running arm program. It is therefore necessary to understand how the ARM program gets to the actual running state from the image in ROM.
In fact, the directives in RO should have at least one of these features:
1. Move RW from ROM to ram because RW is a variable and the variable cannot exist in ROM.
2. Clear the Ram area where the Zi is located, because the Zi area is not in image, so the program needs to clear the corresponding RAM area according to the Zi address and size given by the compiler. Zi is also a variable, the same way: The variable can not exist in ROM in the initial stage of the program, the RO instructions to complete the two work after the C program to access the variable normally. Otherwise, you can only run code that does not contain variables.
The instructions and constants in ARM C are compiled with RO type data.
Variables in ARM c that have not been initialized or initialized to 0 are compiled with Zi type data.
The variables in ARM c that have been initialized to a value other than 0 are compiled with the future RW type data.

The . Text segment is a code snippet. It is used to put the program code. It is usually read-only (program code, compiled OK, it is not possible to change to change).

The . data segment is a data segment. It is used to store the initialized (initailized) global variable (global) and the initialized static variable (static). It is readable and writable.

The . BSS segment is a global variable data segment. It is used to hold uninitialized (uninitailized) global Variables (global) and uninitialized static variables (static). It is also readable and writable. BSS is an abbreviation for English block Started by symbol. The reason to separate BSS from data is because the system will clear the initial values of the variables for these BSS segments.

The . Constdata segment is a constant data segment. It is used to store constants (const). It is also read-only.

The memory allocated by malloc in the source program is the BSS, and its size is not determined by the size of the data, but is determined by the maximum amount of memory allocated at the same time in the program, but if the scope is exceeded, that is, the allocation fails, it can be allocated after the space is freed.

These paragraphs allow the user to define their first address and size very flexibly. For most users, however, the program code area is in ROM or flash, and the read-write area is in SRAM or DRAM. Consider the size of your program, function call size, memory usage size, and then, refer to a connection location file, a little modification can be

Stack ( Stack ) is usually what we call a stack. It is used to hold local variables and parameters of the function. It operates in a way similar to a stack in a data structure, and is a "last-in, first-out" (last-in Out,lifo). This means that the last data placed on the stack will be the first data to be moved from the stack, which is ideal for temporarily stored information, and for information that does not need to be saved for a long time. When a function or procedure is called, the system usually clears the stored local variables, function call information, and other information on the stack. The top of the stack is usually at the end of the read-write Ram area, where the address space is usually "down", which means that the more data is stored on the stack, the smaller the stack's address.

Heap ( Heap ) Is the dynamic memory allocation that we usually say . It is used to manage dynamic memory. The way it works is different from the heap in the data structure.

In the integrated development environment of ARM,

1. The read-only snippet is called the code segment, which is the . Text segment above.

2. The read-only constant data segment, called the RO data segment, is the above . Constdata segment.

The above two paragraphs collectively referred to as the RO section (Read only), placed in the ROM or flash and other non-volatile devices.

3, readable writable initialized global variables and static variable segments, known as the RW Data segment (ReadWrite), that is, the above . BSS segment.

4, the readable writable uninitialized global variable and the static variable segment, is called the ZI data segment (Zero Init), namely the above . Data segment. Because the variable in this paragraph is initialized to zero, it is called the Zi segment.

The above two segments are collectively known as RW segments, and at run time it must be reloaded into readable writable RAM.

Arm compilation Space Properties (RPM)

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.