blob: ec3e1de30950bca18a2181ab3f480fdea45f573b [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents the GNU Assembler "as".
Copyright (C) 1991-2013 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".
-->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Using as: Sparc-Relocs</title>
<meta name="description" content="Using as: Sparc-Relocs">
<meta name="keywords" content="Using as: Sparc-Relocs">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Sparc_002dSyntax.html#Sparc_002dSyntax" rel="up" title="Sparc-Syntax">
<link href="Sparc_002dSize_002dTranslations.html#Sparc_002dSize_002dTranslations" rel="next" title="Sparc-Size-Translations">
<link href="Sparc_002dConstants.html#Sparc_002dConstants" rel="prev" title="Sparc-Constants">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Sparc_002dRelocs"></a>
<div class="header">
<p>
Next: <a href="Sparc_002dSize_002dTranslations.html#Sparc_002dSize_002dTranslations" accesskey="n" rel="next">Sparc-Size-Translations</a>, Previous: <a href="Sparc_002dConstants.html#Sparc_002dConstants" accesskey="p" rel="prev">Sparc-Constants</a>, Up: <a href="Sparc_002dSyntax.html#Sparc_002dSyntax" accesskey="u" rel="up">Sparc-Syntax</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Relocations-3"></a>
<h4 class="subsubsection">9.41.3.4 Relocations</h4>
<a name="index-Sparc-relocations"></a>
<a name="index-relocations_002c-Sparc"></a>
<p>ELF relocations are available as defined in the 32-bit and 64-bit
Sparc ELF specifications.
</p>
<p><code>R_SPARC_HI22</code> is obtained using &lsquo;<samp>%hi</samp>&rsquo; and <code>R_SPARC_LO10</code>
is obtained using &lsquo;<samp>%lo</samp>&rsquo;. Likewise <code>R_SPARC_HIX22</code> is
obtained from &lsquo;<samp>%hix</samp>&rsquo; and <code>R_SPARC_LOX10</code> is obtained
using &lsquo;<samp>%lox</samp>&rsquo;. For example:
</p>
<div class="example">
<pre class="example">sethi %hi(symbol), %g1
or %g1, %lo(symbol), %g1
sethi %hix(symbol), %g1
xor %g1, %lox(symbol), %g1
</pre></div>
<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>
<p>V9 code model relocations can be requested as follows:
</p>
<ul>
<li> <code>R_SPARC_HH22</code> is requested using &lsquo;<samp>%hh</samp>&rsquo;. It can
also be generated using &lsquo;<samp>%uhi</samp>&rsquo;.
</li><li> <code>R_SPARC_HM10</code> is requested using &lsquo;<samp>%hm</samp>&rsquo;. It can
also be generated using &lsquo;<samp>%ulo</samp>&rsquo;.
</li><li> <code>R_SPARC_LM22</code> is requested using &lsquo;<samp>%lm</samp>&rsquo;.
</li><li> <code>R_SPARC_H44</code> is requested using &lsquo;<samp>%h44</samp>&rsquo;.
</li><li> <code>R_SPARC_M44</code> is requested using &lsquo;<samp>%m44</samp>&rsquo;.
</li><li> <code>R_SPARC_L44</code> is requested using &lsquo;<samp>%l44</samp>&rsquo; or &lsquo;<samp>%l34</samp>&rsquo;.
</li><li> <code>R_SPARC_H34</code> is requested using &lsquo;<samp>%h34</samp>&rsquo;.
</li></ul>
<p>The &lsquo;<samp>%l34</samp>&rsquo; 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>
<p>The &lsquo;<samp>%h34</samp>&rsquo; and &lsquo;<samp>%l34</samp>&rsquo; relocations are used for the abs34 code
model. Here is an example abs34 address generation sequence:
</p>
<div class="example">
<pre class="example">sethi %h34(symbol), %g1
sllx %g1, 2, %g1
or %g1, %l34(symbol), %g1
</pre></div>
<p>The PC relative relocation <code>R_SPARC_PC22</code> can be obtained by
enclosing an operand inside of &lsquo;<samp>%pc22</samp>&rsquo;. Likewise, the
<code>R_SPARC_PC10</code> relocation can be obtained using &lsquo;<samp>%pc10</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:
</p>
<div class="example">
<pre class="example">sethi %pc22(_GLOBAL_OFFSET_TABLE_-4), %l7
add %l7, %pc10(_GLOBAL_OFFSET_TABLE_+4), %l7
</pre></div>
<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>%gdop_hix22</samp>&rsquo;. The <code>R_SPARC_GOTDATA_OP_LOX10</code>
relocation can obtained by enclosing an operand inside of
&lsquo;<samp>%gdop_lox10</samp>&rsquo;. Likewise, <code>R_SPARC_GOTDATA_OP</code> can be
obtained by enclosing an operand inside of &lsquo;<samp>%gdop</samp>&rsquo;.
For example, assuming the GOT base is in register <code>%l7</code>:
</p>
<div class="example">
<pre class="example">sethi %gdop_hix22(symbol), %l1
xor %l1, %gdop_lox10(symbol), %l1
ld [%l7 + %l1], %l2, %gdop(symbol)
</pre></div>
<p>There are many relocations that can be requested for access to
thread local storage variables. All of the Sparc TLS mnemonics
are supported:
</p>
<ul>
<li> <code>R_SPARC_TLS_GD_HI22</code> is requested using &lsquo;<samp>%tgd_hi22</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_GD_LO10</code> is requested using &lsquo;<samp>%tgd_lo10</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_GD_ADD</code> is requested using &lsquo;<samp>%tgd_add</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_GD_CALL</code> is requested using &lsquo;<samp>%tgd_call</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LDM_HI22</code> is requested using &lsquo;<samp>%tldm_hi22</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LDM_LO10</code> is requested using &lsquo;<samp>%tldm_lo10</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LDM_ADD</code> is requested using &lsquo;<samp>%tldm_add</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LDM_CALL</code> is requested using &lsquo;<samp>%tldm_call</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LDO_HIX22</code> is requested using &lsquo;<samp>%tldo_hix22</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LDO_LOX10</code> is requested using &lsquo;<samp>%tldo_lox10</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LDO_ADD</code> is requested using &lsquo;<samp>%tldo_add</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_IE_HI22</code> is requested using &lsquo;<samp>%tie_hi22</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_IE_LO10</code> is requested using &lsquo;<samp>%tie_lo10</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_IE_LD</code> is requested using &lsquo;<samp>%tie_ld</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_IE_LDX</code> is requested using &lsquo;<samp>%tie_ldx</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_IE_ADD</code> is requested using &lsquo;<samp>%tie_add</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LE_HIX22</code> is requested using &lsquo;<samp>%tle_hix22</samp>&rsquo;.
</li><li> <code>R_SPARC_TLS_LE_LOX10</code> is requested using &lsquo;<samp>%tle_lox10</samp>&rsquo;.
</li></ul>
<p>Here are some example TLS model sequences.
</p>
<p>First, General Dynamic:
</p>
<div class="example">
<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></div>
<p>Local Dynamic:
</p>
<div class="example">
<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></div>
<p>Initial Exec:
</p>
<div class="example">
<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></div>
<p>And finally, Local Exec:
</p>
<div class="example">
<pre class="example">sethi %tle_hix22(symbol), %l1
add %l1, %tle_lox10(symbol), %l1
add %g7, %l1, %l1
</pre></div>
<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.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Sparc_002dSize_002dTranslations.html#Sparc_002dSize_002dTranslations" accesskey="n" rel="next">Sparc-Size-Translations</a>, Previous: <a href="Sparc_002dConstants.html#Sparc_002dConstants" accesskey="p" rel="prev">Sparc-Constants</a>, Up: <a href="Sparc_002dSyntax.html#Sparc_002dSyntax" accesskey="u" rel="up">Sparc-Syntax</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>