1. Composition of target files
A binary file is made up of a series of segments, and of course there are some symbols, memory allocation, etc. The link text can actually give you a rough idea of the program's composition. The same segments of each target file are combined to achieve the link of the executable program. Of course, the specific linking methods and principles are designed by the tool. For example, the linking order follows the input order, etc.
I remember that in the process of porting u-boot to TQ2440, I had modified the link text, that is, the u-boot.lds file. At that time, I added a function about nand flash operation. In order to ensure that the added function would not be placed before the startup code during the link process and cause problems with the chip startup, I deliberately modified the link order of the program to ensure that the link document was correctly linked.
1. [root@Gong-Computer u-boot-2010.06]# vi arch/arm/cpu/arm920t/u-boot.lds
2. . = ALIGN(4);
3. .text:
4. {
5. arch/arm/cpu/arm920t/start.o (.text)
6. board/samsung/smdk2440/lowlevel_init.o (.text)
7. board/samsung/smdk2440/nand_read.o (.text)
8. *(.text)
9. }
The basic contents of the binary file mainly include several segments. Of course, some other conditions are required. In the linking process, it seems that some C language running environment is also needed, which is mainly used to control the startup and shutdown of the program. These are all implemented by crt* (C RunTime) target files. These target files are not often seen in our program design. If you analyze the compilation process of u-boot, you will find that these target files do exist.
Link text makes file linking more convenient and practical. Therefore, it is very necessary to understand the most basic paragraphs of the target.
A few points to note:
1. Static variables, whether local or global, are in the data segment, unlike local variables in the stack. When the stack is popped, the contents are released, and the static variables will not change. However, local static variables can only be accessed by the function that defines the variable, and cannot be accessed by other functions.
2. If global variables and static variables are initialized to 0 or not initialized, the variable is allocated to .bss (uninitialized part). Only when global variables and static variables are initialized to non-zero values will they be allocated to the .data segment.
3. If global variables and static variables are not initialized, they will generally default to 0. This is why these two numbers are still in the .bss section even if they are initialized to 0. Therefore, you need to pay attention to the values of global variables and static variables when they are not initialized, but there is no such feature for local variables. If they are not initialized, a random value will appear.
The above conclusions can be manually tested through code.
2. Program structure in Linux
In Linux, each process has a 4G virtual space, of which the first 3G is the user space and the last 1G is the kernel space. The 4G space is independent of each process. However, the area allocation of these memory spaces is indeed the same, and the starting address of each area is also fixed. The structure of a Linux program is as follows:
Since the starting address of each segment is fixed, it is convenient to map the virtual address to the physical address, which facilitates the loading of the program, especially the implementation of shared libraries.
3. Stack and Heap
In fact, I had a big misunderstanding of these two concepts at the beginning. I didn't understand the relationship between them. I always understood the stack as a heap and a stack. In fact, the stack refers to the stack. Once you understand this, it's easy to understand the difference between the two. The stack can actually be considered a data structure with a typical first-in, last-out feature.
Generally speaking, the stack grows in reverse, that is, from high address to low address, but there are other growth modes, such as ARM has 4 different growth modes, so the growth direction of the stack can only be determined by the CPU, and the stacks of different CPUs may be different. The stack is mainly used to implement function calls.
The heap is generally located above the bass segment, and is mainly used to implement dynamic memory allocation and release. In C language, it is mainly implemented through malloc/free functions, and in C++, it is mainly implemented through new/delete. However, this block of memory is usually continuously allocated and released and meets the basic alignment form, which leads to memory fragmentation and reduces the access rate. At the same time, because of the problems of zero space application in this area and the pointer is still valid after release, the pointer is usually pointed to NULL after release.
Previous article:Several magical uses of gcc
Next article:Synchronous and asynchronous IO, blocking and non-blocking IO
- Popular Resources
- Popular amplifiers
- Setup_SmartRFProgr_1.12.7.rar
- It s an interface for using huffman trees (data structure application) that can be used for compress
- Design and application of USB peripheral devices for EZ-USB FX series microcontrollers
- The program was written with some object-orientation in mind, which means that all functions that operate
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Why do clocks use 32.768K crystals?
- Problems and Solutions in TMS320F206 Simulation Debugging
- DCDC input end inrush current problem
- Smart Home Series Articles | Battle for Control: Who is the control center of the smart home system?
- EEWORLD University Hall----Live Replay: MCU programming is no longer difficult, use MPLAB? Code Configurator (MCC) to achieve rapid development
- Understanding of the working principle of single chip microcomputer
- Talk about the basic structure of MSP430 program library
- Why can't the mobile and computer versions be horizontal?
- How to determine the device address of an I2C slave?
- EEWORLD University Hall----Automatic Control Theory Tsinghua University