Accessing data through the toc entry with the te storage-mapping class

The TE storage-mapping class is used to access external data.

As is the case with the TC storage-mapping class, the TE storage-mapping class can be used to access external data. An external data item is accessed by first loading that item's address from the TOC, and then using that address to get the data. To avoid the generation of TOC-overflow code, the TE symbol is loaded from the TOC with a two-instruction sequence as shown in the following example:

       .toc
       .tc      a[TE],a[RW]

       .extern  a[RW]
       .csect   prog1[PR]
       ...
       addis    3,a[TE](2)       # R_TOCU relocation used by default.
       ld       5,a[TE](3)       # R_TOCL relocation used by default.
       # Now GPR5 contains the address of a[RW]
The two instructions to load a[TE] from the TOC do not have to be sequential, but adding an offset to the referenced symbol is not allowed. For example, the ld instruction cannot be as follows:

       ld       5,a[TE]+8(3)       # Invalid reference
The selection of the storage-mapping class and the R_TOCU and R_TOCL relocation types can be selected independently. For example, a[TE] can be used as a normal TOC symbol with the following instruction:

       ld       5,a[TE]@tc(2)       # GPR5 contains the address of a[RW]
The two-instruction sequence can also be used with a[TC] from the previous example:

       addis    5,a[TC]@u(2)
       ld       5,a[TC]@l(5)       # GPR5 contains the address of a[RW]