SPARC Assembly Language Reference Manual

Exit Print View

Updated: July 2014
 
 

5.4.3 Local Dynamic TLS Code Model

An example of the local 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   %tldm_hi22(sum),%i2
        add     %i2,%tldm_lo10(sum),%i1
        add     %i3,%i1,%o0,%tldm_add(sum)
        call    __tls_get_addr,%tldm_call(sum)
        nop
        sethi   %tldo_hix22(sum),%l7
        xor     %l7,%tldo_lox10(sum),%l6
        add     %o0,%l6,%l4,%tldo_add(sum)
        ld      [%l4],%l5
        add     %l5,%i0,%l3
        st      %l3,[%l4]
        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. Then it takes two more instructions 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 local module's TLS data in register %o0. Three more instructions form the offset of sum in the module data and to add that to the module data address. Note that the module data address can be reused to access multiple TLS variables.

The operators act as follows:

%tldm_hi22(sum)R_SPARC_TLS_LDM_HI22 relocation
%tldm_lo10(sum)R_SPARC_TLS_LDM_LO10
%tldm_add(sum)R_SPARC_TLS_LDM_ADD
%tldm_call(sum)R_SPARC_TLS_LDM_CALL
%tldo_hix22(sum)R_SPARC_TLS_LDO_HIX22 relocation
%tldo_lox10(sum)R_SPARC_TLS_LDO_LOX10
%tldo_add(sum)R_SPARC_TLS_LDO_ADD