Altera Nios II User Manual page 175

Hide thumbs Also See for Nios II:
Table of Contents

Advertisement

Chapter 7: Application Binary Interface
ABI for Linux Systems
Multiway branches such as switch statements can be implemented with a table of
GOT-relative offsets, as shown in
Example 7–17. Switch Statement Implemented with Table
# Scaled table offset in r4
orhi
addi
add
add
ldw
add
jmp
...
Ltable:
.word
.word
.word
Linux Program Loading and Dynamic Linking
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
"Procedure Linkage Table" on page
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.
Function Addresses
Function addresses use the same SHN_UNDEF and st_value convention for PLT entries
as in other architectures, such as x86_64.
Procedure Linkage Table
Function calls in a position-dependent executable may use the call and jmpi
instructions, which address the contents of a 256-MB segment. They may also use the
%lo, %hi, and %hiadj operators to take the address of a function. If the function is in
another shared object, the link editor creates a callable stub in the executable called a
PLT entry. The PLT entry loads the address of the called function from the PLT GOT (a
region at the start of the GOT) and transfers control to it.
The PLT GOT entry needs a relocation referring to the final symbol, of type
R_NIOS2_JUMP_SLOT. The dynamic linker may immediately resolve it, or may leave
it unmodified for lazy binding. The link editor fills in an initial value pointing to the
lazy binding stubs at the start of the PLT section.
February 2014 Altera Corporation
Example
r3, %gotoff_hiadj(Ltable)
r3, r3, %gotoff_lo(Ltable) # R_NIOS2_GOTOFF_LO Ltable
r3, r22, r3
r3, r3, r4
r4, 0(r3)
r4, r4, r22
r4
%gotoff(Label1)
%gotoff(Label2)
%gotoff(Label3)
7–17.
# R_NIOS2_GOTOFF_HA Ltable
# r3 == &Ltable
# r3 == Ltable[index]
# Convert offset into destination
7–17.
Nios II Processor Reference Handbook
7–17

Advertisement

Table of Contents
loading

Table of Contents