as: Sparc-Relocs

1 
1 9.44.3.4 Relocations
1 ....................
1 
1 ELF relocations are available as defined in the 32-bit and 64-bit Sparc
1 ELF specifications.
1 
1    'R_SPARC_HI22' is obtained using '%hi' and 'R_SPARC_LO10' is obtained
1 using '%lo'.  Likewise 'R_SPARC_HIX22' is obtained from '%hix' and
1 'R_SPARC_LOX10' is obtained using '%lox'.  For example:
1 
1      sethi %hi(symbol), %g1
1      or    %g1, %lo(symbol), %g1
1 
1      sethi %hix(symbol), %g1
1      xor   %g1, %lox(symbol), %g1
1 
1    These "high" mnemonics extract bits 31:10 of their operand, and the
1 "low" mnemonics extract bits 9:0 of their operand.
1 
1    V9 code model relocations can be requested as follows:
1 
1    * 'R_SPARC_HH22' is requested using '%hh'.  It can also be generated
1      using '%uhi'.
1    * 'R_SPARC_HM10' is requested using '%hm'.  It can also be generated
1      using '%ulo'.
1    * 'R_SPARC_LM22' is requested using '%lm'.
1 
1    * 'R_SPARC_H44' is requested using '%h44'.
1    * 'R_SPARC_M44' is requested using '%m44'.
1    * 'R_SPARC_L44' is requested using '%l44' or '%l34'.
1    * 'R_SPARC_H34' is requested using '%h34'.
1 
1    The '%l34' generates a 'R_SPARC_L44' relocation because it calculates
1 the necessary value, and therefore no explicit 'R_SPARC_L34' relocation
1 needed to be created for this purpose.
1 
1    The '%h34' and '%l34' relocations are used for the abs34 code model.
1 Here is an example abs34 address generation sequence:
1 
1      sethi %h34(symbol), %g1
1      sllx  %g1, 2, %g1
1      or    %g1, %l34(symbol), %g1
1 
1    The PC relative relocation 'R_SPARC_PC22' can be obtained by
1 enclosing an operand inside of '%pc22'.  Likewise, the 'R_SPARC_PC10'
1 relocation can be obtained using '%pc10'.  These are mostly used when
1 assembling PIC code.  For example, the standard PIC sequence on Sparc to
1 get the base of the global offset table, PC relative, into a register,
1 can be performed as:
1 
1      sethi %pc22(_GLOBAL_OFFSET_TABLE_-4), %l7
1      add   %l7, %pc10(_GLOBAL_OFFSET_TABLE_+4), %l7
1 
1    Several relocations exist to allow the link editor to potentially
1 optimize GOT data references.  The 'R_SPARC_GOTDATA_OP_HIX22' relocation
1 can obtained by enclosing an operand inside of '%gdop_hix22'.  The
1 'R_SPARC_GOTDATA_OP_LOX10' relocation can obtained by enclosing an
1 operand inside of '%gdop_lox10'.  Likewise, 'R_SPARC_GOTDATA_OP' can be
1 obtained by enclosing an operand inside of '%gdop'.  For example,
1 assuming the GOT base is in register '%l7':
1 
1      sethi %gdop_hix22(symbol), %l1
1      xor   %l1, %gdop_lox10(symbol), %l1
1      ld    [%l7 + %l1], %l2, %gdop(symbol)
1 
1    There are many relocations that can be requested for access to thread
1 local storage variables.  All of the Sparc TLS mnemonics are supported:
1 
1    * 'R_SPARC_TLS_GD_HI22' is requested using '%tgd_hi22'.
1    * 'R_SPARC_TLS_GD_LO10' is requested using '%tgd_lo10'.
1    * 'R_SPARC_TLS_GD_ADD' is requested using '%tgd_add'.
1    * 'R_SPARC_TLS_GD_CALL' is requested using '%tgd_call'.
1 
1    * 'R_SPARC_TLS_LDM_HI22' is requested using '%tldm_hi22'.
1    * 'R_SPARC_TLS_LDM_LO10' is requested using '%tldm_lo10'.
1    * 'R_SPARC_TLS_LDM_ADD' is requested using '%tldm_add'.
1    * 'R_SPARC_TLS_LDM_CALL' is requested using '%tldm_call'.
1 
1    * 'R_SPARC_TLS_LDO_HIX22' is requested using '%tldo_hix22'.
1    * 'R_SPARC_TLS_LDO_LOX10' is requested using '%tldo_lox10'.
1    * 'R_SPARC_TLS_LDO_ADD' is requested using '%tldo_add'.
1 
1    * 'R_SPARC_TLS_IE_HI22' is requested using '%tie_hi22'.
1    * 'R_SPARC_TLS_IE_LO10' is requested using '%tie_lo10'.
1    * 'R_SPARC_TLS_IE_LD' is requested using '%tie_ld'.
1    * 'R_SPARC_TLS_IE_LDX' is requested using '%tie_ldx'.
1    * 'R_SPARC_TLS_IE_ADD' is requested using '%tie_add'.
1 
1    * 'R_SPARC_TLS_LE_HIX22' is requested using '%tle_hix22'.
1    * 'R_SPARC_TLS_LE_LOX10' is requested using '%tle_lox10'.
1 
1    Here are some example TLS model sequences.
1 
1    First, General Dynamic:
1 
1      sethi  %tgd_hi22(symbol), %l1
1      add    %l1, %tgd_lo10(symbol), %l1
1      add    %l7, %l1, %o0, %tgd_add(symbol)
1      call   __tls_get_addr, %tgd_call(symbol)
1      nop
1 
1    Local Dynamic:
1 
1      sethi  %tldm_hi22(symbol), %l1
1      add    %l1, %tldm_lo10(symbol), %l1
1      add    %l7, %l1, %o0, %tldm_add(symbol)
1      call   __tls_get_addr, %tldm_call(symbol)
1      nop
1 
1      sethi  %tldo_hix22(symbol), %l1
1      xor    %l1, %tldo_lox10(symbol), %l1
1      add    %o0, %l1, %l1, %tldo_add(symbol)
1 
1    Initial Exec:
1 
1      sethi  %tie_hi22(symbol), %l1
1      add    %l1, %tie_lo10(symbol), %l1
1      ld     [%l7 + %l1], %o0, %tie_ld(symbol)
1      add    %g7, %o0, %o0, %tie_add(symbol)
1 
1      sethi  %tie_hi22(symbol), %l1
1      add    %l1, %tie_lo10(symbol), %l1
1      ldx    [%l7 + %l1], %o0, %tie_ldx(symbol)
1      add    %g7, %o0, %o0, %tie_add(symbol)
1 
1    And finally, Local Exec:
1 
1      sethi  %tle_hix22(symbol), %l1
1      add    %l1, %tle_lox10(symbol), %l1
1      add    %g7, %l1, %l1
1 
1    When assembling for 64-bit, and a secondary constant addend is
1 specified in an address expression that would normally generate an
1 'R_SPARC_LO10' relocation, the assembler will emit an 'R_SPARC_OLO10'
1 instead.
1