SPARC Assembly Language Reference Manual

Exit Print View

Updated: July 2014
 
 

5.4.4 General Dynamic TLS Code Model

An example of the general dynamic TLS code model is shown below:

add:
        save    %sp,-176,%sp
.L900000107:
        rd      %pc,%i3
        sethi   %pc22(_GLOBAL_OFFSET_TABLE_-(.L900000107-.)),%g1
        add     %g1,%pc10(_GLOBAL_OFFSET_TABLE_-(.L900000107-.)),%g1
        add     %g1,%i3,%i3
        sethi   %tgd_hi22(sum),%i2
        add     %i2,%tgd_lo10(sum),%i1
        add     %i3,%i1,%o0,%tgd_add(sum)
        call    __tls_get_addr,%tgd_call(sum)
        nop
        ld      [%o0],%l7
        add     %l7,%i0,%l6
        st      %l6,[%o0]
        ret
        restore %g0,%g0,%g0

Notice that we could not have a leaf routine because of the call instruction.

There are four instructions to form a pointer to the GOT into register %i3, followed by two more instruction to form the offset of the address of sum in the GOT, and another instruction to add those to the address of the GOT to form the address of the GOT slot for sum. This address is passed to function __tls_get_addr that returns the address for sum in register %o0.

The operators act as follows:

%tgd_hi22(sum)R_SPARC_TLS_GD_HI22 relocation
%tgd_lo10(sum)R_SPARC_TLS_GD_LO10
%tgd_add(sum)R_SPARC_TLS_GD_ADD
%tgd_call(sum)R_SPARC_TLS_GD_CALL