blob: 22180d3ff160b38b1ed4740b87d2eee14addf22a [file] [log] [blame]
<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, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2006, 2007, 2008, 2009, 2010 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>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Sparc-Relocs"></a>
<a name="Sparc_002dRelocs"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Sparc_002dSize_002dTranslations.html#Sparc_002dSize_002dTranslations">Sparc-Size-Translations</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Sparc_002dConstants.html#Sparc_002dConstants">Sparc-Constants</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Sparc_002dSyntax.html#Sparc_002dSyntax">Sparc-Syntax</a>
<hr>
</div>
<h5 class="subsubsection">9.35.3.4 Relocations</h5>
<p><a name="index-Sparc-relocations-1647"></a><a name="index-relocations_002c-Sparc-1648"></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 &lsquo;<samp><span class="samp">%hi</span></samp>&rsquo; and <code>R_SPARC_LO10</code>
is obtained using &lsquo;<samp><span class="samp">%lo</span></samp>&rsquo;. Likewise <code>R_SPARC_HIX22</code> is
obtained from &lsquo;<samp><span class="samp">%hix</span></samp>&rsquo; and <code>R_SPARC_LOX10</code> is obtained
using &lsquo;<samp><span class="samp">%lox</span></samp>&rsquo;. 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 &ldquo;high&rdquo; mnemonics extract bits 31:10 of their operand,
and the &ldquo;low&rdquo; 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 &lsquo;<samp><span class="samp">%hh</span></samp>&rsquo;. It can
also be generated using &lsquo;<samp><span class="samp">%uhi</span></samp>&rsquo;.
<li><code>R_SPARC_HM10</code> is requested using &lsquo;<samp><span class="samp">%hm</span></samp>&rsquo;. It can
also be generated using &lsquo;<samp><span class="samp">%ulo</span></samp>&rsquo;.
<li><code>R_SPARC_LM22</code> is requested using &lsquo;<samp><span class="samp">%lm</span></samp>&rsquo;.
<li><code>R_SPARC_H44</code> is requested using &lsquo;<samp><span class="samp">%h44</span></samp>&rsquo;.
<li><code>R_SPARC_M44</code> is requested using &lsquo;<samp><span class="samp">%m44</span></samp>&rsquo;.
<li><code>R_SPARC_L44</code> is requested using &lsquo;<samp><span class="samp">%l44</span></samp>&rsquo;.
</ul>
<p>The PC relative relocation <code>R_SPARC_PC22</code> can be obtained by
enclosing an operand inside of &lsquo;<samp><span class="samp">%pc22</span></samp>&rsquo;. Likewise, the
<code>R_SPARC_PC10</code> relocation can be obtained using &lsquo;<samp><span class="samp">%pc10</span></samp>&rsquo;.
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
&lsquo;<samp><span class="samp">%gdop_hix22</span></samp>&rsquo;. The <code>R_SPARC_GOTDATA_OP_LOX10</code>
relocation can obtained by enclosing an operand inside of
&lsquo;<samp><span class="samp">%gdop_lox10</span></samp>&rsquo;. Likewise, <code>R_SPARC_GOTDATA_OP</code> can be
obtained by enclosing an operand inside of &lsquo;<samp><span class="samp">%gdop</span></samp>&rsquo;.
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 &lsquo;<samp><span class="samp">%tgd_hi22</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_GD_LO10</code> is requested using &lsquo;<samp><span class="samp">%tgd_lo10</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_GD_ADD</code> is requested using &lsquo;<samp><span class="samp">%tgd_add</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_GD_CALL</code> is requested using &lsquo;<samp><span class="samp">%tgd_call</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LDM_HI22</code> is requested using &lsquo;<samp><span class="samp">%tldm_hi22</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LDM_LO10</code> is requested using &lsquo;<samp><span class="samp">%tldm_lo10</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LDM_ADD</code> is requested using &lsquo;<samp><span class="samp">%tldm_add</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LDM_CALL</code> is requested using &lsquo;<samp><span class="samp">%tldm_call</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LDO_HIX22</code> is requested using &lsquo;<samp><span class="samp">%tldo_hix22</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LDO_LOX10</code> is requested using &lsquo;<samp><span class="samp">%tldo_lox10</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LDO_ADD</code> is requested using &lsquo;<samp><span class="samp">%tldo_add</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_IE_HI22</code> is requested using &lsquo;<samp><span class="samp">%tie_hi22</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_IE_LO10</code> is requested using &lsquo;<samp><span class="samp">%tie_lo10</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_IE_LD</code> is requested using &lsquo;<samp><span class="samp">%tie_ld</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_IE_LDX</code> is requested using &lsquo;<samp><span class="samp">%tie_ldx</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_IE_ADD</code> is requested using &lsquo;<samp><span class="samp">%tie_add</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LE_HIX22</code> is requested using &lsquo;<samp><span class="samp">%tle_hix22</span></samp>&rsquo;.
<li><code>R_SPARC_TLS_LE_LOX10</code> is requested using &lsquo;<samp><span class="samp">%tle_lox10</span></samp>&rsquo;.
</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>