Chapter 4. How is dynamic linking different to static linking?

To successfully create a statically linked image, the linker must ensure that the image produced contains all the functions and variables required for that image by resolving every reference to a definition. The linker has information on the memory layout. Therefore it can locate all the code and data as required. This not only allows the linker to ensure that all the required code and data is linked into the image, but also allows it to resolve all the relocations in the image. The final image that is produced can then be loaded directly into memory and executed without any need for further processing.

However, in a dynamically linked environment, the code and data spreads over a number of different modules. For a particular application to execute, it might have to use the code and data from one or more of these modules.

The execution addresses of the various modules are not known until they are loaded onto the platform. This means the static linker cannot resolve the references and relocations between different modules. Therefore, before the image is executed on the platform, a further link step is required to handle the references and relocations between the different modules/images. This link step is known as dynamic linking.

The job of both the static and dynamic linker is to bind the symbolic references present in code and data to real addresses that can be executed at run-time. Binding symbolic references at static link time is typically efficient at run-time, but inflexible. Binding symbolic references at dynamic linking is more flexible but less efficient.

There are a number of places that the dividing line between the programs can be drawn. At one extreme we have all static linker and no dynamic linker when there is no run-time loading of code. At the other extreme there is no static linker and every symbolic reference is bound by the dynamic linker, either at load-time or even on demand. However, the majority of platforms have both a static and dynamic linker to allow a blend of flexibility and efficiency.

Another way of thinking about it is that dynamic linking is the completion of decisions deferred from static link time. The static linker has to encode enough information in the dynamic segment for the dynamic linker to resolve these decisions.

This section includes:

Copyright © 2010 ARM. All rights reserved.ARM DAI 0242A
Non-ConfidentialID011411