![Intel NIOS II Owner Reference Manual Download Page 164](http://html1.mh-extra.com/html/intel/nios-ii/nios-ii_owner-reference-manual_2071826164.webp)
callr r3
PLTGOT[n] R_NIOS_JUMP_SLOT fun
When a function or variable resides in the current shared object at compile time, it can
be accessed via a PC-relative or GOT-relative offset, as shown below.
Example 22. Accessing Function or Variable in Current Shared Object
orhi r3, %gotoff_hiadj(x) # R_NIOS2_GOTOFF_HA x
addi r3, r3, %gotoff_lo(x) # R_NIOS2_GOTOFF_LO x
add r3, r22, r3
# Address of x in r3
Multiway branches such as switch statements can be implemented with a table of
GOT-relative offsets, as shown below.
Example 23. Switch Statement Implemented with Table
# Scaled table offset in r4
orhi r3, %gotoff_hiadj(Ltable) # R_NIOS2_GOTOFF_HA Ltable
addi r3, r3, %gotoff_lo(Ltable) # R_NIOS2_GOTOFF_LO Ltable
add r3, r22, r3 # r3 == &Ltable
add r3, r3, r4
ldw r4, 0(r3) # r3 == Ltable[index]
add r4, r4, r22 # Convert offset into
destination
jmp r4
...
Ltable:
.word %gotoff(Label1)
.word %gotoff(Label2)
.word %gotoff(Label3)
Related Information
Procedure Linkage Table
on page 165
7.9.6. Linux Program Loading and Dynamic Linking
7.9.6.1. Global Offset Table
Because shared libraries are position-independent, they can not contain absolute
addresses for symbols. Instead, addresses are loaded from the GOT.
The first word of the GOT is filled in by the link editor with the unrelocated address of
the
_DYNAMIC
, which is at the start of the dynamic section. The second and third
words are reserved for the dynamic linker.
For information about the dynamic linker, refer to the "Procedure Linkage Table”
section.
The linker-defined symbol
_GLOBAL_OFFSET_TABLE_
points to the reserved entries
at the beginning of the GOT. The linker-defined symbol
_gp_got
points to the base
address used for GOT-relative relocations. The value of
_gp_got
might vary between
object files if the linker creates multiple GOT sections.
7. Application Binary Interface
NII-PRG | 2018.04.18
Nios II Processor Reference Guide
164