[Go]-C + + program startup process

Source: Internet
Author: User

First, the compile, link process.
1. Pre-compilation expansion macros
2. Compile a target file for each of the. cxx Source Files
3. The compiler synthesizes these target files into a library file, parsing the symbol references that can be found
4. The connector links the target library file with the static and dynamic link libraries of the required references, that is, the need to synthesize other static libraries into the executable file, convert the corresponding symbol references to addresses, and then ensure that the symbols of the other dynamic link libraries referenced are present. Finally, the executable file is generated.

The startup process for Windows programs
1. The operating system first creates the appropriate process and allocates the private process space, and then the operating system loader is responsible for mapping the data segments and code snippets of the executable file to the virtual memory space of the process.
2. The loader reads into the executable program's import symbol table, which can be used to find out all the dependent dynamic link libraries of the executable program.
3. The loader calls LoadLibrary for each dynamic link library of the program
(1) to find the corresponding dynamic library file, the loader determines an appropriate base address for the dynamic link library. If the base address is different from the base site that the dynamic link library wants to record, the loader does rebase for the library, and then the entire dynamic-link library is mapped to the virtual memory space of the process.
(2) The loader reads the Import symbol table and export symbol table of the dynamic link library, comparing whether the import symbols required by the application match the exported symbols of the library.
(3) for the library's Import symbol table, find the corresponding dependent dynamic link library, if there is a jump, then jump to 3
(4) Call the initialization function of the dynamic link library
4. Initialize the global variables for the application and call the constructors automatically for global objects.
5. Enter the application entry point function to begin execution

Linux
1. Input command, enter
2.exec system call takes over, prepares some environments for application run convenience love that, and find the appropriate interpreter for running commands.
3. The application interpreter is usually a part of the file that Ld,ld takes control and reads the executable program, including the file header and the shared object (so file)
4. For each dependent library, LD needs to read the first part of the file header and related information in this so, and then recursively find the other shared objects on which the shared object depends, up to the bottom.
5.LD will map all dependent so to the virtual memory of the program's process space (note that mappings are not read-in), because each shared object occupies a different contiguous region in the virtual memory space of the process, and their "base address varies", Thus, some of the symbols in the interior, which are represented by absolute addresses, need to be modified accordingly.
6. Initialize the application's global variables, for the global object Child Oh, the call constructor
7. Start execution from the entry function

[Go]-C + + program startup process

Related Article

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.