Sparc_002dRelocs.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU Assembler "as".
  4. Copyright (C) 1991-2017 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>Using as: Sparc-Relocs</title>
  15. <meta name="description" content="Using as: Sparc-Relocs">
  16. <meta name="keywords" content="Using as: Sparc-Relocs">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="Sparc_002dSyntax.html#Sparc_002dSyntax" rel="up" title="Sparc-Syntax">
  25. <link href="Sparc_002dSize_002dTranslations.html#Sparc_002dSize_002dTranslations" rel="next" title="Sparc-Size-Translations">
  26. <link href="Sparc_002dConstants.html#Sparc_002dConstants" rel="prev" title="Sparc-Constants">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style:oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; font-weight:normal}
  51. span.sansserif {font-family:sans-serif; font-weight:normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="Sparc_002dRelocs"></a>
  58. <div class="header">
  59. <p>
  60. 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>
  61. </div>
  62. <hr>
  63. <a name="Relocations-3"></a>
  64. <h4 class="subsubsection">9.43.3.4 Relocations</h4>
  65. <a name="index-Sparc-relocations"></a>
  66. <a name="index-relocations_002c-Sparc"></a>
  67. <p>ELF relocations are available as defined in the 32-bit and 64-bit
  68. Sparc ELF specifications.
  69. </p>
  70. <p><code>R_SPARC_HI22</code> is obtained using &lsquo;<samp>%hi</samp>&rsquo; and <code>R_SPARC_LO10</code>
  71. is obtained using &lsquo;<samp>%lo</samp>&rsquo;. Likewise <code>R_SPARC_HIX22</code> is
  72. obtained from &lsquo;<samp>%hix</samp>&rsquo; and <code>R_SPARC_LOX10</code> is obtained
  73. using &lsquo;<samp>%lox</samp>&rsquo;. For example:
  74. </p>
  75. <div class="example">
  76. <pre class="example">sethi %hi(symbol), %g1
  77. or %g1, %lo(symbol), %g1
  78. sethi %hix(symbol), %g1
  79. xor %g1, %lox(symbol), %g1
  80. </pre></div>
  81. <p>These &ldquo;high&rdquo; mnemonics extract bits 31:10 of their operand,
  82. and the &ldquo;low&rdquo; mnemonics extract bits 9:0 of their operand.
  83. </p>
  84. <p>V9 code model relocations can be requested as follows:
  85. </p>
  86. <ul>
  87. <li> <code>R_SPARC_HH22</code> is requested using &lsquo;<samp>%hh</samp>&rsquo;. It can
  88. also be generated using &lsquo;<samp>%uhi</samp>&rsquo;.
  89. </li><li> <code>R_SPARC_HM10</code> is requested using &lsquo;<samp>%hm</samp>&rsquo;. It can
  90. also be generated using &lsquo;<samp>%ulo</samp>&rsquo;.
  91. </li><li> <code>R_SPARC_LM22</code> is requested using &lsquo;<samp>%lm</samp>&rsquo;.
  92. </li><li> <code>R_SPARC_H44</code> is requested using &lsquo;<samp>%h44</samp>&rsquo;.
  93. </li><li> <code>R_SPARC_M44</code> is requested using &lsquo;<samp>%m44</samp>&rsquo;.
  94. </li><li> <code>R_SPARC_L44</code> is requested using &lsquo;<samp>%l44</samp>&rsquo; or &lsquo;<samp>%l34</samp>&rsquo;.
  95. </li><li> <code>R_SPARC_H34</code> is requested using &lsquo;<samp>%h34</samp>&rsquo;.
  96. </li></ul>
  97. <p>The &lsquo;<samp>%l34</samp>&rsquo; generates a <code>R_SPARC_L44</code> relocation because it
  98. calculates the necessary value, and therefore no explicit
  99. <code>R_SPARC_L34</code> relocation needed to be created for this purpose.
  100. </p>
  101. <p>The &lsquo;<samp>%h34</samp>&rsquo; and &lsquo;<samp>%l34</samp>&rsquo; relocations are used for the abs34 code
  102. model. Here is an example abs34 address generation sequence:
  103. </p>
  104. <div class="example">
  105. <pre class="example">sethi %h34(symbol), %g1
  106. sllx %g1, 2, %g1
  107. or %g1, %l34(symbol), %g1
  108. </pre></div>
  109. <p>The PC relative relocation <code>R_SPARC_PC22</code> can be obtained by
  110. enclosing an operand inside of &lsquo;<samp>%pc22</samp>&rsquo;. Likewise, the
  111. <code>R_SPARC_PC10</code> relocation can be obtained using &lsquo;<samp>%pc10</samp>&rsquo;.
  112. These are mostly used when assembling PIC code. For example, the
  113. standard PIC sequence on Sparc to get the base of the global offset
  114. table, PC relative, into a register, can be performed as:
  115. </p>
  116. <div class="example">
  117. <pre class="example">sethi %pc22(_GLOBAL_OFFSET_TABLE_-4), %l7
  118. add %l7, %pc10(_GLOBAL_OFFSET_TABLE_+4), %l7
  119. </pre></div>
  120. <p>Several relocations exist to allow the link editor to potentially
  121. optimize GOT data references. The <code>R_SPARC_GOTDATA_OP_HIX22</code>
  122. relocation can obtained by enclosing an operand inside of
  123. &lsquo;<samp>%gdop_hix22</samp>&rsquo;. The <code>R_SPARC_GOTDATA_OP_LOX10</code>
  124. relocation can obtained by enclosing an operand inside of
  125. &lsquo;<samp>%gdop_lox10</samp>&rsquo;. Likewise, <code>R_SPARC_GOTDATA_OP</code> can be
  126. obtained by enclosing an operand inside of &lsquo;<samp>%gdop</samp>&rsquo;.
  127. For example, assuming the GOT base is in register <code>%l7</code>:
  128. </p>
  129. <div class="example">
  130. <pre class="example">sethi %gdop_hix22(symbol), %l1
  131. xor %l1, %gdop_lox10(symbol), %l1
  132. ld [%l7 + %l1], %l2, %gdop(symbol)
  133. </pre></div>
  134. <p>There are many relocations that can be requested for access to
  135. thread local storage variables. All of the Sparc TLS mnemonics
  136. are supported:
  137. </p>
  138. <ul>
  139. <li> <code>R_SPARC_TLS_GD_HI22</code> is requested using &lsquo;<samp>%tgd_hi22</samp>&rsquo;.
  140. </li><li> <code>R_SPARC_TLS_GD_LO10</code> is requested using &lsquo;<samp>%tgd_lo10</samp>&rsquo;.
  141. </li><li> <code>R_SPARC_TLS_GD_ADD</code> is requested using &lsquo;<samp>%tgd_add</samp>&rsquo;.
  142. </li><li> <code>R_SPARC_TLS_GD_CALL</code> is requested using &lsquo;<samp>%tgd_call</samp>&rsquo;.
  143. </li><li> <code>R_SPARC_TLS_LDM_HI22</code> is requested using &lsquo;<samp>%tldm_hi22</samp>&rsquo;.
  144. </li><li> <code>R_SPARC_TLS_LDM_LO10</code> is requested using &lsquo;<samp>%tldm_lo10</samp>&rsquo;.
  145. </li><li> <code>R_SPARC_TLS_LDM_ADD</code> is requested using &lsquo;<samp>%tldm_add</samp>&rsquo;.
  146. </li><li> <code>R_SPARC_TLS_LDM_CALL</code> is requested using &lsquo;<samp>%tldm_call</samp>&rsquo;.
  147. </li><li> <code>R_SPARC_TLS_LDO_HIX22</code> is requested using &lsquo;<samp>%tldo_hix22</samp>&rsquo;.
  148. </li><li> <code>R_SPARC_TLS_LDO_LOX10</code> is requested using &lsquo;<samp>%tldo_lox10</samp>&rsquo;.
  149. </li><li> <code>R_SPARC_TLS_LDO_ADD</code> is requested using &lsquo;<samp>%tldo_add</samp>&rsquo;.
  150. </li><li> <code>R_SPARC_TLS_IE_HI22</code> is requested using &lsquo;<samp>%tie_hi22</samp>&rsquo;.
  151. </li><li> <code>R_SPARC_TLS_IE_LO10</code> is requested using &lsquo;<samp>%tie_lo10</samp>&rsquo;.
  152. </li><li> <code>R_SPARC_TLS_IE_LD</code> is requested using &lsquo;<samp>%tie_ld</samp>&rsquo;.
  153. </li><li> <code>R_SPARC_TLS_IE_LDX</code> is requested using &lsquo;<samp>%tie_ldx</samp>&rsquo;.
  154. </li><li> <code>R_SPARC_TLS_IE_ADD</code> is requested using &lsquo;<samp>%tie_add</samp>&rsquo;.
  155. </li><li> <code>R_SPARC_TLS_LE_HIX22</code> is requested using &lsquo;<samp>%tle_hix22</samp>&rsquo;.
  156. </li><li> <code>R_SPARC_TLS_LE_LOX10</code> is requested using &lsquo;<samp>%tle_lox10</samp>&rsquo;.
  157. </li></ul>
  158. <p>Here are some example TLS model sequences.
  159. </p>
  160. <p>First, General Dynamic:
  161. </p>
  162. <div class="example">
  163. <pre class="example">sethi %tgd_hi22(symbol), %l1
  164. add %l1, %tgd_lo10(symbol), %l1
  165. add %l7, %l1, %o0, %tgd_add(symbol)
  166. call __tls_get_addr, %tgd_call(symbol)
  167. nop
  168. </pre></div>
  169. <p>Local Dynamic:
  170. </p>
  171. <div class="example">
  172. <pre class="example">sethi %tldm_hi22(symbol), %l1
  173. add %l1, %tldm_lo10(symbol), %l1
  174. add %l7, %l1, %o0, %tldm_add(symbol)
  175. call __tls_get_addr, %tldm_call(symbol)
  176. nop
  177. sethi %tldo_hix22(symbol), %l1
  178. xor %l1, %tldo_lox10(symbol), %l1
  179. add %o0, %l1, %l1, %tldo_add(symbol)
  180. </pre></div>
  181. <p>Initial Exec:
  182. </p>
  183. <div class="example">
  184. <pre class="example">sethi %tie_hi22(symbol), %l1
  185. add %l1, %tie_lo10(symbol), %l1
  186. ld [%l7 + %l1], %o0, %tie_ld(symbol)
  187. add %g7, %o0, %o0, %tie_add(symbol)
  188. sethi %tie_hi22(symbol), %l1
  189. add %l1, %tie_lo10(symbol), %l1
  190. ldx [%l7 + %l1], %o0, %tie_ldx(symbol)
  191. add %g7, %o0, %o0, %tie_add(symbol)
  192. </pre></div>
  193. <p>And finally, Local Exec:
  194. </p>
  195. <div class="example">
  196. <pre class="example">sethi %tle_hix22(symbol), %l1
  197. add %l1, %tle_lox10(symbol), %l1
  198. add %g7, %l1, %l1
  199. </pre></div>
  200. <p>When assembling for 64-bit, and a secondary constant addend is
  201. specified in an address expression that would normally generate
  202. an <code>R_SPARC_LO10</code> relocation, the assembler will emit an
  203. <code>R_SPARC_OLO10</code> instead.
  204. </p>
  205. <hr>
  206. <div class="header">
  207. <p>
  208. 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>
  209. </div>
  210. </body>
  211. </html>