Example 10. GOT Slot with Thread-Local Storage
GOT[n] R_NIOS2_TLS_DTPMOD x
GOT[n+1] 0
Example 11. Initial Exec Model
ldw r4, %tls_ie(x)(r22) # R_NIOS2_TLS_IE16 x
add r4, r23, r4
# Address of x in r4
A single GOT slot is allocated to hold the offset of x from the thread pointer, as shown
in "GOT SLot for Initial Exec Model" example.
Example 12. GOT Slot for Initial Exec Model
GOT[n] R_NIOS2_TLS_TPREL x
Example 13. Local Exec Model
addi r4, r23, %tls_le(x) # R_NIOS2_TLS_LE16 x
# Address of x in r4
There is no GOT slot associated with the local exec model.
Debug information uses the GNU extension DW_OP_GNU_push_tls_address.
Example 14. Debug Information
.byte 0x03 # DW_OP_addr
.word %tls_ldo(x) # R_NIOS2_TLS_DTPREL x
.byte 0xe0 # DW_OP_GNU_push_tls_address
7.9.2. Linux Function Calls
Register
r23
is reserved for the thread pointer on GNU Linux systems. It is initialized
by the C library and it may be used directly for TLS access, but not modified. On non-
Linux systems
r23
is a general-purpose, callee-saved register.
The global pointer,
r26
or
gp
, is globally fixed. It is initialized in startup code and
always valid on entry to a function. This method does not allow for multiple
gp
values,
so
gp
-relative data references are only possible in the main application (that is, from
position dependent code).
gp
is only used for small data access, not GOT access,
because code compiled as PIC may be used from shared libraries. The linker may take
advantage of
gp
for shorter PLT sequences when the addresses are in range. The
compiler needs an option to disable use of
gprel
; the option is necessary for
applications with excessive amounts of small data. For comparison, XUL (Mozilla
display engine, 16 MB code, 2 MB data) has only 27 KB of small data and the limit is
64 KB. This option is separate from -G 0, because -G 0 creates ABI incompatibility. A
file compiled with -G 0 puts global
int
variables into
.data
but files compiled with -
G 8 expect such
int
variables to be in
.sdata
.
7. Application Binary Interface
NII-PRG | 2018.04.18
Nios II Processor Reference Guide
160