Analysis of Windows dynamic link library [DLL] and Linux shared library [so] technology

Source: Internet
Author: User

First, the technical advantages of dynamic link library:

1) Save memory and disk space, because a dynamic library can be used by multiple processes or programs in a single copy of memory or disk.

2) modular programming for easy collaboration; This static library is also capable.

3) when loading DLLs or so dynamically, it is easy to upgrade the module without recompiling or linking the entire program.

Second, the dynamic link library of Windows:

A static library of 1.windows generates a. lib file that contains functions and data entities that are linked to the program;

2.windows Dynamic library generates a. dll file and exports a. lib file, the function in the. lib file does not have an entity [not a

to be exact], the function inside is a jump that points to the functional entity in the. Lib, of course, the jump address in. Libs is a relatively

address [function at the DLL's offset]; A. dll file is an address that can relocate a file.

3. There are two ways to use a dynamic library:

1) Dynamic Link:

Link the. lib file exported by the dynamic library to the executable file.

When the program loads into memory, there will be a dynamic linker loading the dynamically loaded library into memory [already in memory without loading], at which time the. dll

The memory address determines that the dynamic linker changes the function jump address in the. lib section of the program to the original offset address plus the result of the. dll start address.

This will allow you to find the function location to invoke.

As for multi-process sharing of a dynamic library, each dynamic connector maps the address of the same library in memory to a different process space [virtual memory];

The addresses that map to the unused process space are likely to be different.

2) Dynamic loading:

That is, in the process of running the program to load the required library into memory [already exist without loading], through the corresponding API to get the required use of the dynamic

State Library function interface address, use function pointer way to use, after use, can dynamically unload dynamic library.

(*) Comparison of two ways:

(1) The first method requires the declaration of a function, a variable (that is, a header file in C + + +), and uses. lib to "spoof" the static linker;

The second method does not have a function declaration, the use of functions is the way to take a function pointer, so static linker can not "fault."

(2) The first method is the system to maintain dynamic library loading and unloading, the second requires the programmer to solve their own.

At the same time the first method of the dynamic library in the process space life cycle is the same as the program life cycle, the second is determined by the programmer.

(3) The first in the release of a new DLL, the corresponding LIB file to relink the program, the second is not required, just replace the old DLL .

third, the Linux shared library:  

  Linux shared libraries are essentially the same as Windows dynamic libraries, especially when dynamically loading. The difference is mainly reflected in the Linux shared library generated. So files will not

Also export a file similar to. lib.

If you want to use a dynamically linked method, you need to use a link to the. so file, but it does not actually link the file to the final executable file. It's just

Record the dependent on the. So file and record the symbols referenced in the. So to the list of symbols that need to be relocated [the list contains the relative addresses of each function].

When a program is loaded into memory space, similar to Windows, it is also determined. So the address of the relative address of the function and used to replace the function call in the program

Pin [After the program compiles the link, the function call is address jump].

Analysis of Windows dynamic link library [DLL] and Linux shared library [so] technology

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.