hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!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-2021 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.1, 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="previous" 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="previous">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-4"></a>
<h4 class="subsubsection">9.44.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="previous">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>