Android Linker (1)--__linker_init ()

Source: Internet
Author: User

__linker_init () at begin. S is called and passed in two parameters: SP (stack pointer), #0.

The linker (dynamic linker, also known as the interpreter) itself is also a shared object,__linker_init () responsible for initializing linker, completing linker relocation, and so on. Any reference to an external variable or function will produce segfault because the relocation of linker has not been completed (got is not yet available) before calling __linker_init ().

Since the relocation of the linker is done by itself, the process is called Bootstrap (Bootstrap).

The first step of the __linker_init () is to break down the parameters, and the argc, argv, environment variables, and ELF aux vectors that are passed in by the SP parameters are loaded into the corresponding members of the Kernelargumentblock object for easy access.

In the AUXV array, items of type at_base are stored with the start address of the linker mirror. __linker_init () gets linker_addr, and the address of the ELF_HDR (elf header) and PHDR (program header) are obtained.

__linker_init () then populates a SOINFO structure variable.

The member flags are set on Flag_linker, and the debug information is not printed after this tag, because those debug functions are not available until LINKER completes the relocation.

Phdr_table_get_load_size () calculates the size of the entire linker image by locating the maximum address and minimum address of the segment memory according to the program header, subtracting after the completion of the page alignment.

Get_elf_exec_load_bias () Gets the linker load address in memory, which is actually the first loadable segment (pt_load) in-memory virtual address.

__linker_init () then takes Linker_so as a parameter, calling Soinfo_link_image ().

Find the address of the dynamic link segment (pt_dynamic) in Soinfo_link_image () and get the number of dynamic link structures. It then iterates through all the dynamic link structures, fetching important information such as "string table address", "Symbol table address", "Relocation table Address", and fills in the corresponding members of the SOINFO structure. It then loads all dependent libraries, but in fact it does not depend on any other shared object during the linker bootstrap process. Relocation work is also done in Soinfo_link_image (), including Rel and Plt_rel (the relocation item associated with the PLT).

__linker_init () finally calls __linker_init_post_relocation (), which, from the name, shows that the work that needs to be done after relocation is done in this function.

__linker_init () Finally returns the entry address of the mirror, the e_entry saved virtual address in the ELF header.

Android Linker (1)--__linker_init ()

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.