The term BSS (block started by symbol) was initially a pseudo command in the UA-SAP assembler (United aircraft symbolic assembly program) to reserve a piece of memory space for the symbol. The assembler was developed by United Airlines for the IBM 1950s mainframe in the middle of 704. Later, the word BSS was introduced to the standard assembler FAP (Fortran assembly program) on IBM 709 and 7090/94 models as a keyword to define the symbol and reserve a given amount of uninitialized space for the symbol. UNIX
FAQ section 1.3 (http://www.faqs.org/faqs/unix-faq/faq/part1/section-3.html) contains an explanation of the origins of the word BSS by Dennis rithcie, father of UNIX and C language.
Generally, after the C language is compiled, all statements are compiled into machine code and saved in. text Segment; initialized global variables and local static variables are saved in. data Segment; uninitialized global variables and local static variables are generally put in. in the "BSS" section. We know that the default values of uninitialized global variables and local static variables are both 0. They can also be placed. data Segment, but because they are all 0. it is unnecessary to allocate space for data segments and store data 0. When the program runs, they really occupy the memory space, and the executable file must record all uninitialized global changes.
Total volume and local static variable size, recorded as. BSS segment. Therefore, the BSS segment only reserves a location for uninitialized global variables and local static variables. It does not have any content, so it does not occupy space in the file.
The data segment contains the initialized global variables and their values. The size of the BSS segment is obtained from the executable file, and then the linker obtains the size of the memory block, followed by the data segment. When this memory area enters the address space of the program, all are cleared. The entire section that contains the data segment and BSS segment
This is usually called a data zone.
In an architecture that adopts segmented memory management (such as Intel's 80x86 system) and BSS segment (block started by symbol segment) it is usually a memory area used to store uninitialized global variables in the program. Generally, the BSS segment is cleared during initialization. The BSS segment is a static memory allocation, that is, the program clears it from the beginning.
For example, after a program such as C language is compiled, initialized global variables are saved in the. Data Segment, and uninitialized global variables are saved in the. BSS segment. In programming ground up. the BSS is interpreted as: there is another section called. BSS. this section is like the data section, Except t that it doesn't take up space in
Executable. both the text and data segments are in the executable file (which is usually fixed in the image file in the embedded system) and loaded by the system from the executable file; the BSS segment is not in the executable file and is initialized by the system.
In general, the program source code is divided into two types after compilation: program instructions and program data. Code segments are program instructions, while data segments and. BSS segments are procedural data. Many may have questions: why is it so troublesome to separate program commands from data storage? Isn't it easier to put data in a segment in a hybrid manner? In fact, data and command segmentation have many advantages. It mainly includes the following aspects.
Reason for separating program commands and data:
On the one hand, after a program is loaded, data and commands are mapped to two virtual storage regions respectively. Because the data area is read-only for the process, and the command area is read-only for the process, the permissions of the two virtual storage areas can be set to read-write and read-only respectively. This prevents program commands from being rewritten intentionally or unintentionally.
On the other hand, for modern CPUs, they have extremely powerful cache systems. Because caching plays an important role in modern computers, programs must try to increase the cache hit rate. The separation of the command zone and data Zone helps improve the program locality. The cache of modern CPUs is generally designed to separate the data cache from the instruction cache. Therefore, separating the instructions and data of programs improves the slow memory hit rate of the CPU.
The third reason is, in fact, the most important reason: when the system runs multiple copies of the program, their commands are the same, therefore, you only need to save a copy of the instruction in the memory. This is true for read-only areas such as commands, and also for other read-only data. For example, resources such as icons, images, and texts contained in many programs can also be shared. Of course, the data regions of each replica process are different. They are private. Don't underestimate the concept of this shared command. It occupies an extremely important position in modern operating systems, especially in systems with dynamic links, which can save a lot of memory. For example, Windows
After Internet Explorer 7.0 runs, its total virtual storage space is 112 844 kb, and its private data is 15 944 KB, A 96 900 kb space is shared (the data source is shown in Figure 3-2 ). If hundreds of processes are running in the system, you can imagine a shared approach to save a lot of space. More in-depth information about Memory sharing will be discussed in the loading section.