A program contains data segments, code segments, and BSS segments. The BSS segment stores some uninitialized static and global variables. to properly use the memory, the BSS segment does not exist in the. binfile compiled at the end. In response to this question, I personally asked myself. The following answers are based on my understanding. I may describe some questions, or I may not understand them. I hope some friends can tell me this. Thank you!
1. Since the BSS segment does not exist in the final compiled file, what is the role of BSS?
A: After the program compiles the link, the command code will instruct you to access the addresses of non-initialized global and static variables. when compiling the link, therefore, the address corresponding to the BSS segment is still assigned to these variables, and the role of BSS is to provide the start_bss and end_bss addresses.
2. Since BSS has been cut down, how can we get the start_bss and end_bss addresses from the program?
A: The same is true. The program will specify two addresses during compilation, so even if there is no BSS, these two addresses are already written into the machine code during compilation. In other words, compile the program first, and then cut down the BSS. Check out makefilearm-linux-ld-T leds. lds-o led. elf start. o led. o
Arm-linux-objcopy-O binary led. elf led. bin does.
3. Why should I use a program to clear BSS?
Answer: as described above, BSS is cut down after compiling the binfile. After the program is burned into the memory, the content in the memory of the corresponding BSS is unknown, so we must manually clear it.