![Intel NIOS II Owner Reference Manual Download Page 163](http://html1.mh-extra.com/html/intel/nios-ii/nios-ii_owner-reference-manual_2071826163.webp)
Example 16. Small GOT Model Entry for Global Symbols
addi r3, r22, %got(x) # R_NIOS2_GOT16
GOT[n] R_NIOS2_GLOB_DAT x
Example 17. Large GOT Model Entry for Global Symbols
movhi r3, %got_hiadj(x) # R_NIOS2_GOT_HA
addi r3, r3, %got_lo(x) # R_NIOS2_GOT_LO
add r3, r3, r22
GOT[n] R_NIOS2_GLOB_DAT x
For local symbols, the symbolic reference to x is replaced by a relative relocation
against symbol zero, with the link time address of x as an addend, as shown in the
example below.
Example 18. Local Symbols for small GOT Model
addi r3, r22, %got(x) # R_NIOS2_GOT16
GOT[n] R_NIOS2_REx
Example 19. Local Symbols for large GOT Model
movhi r3, %got_hiadj(x) # R_NIOS2_GOT_HA
addi r3, r3, %got_lo(x) # R_NIOS2_GOT_LO
add r3, r3, r22
GOT[n] R_NIOS2_REx
The
call
and
jmpi
instructions are not available in position-independent code.
Instead, all calls are made through the GOT. Function addresses may be loaded with
%call
, which allows lazy binding. To initialize a function pointer, load the address of
the function with
%got
instead. If no input object requires the address of the function
its GOT entry is placed in the PLT GOT for lazy binding, as shown in the example
below.
For information about the PLT, refer to the "Procedure Linkage Table" section.
Example 20. Small GOT Model entry in PLT GOT
ldw r3, %call(fun)(r22) # R_NIOS2_CALL16 fun
callr r3
PLTGOT[n] R_NIOS_JUMP_SLOT fun
Example 21. Large GOT Model entry in PLT GOT
movhi r3, %call_hiadj(x) # R_NIOS2_CALL_HA
addi r3, r3, %call_lo(x) # R_NIOS2_CALL_LO
add r3, r3, r22
ldw r3, 0(r3)
7. Application Binary Interface
NII-PRG | 2018.04.18
Nios II Processor Reference Guide
163