<html lang="en"> <head> <title>Sparc-Relocs - Using as</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Using as"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Sparc_002dSyntax.html#Sparc_002dSyntax" title="Sparc-Syntax"> <link rel="prev" href="Sparc_002dConstants.html#Sparc_002dConstants" title="Sparc-Constants"> <link rel="next" href="Sparc_002dSize_002dTranslations.html#Sparc_002dSize_002dTranslations" title="Sparc-Size-Translations"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <!-- This file documents the GNU Assembler "as". Copyright (C) 1991-2015 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''. --> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Sparc-Relocs"></a> <a name="Sparc_002dRelocs"></a> <p> Next: <a rel="next" accesskey="n" href="Sparc_002dSize_002dTranslations.html#Sparc_002dSize_002dTranslations">Sparc-Size-Translations</a>, Previous: <a rel="previous" accesskey="p" href="Sparc_002dConstants.html#Sparc_002dConstants">Sparc-Constants</a>, Up: <a rel="up" accesskey="u" href="Sparc_002dSyntax.html#Sparc_002dSyntax">Sparc-Syntax</a> <hr> </div> <h5 class="subsubsection">9.42.3.4 Relocations</h5> <p><a name="index-Sparc-relocations-2026"></a><a name="index-relocations_002c-Sparc-2027"></a> ELF relocations are available as defined in the 32-bit and 64-bit Sparc ELF specifications. <p><code>R_SPARC_HI22</code> is obtained using ‘<samp><span class="samp">%hi</span></samp>’ and <code>R_SPARC_LO10</code> is obtained using ‘<samp><span class="samp">%lo</span></samp>’. Likewise <code>R_SPARC_HIX22</code> is obtained from ‘<samp><span class="samp">%hix</span></samp>’ and <code>R_SPARC_LOX10</code> is obtained using ‘<samp><span class="samp">%lox</span></samp>’. For example: <pre class="example"> sethi %hi(symbol), %g1 or %g1, %lo(symbol), %g1 sethi %hix(symbol), %g1 xor %g1, %lox(symbol), %g1 </pre> <p>These “high” mnemonics extract bits 31:10 of their operand, and the “low” mnemonics extract bits 9:0 of their operand. <p>V9 code model relocations can be requested as follows: <ul> <li><code>R_SPARC_HH22</code> is requested using ‘<samp><span class="samp">%hh</span></samp>’. It can also be generated using ‘<samp><span class="samp">%uhi</span></samp>’. <li><code>R_SPARC_HM10</code> is requested using ‘<samp><span class="samp">%hm</span></samp>’. It can also be generated using ‘<samp><span class="samp">%ulo</span></samp>’. <li><code>R_SPARC_LM22</code> is requested using ‘<samp><span class="samp">%lm</span></samp>’. <li><code>R_SPARC_H44</code> is requested using ‘<samp><span class="samp">%h44</span></samp>’. <li><code>R_SPARC_M44</code> is requested using ‘<samp><span class="samp">%m44</span></samp>’. <li><code>R_SPARC_L44</code> is requested using ‘<samp><span class="samp">%l44</span></samp>’ or ‘<samp><span class="samp">%l34</span></samp>’. <li><code>R_SPARC_H34</code> is requested using ‘<samp><span class="samp">%h34</span></samp>’. </ul> <p>The ‘<samp><span class="samp">%l34</span></samp>’ generates a <code>R_SPARC_L44</code> relocation because it calculates the necessary value, and therefore no explicit <code>R_SPARC_L34</code> relocation needed to be created for this purpose. <p>The ‘<samp><span class="samp">%h34</span></samp>’ and ‘<samp><span class="samp">%l34</span></samp>’ relocations are used for the abs34 code model. Here is an example abs34 address generation sequence: <pre class="example"> sethi %h34(symbol), %g1 sllx %g1, 2, %g1 or %g1, %l34(symbol), %g1 </pre> <p>The PC relative relocation <code>R_SPARC_PC22</code> can be obtained by enclosing an operand inside of ‘<samp><span class="samp">%pc22</span></samp>’. Likewise, the <code>R_SPARC_PC10</code> relocation can be obtained using ‘<samp><span class="samp">%pc10</span></samp>’. These are mostly used when assembling PIC code. For example, the standard PIC sequence on Sparc to get the base of the global offset table, PC relative, into a register, can be performed as: <pre class="example"> sethi %pc22(_GLOBAL_OFFSET_TABLE_-4), %l7 add %l7, %pc10(_GLOBAL_OFFSET_TABLE_+4), %l7 </pre> <p>Several relocations exist to allow the link editor to potentially optimize GOT data references. The <code>R_SPARC_GOTDATA_OP_HIX22</code> relocation can obtained by enclosing an operand inside of ‘<samp><span class="samp">%gdop_hix22</span></samp>’. The <code>R_SPARC_GOTDATA_OP_LOX10</code> relocation can obtained by enclosing an operand inside of ‘<samp><span class="samp">%gdop_lox10</span></samp>’. Likewise, <code>R_SPARC_GOTDATA_OP</code> can be obtained by enclosing an operand inside of ‘<samp><span class="samp">%gdop</span></samp>’. For example, assuming the GOT base is in register <code>%l7</code>: <pre class="example"> sethi %gdop_hix22(symbol), %l1 xor %l1, %gdop_lox10(symbol), %l1 ld [%l7 + %l1], %l2, %gdop(symbol) </pre> <p>There are many relocations that can be requested for access to thread local storage variables. All of the Sparc TLS mnemonics are supported: <ul> <li><code>R_SPARC_TLS_GD_HI22</code> is requested using ‘<samp><span class="samp">%tgd_hi22</span></samp>’. <li><code>R_SPARC_TLS_GD_LO10</code> is requested using ‘<samp><span class="samp">%tgd_lo10</span></samp>’. <li><code>R_SPARC_TLS_GD_ADD</code> is requested using ‘<samp><span class="samp">%tgd_add</span></samp>’. <li><code>R_SPARC_TLS_GD_CALL</code> is requested using ‘<samp><span class="samp">%tgd_call</span></samp>’. <li><code>R_SPARC_TLS_LDM_HI22</code> is requested using ‘<samp><span class="samp">%tldm_hi22</span></samp>’. <li><code>R_SPARC_TLS_LDM_LO10</code> is requested using ‘<samp><span class="samp">%tldm_lo10</span></samp>’. <li><code>R_SPARC_TLS_LDM_ADD</code> is requested using ‘<samp><span class="samp">%tldm_add</span></samp>’. <li><code>R_SPARC_TLS_LDM_CALL</code> is requested using ‘<samp><span class="samp">%tldm_call</span></samp>’. <li><code>R_SPARC_TLS_LDO_HIX22</code> is requested using ‘<samp><span class="samp">%tldo_hix22</span></samp>’. <li><code>R_SPARC_TLS_LDO_LOX10</code> is requested using ‘<samp><span class="samp">%tldo_lox10</span></samp>’. <li><code>R_SPARC_TLS_LDO_ADD</code> is requested using ‘<samp><span class="samp">%tldo_add</span></samp>’. <li><code>R_SPARC_TLS_IE_HI22</code> is requested using ‘<samp><span class="samp">%tie_hi22</span></samp>’. <li><code>R_SPARC_TLS_IE_LO10</code> is requested using ‘<samp><span class="samp">%tie_lo10</span></samp>’. <li><code>R_SPARC_TLS_IE_LD</code> is requested using ‘<samp><span class="samp">%tie_ld</span></samp>’. <li><code>R_SPARC_TLS_IE_LDX</code> is requested using ‘<samp><span class="samp">%tie_ldx</span></samp>’. <li><code>R_SPARC_TLS_IE_ADD</code> is requested using ‘<samp><span class="samp">%tie_add</span></samp>’. <li><code>R_SPARC_TLS_LE_HIX22</code> is requested using ‘<samp><span class="samp">%tle_hix22</span></samp>’. <li><code>R_SPARC_TLS_LE_LOX10</code> is requested using ‘<samp><span class="samp">%tle_lox10</span></samp>’. </ul> <p>Here are some example TLS model sequences. <p>First, General Dynamic: <pre class="example"> sethi %tgd_hi22(symbol), %l1 add %l1, %tgd_lo10(symbol), %l1 add %l7, %l1, %o0, %tgd_add(symbol) call __tls_get_addr, %tgd_call(symbol) nop </pre> <p>Local Dynamic: <pre class="example"> sethi %tldm_hi22(symbol), %l1 add %l1, %tldm_lo10(symbol), %l1 add %l7, %l1, %o0, %tldm_add(symbol) call __tls_get_addr, %tldm_call(symbol) nop sethi %tldo_hix22(symbol), %l1 xor %l1, %tldo_lox10(symbol), %l1 add %o0, %l1, %l1, %tldo_add(symbol) </pre> <p>Initial Exec: <pre class="example"> sethi %tie_hi22(symbol), %l1 add %l1, %tie_lo10(symbol), %l1 ld [%l7 + %l1], %o0, %tie_ld(symbol) add %g7, %o0, %o0, %tie_add(symbol) sethi %tie_hi22(symbol), %l1 add %l1, %tie_lo10(symbol), %l1 ldx [%l7 + %l1], %o0, %tie_ldx(symbol) add %g7, %o0, %o0, %tie_add(symbol) </pre> <p>And finally, Local Exec: <pre class="example"> sethi %tle_hix22(symbol), %l1 add %l1, %tle_lox10(symbol), %l1 add %g7, %l1, %l1 </pre> <p>When assembling for 64-bit, and a secondary constant addend is specified in an address expression that would normally generate an <code>R_SPARC_LO10</code> relocation, the assembler will emit an <code>R_SPARC_OLO10</code> instead. </body></html>