7.5. Handling function calls between modules

Because the execution addresses of different modules are not normally known until execution time, any function calls between the modules must be handled by the dynamic linker. To allow this the static linker generates relocations to be processed by the dynamic linker. The static linker might also insert code sequences known as PLT entries for the function calls (code generation for intra-call veneers). Whether the PLT entries are required is defined by the particular platform or operating system and is normally controlled with a linker command-line option.

Without PLT entries (using the --pltgot=none linker command-line option) the job of the static linker is not as complicated. However, the dynamic linker is restricted to loading the shared library to within the branch range of any application that wishes to call functions within that shared library. Also, the dynamic linker must resolve dynamic relocations for each instance of a function call. For example, if an application calls a shared library function bar eight times, the dynamic linker must resolve eight dynamic relocations.

PLT entries are commonly used because they can simplify the dynamic linking process. For an application that uses a function like bar from Example 7.1, the dynamic linker only needs to resolve a single relocation for its PLT entry. A PLT entry is a small piece of code inserted by the linker that can branch to anywhere in the 32-bit address range of the ARM CPU. It is effectively a long-branch veneer inserted between the caller and the dynamically imported callee or destination.

A PLT entry is made up of code inserted by the linker, a data entry, and a relocation. The data entry contains the address to branch to, and the relocation is against this location to allow the dynamic linker to enter the correct address. This means the dynamic linker only needs to insert the address of the target into the data entry and does not need to be concerned about calculating PC offsets or handling when the target function is out of direct branch range.

There are a number of different types of PLT entries. The instruction sequence generated and also where the data item is stored varies between the PLT types. Two of the most common are direct and indirect PLTs.

Copyright © 2010 ARM. All rights reserved.ARM DAI 0242A