Learn about Dynamic Links (2) -- Address-independent code and Dynamic Links

Source: Internet
Author: User

Learn about Dynamic Links (2) -- Address-independent code and Dynamic Links

Remove the part of the instruction that needs to be modified and place it in the Data zone to keep the instruction part unchanged. Each process can have a copy of the data part. This is the Position-independent Code (PIC). The advantage is that the commands are shared by multiple processes to save memory.

To implement PIC, you must solve the address location problem in the instruction. The address reference in the command can be divided:

1. function calls and variable access within the module;

2. function calls and variable access outside the module.

In 1st cases, since we all define in the same module and there is a certain relative position between them, we can solve the problem by calling the relative address.

In 2nd cases, for external access to the module, a global Offset Table (GOT) needs to be created in the data area to store the addresses of external variables or functions. Of course, the addresses in the GOT table need to be filled by the linker when the module is loaded and the addresses are relocated. In this way, you can first find the related items in the GOT table through the relative address for external symbol access in the command, and then obtain the specific address of the target variable or function.

In the Android system, there are two relocation tables for external variables and function references, so we call soinfo_relocate two consecutive times to relocate:

Finally, use "readelf-d xxx. so | grep TEXTREL "command to view xxx. so is PIC, because so does not contain any code segment to relocate the table, so there is no output.

Learning Materials: programmer self-cultivation-links, loading and libraries

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.