Relocatable target file (multiple expert answer version, not integrated) __the

Source: Internet
Author: User
Tags glob

A/C + + program to be preprocessed, compiled, compiled and connected four steps to generate executable files, the third assembly generated after the. o file that is obj file, also known as relocatable target file, where the relocatable how to understand.
In short, that means the code snippet and the address of the data in the file are not finalized.
The target file generated by the compiler is a relocatable program module and cannot be run directly, and the link is the process by which the target file and other compiled program modules (if any) and the standard library functions provided by the system are connected together to generate a runnable executable file.
Relocation is the linker after the completion of the symbol parsing (know the input module of the code segment and the size of the data segment) a step, its role as the name implies is relocation, to determine such as directives, global variables, such as the memory address at runtime.
For example, two compiled relocatable target files obj1.o and OBJ2.O
Within the OBJ1.O, a global variable glob (the relative address of glob relative to the data segment of the file is recorded in Obj1), and obj2.0 is referenced in this global variable glob.
The relocation of a link is to determine the address of the glob in a linked executable program, rather than the obj1 address, so that obj2 can also invoke glob by address.

Of course, the relocation is not just a global variable, but also includes external functions, instructions, and other Run-time address determination
When you write a global variable or a function in a program, the location process goes through several stages:
1. Relative positioning in this target file, a target file will be all functions in this file, variables for symbolic description, such as a variable a, its relative address is how much. Is global. Or it's static, or it's external.
2. When you connect multiple targets into an executable file, you reposition the variable again, describing the variable in the executable file, similar to the description in the target file, except that the variable has no external, internal, and local variables. All global variables are stored in a logical address, which is determined by connecting the script files to the relative addresses in each target file.
3. When the final operating system loads the executable, the variables and function addresses are repositioned again, by first analyzing the different segments in the executable file, reading the corresponding description table, and mapping the logical address to the physical address. In the end, the executable binaries are added to the real physical memory, and the conversion of the executable file format to the physical address is different between the CPU and the operating system.

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.