7.6. Handling data accesses between modules

Accessing data between different modules is a similar problem to resolving function calls between modules, because at static link time the addresses of the data are unknown to the static linker and must be handled by the dynamic linker.

When accessing a data item from another module, the object producer must add an extra level of indirection to the data access. This allows the use of a table of addresses to store the actual address to be accessed, this table is known as the Global Offset Table (GOT).

In a statically linked image on an ARM processor, one level of indirection is used, for example:

    LDR   r0, [X]
    LDR   r0, [r0]
X   DCD   &Data

In this example, the address where the data is stored is known at static link time and is stored at the literal pool labeled X. For a dynamically linked image, the address where the data item is stored is not known, but the location in the GOT is known. Therefore the object producer must add an extra level of indirection. For example:

    LDR   r0, [X]
    LDR   r0, [r0]
    LDR   r0, [r0]
X   DCD   &GOT_Entry

This code generates the following sequence of operations:

  1. The first instruction loads the contents of the literal pool. That is, the GOT location.

  2. The second instruction loads the address from the GOT.

  3. The third instruction loads the actual data.

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