Specifications

The GOT pointer is loaded using a PC-relative offset to the _gp_got symbol, as shown below.
Example 7-12: Loading the GOT Pointer
nextpc r22
1:
orhi r1, %hiadj(_gp_got - 1b) # R_NIOS2_PCREL_HA _gp_got
addi r1, r1, %lo(_gp_got - 1b) # R_NIOS2_PCREL_LO _gp_got - 4
add r22, r22, r1
# GOT pointer in r22
Data may be accessed by loading its location from the GOT. A single word GOT entry is generated for
each referenced symbol.
Example 7-13: Small GOT Model Entry for Global Symbols
addi r3, r22, %got(x) # R_NIOS2_GOT16
GOT[n] R_NIOS2_GLOB_DAT x
Example 7-14: 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 7-15: Local Symbols for small GOT Model
addi r3, r22, %got(x) # R_NIOS2_GOT16
GOT[n] R_NIOS2_RELATIVE +x
Example 7-16: 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_RELATIVE +x
7-18
Linux Position-Independent Code
NII51016
2015.04.02
Altera Corporation
Application Binary Interface
Send Feedback