Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>Sparc-Relocs (Using as)</title>
  16. <meta name="description" content="Sparc-Relocs (Using as)">
  17. <meta name="keywords" content="Sparc-Relocs (Using as)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  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.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="Sparc_002dRelocs"></a>
  57. <div class="header">
  58. <p>
  59. 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>
  60. </div>
  61. <hr>
  62. <a name="Relocations-4"></a>
  63. <h4 class="subsubsection">9.44.3.4 Relocations</h4>
  64. <a name="index-Sparc-relocations"></a>
  65. <a name="index-relocations_002c-Sparc"></a>
  66. <p>ELF relocations are available as defined in the 32-bit and 64-bit
  67. Sparc ELF specifications.
  68. </p>
  69. <p><code>R_SPARC_HI22</code> is obtained using &lsquo;<samp>%hi</samp>&rsquo; and <code>R_SPARC_LO10</code>
  70. is obtained using &lsquo;<samp>%lo</samp>&rsquo;. Likewise <code>R_SPARC_HIX22</code> is
  71. obtained from &lsquo;<samp>%hix</samp>&rsquo; and <code>R_SPARC_LOX10</code> is obtained
  72. using &lsquo;<samp>%lox</samp>&rsquo;. For example:
  73. </p>
  74. <div class="example">
  75. <pre class="example">sethi %hi(symbol), %g1
  76. or %g1, %lo(symbol), %g1
  77. sethi %hix(symbol), %g1
  78. xor %g1, %lox(symbol), %g1
  79. </pre></div>
  80. <p>These &ldquo;high&rdquo; mnemonics extract bits 31:10 of their operand,
  81. and the &ldquo;low&rdquo; mnemonics extract bits 9:0 of their operand.
  82. </p>
  83. <p>V9 code model relocations can be requested as follows:
  84. </p>
  85. <ul>
  86. <li> <code>R_SPARC_HH22</code> is requested using &lsquo;<samp>%hh</samp>&rsquo;. It can
  87. also be generated using &lsquo;<samp>%uhi</samp>&rsquo;.
  88. </li><li> <code>R_SPARC_HM10</code> is requested using &lsquo;<samp>%hm</samp>&rsquo;. It can
  89. also be generated using &lsquo;<samp>%ulo</samp>&rsquo;.
  90. </li><li> <code>R_SPARC_LM22</code> is requested using &lsquo;<samp>%lm</samp>&rsquo;.
  91. </li><li> <code>R_SPARC_H44</code> is requested using &lsquo;<samp>%h44</samp>&rsquo;.
  92. </li><li> <code>R_SPARC_M44</code> is requested using &lsquo;<samp>%m44</samp>&rsquo;.
  93. </li><li> <code>R_SPARC_L44</code> is requested using &lsquo;<samp>%l44</samp>&rsquo; or &lsquo;<samp>%l34</samp>&rsquo;.
  94. </li><li> <code>R_SPARC_H34</code> is requested using &lsquo;<samp>%h34</samp>&rsquo;.
  95. </li></ul>
  96. <p>The &lsquo;<samp>%l34</samp>&rsquo; generates a <code>R_SPARC_L44</code> relocation because it
  97. calculates the necessary value, and therefore no explicit
  98. <code>R_SPARC_L34</code> relocation needed to be created for this purpose.
  99. </p>
  100. <p>The &lsquo;<samp>%h34</samp>&rsquo; and &lsquo;<samp>%l34</samp>&rsquo; relocations are used for the abs34 code
  101. model. Here is an example abs34 address generation sequence:
  102. </p>
  103. <div class="example">
  104. <pre class="example">sethi %h34(symbol), %g1
  105. sllx %g1, 2, %g1
  106. or %g1, %l34(symbol), %g1
  107. </pre></div>
  108. <p>The PC relative relocation <code>R_SPARC_PC22</code> can be obtained by
  109. enclosing an operand inside of &lsquo;<samp>%pc22</samp>&rsquo;. Likewise, the
  110. <code>R_SPARC_PC10</code> relocation can be obtained using &lsquo;<samp>%pc10</samp>&rsquo;.
  111. These are mostly used when assembling PIC code. For example, the
  112. standard PIC sequence on Sparc to get the base of the global offset
  113. table, PC relative, into a register, can be performed as:
  114. </p>
  115. <div class="example">
  116. <pre class="example">sethi %pc22(_GLOBAL_OFFSET_TABLE_-4), %l7
  117. add %l7, %pc10(_GLOBAL_OFFSET_TABLE_+4), %l7
  118. </pre></div>
  119. <p>Several relocations exist to allow the link editor to potentially
  120. optimize GOT data references. The <code>R_SPARC_GOTDATA_OP_HIX22</code>
  121. relocation can obtained by enclosing an operand inside of
  122. &lsquo;<samp>%gdop_hix22</samp>&rsquo;. The <code>R_SPARC_GOTDATA_OP_LOX10</code>
  123. relocation can obtained by enclosing an operand inside of
  124. &lsquo;<samp>%gdop_lox10</samp>&rsquo;. Likewise, <code>R_SPARC_GOTDATA_OP</code> can be
  125. obtained by enclosing an operand inside of &lsquo;<samp>%gdop</samp>&rsquo;.
  126. For example, assuming the GOT base is in register <code>%l7</code>:
  127. </p>
  128. <div class="example">
  129. <pre class="example">sethi %gdop_hix22(symbol), %l1
  130. xor %l1, %gdop_lox10(symbol), %l1
  131. ld [%l7 + %l1], %l2, %gdop(symbol)
  132. </pre></div>
  133. <p>There are many relocations that can be requested for access to
  134. thread local storage variables. All of the Sparc TLS mnemonics
  135. are supported:
  136. </p>
  137. <ul>
  138. <li> <code>R_SPARC_TLS_GD_HI22</code> is requested using &lsquo;<samp>%tgd_hi22</samp>&rsquo;.
  139. </li><li> <code>R_SPARC_TLS_GD_LO10</code> is requested using &lsquo;<samp>%tgd_lo10</samp>&rsquo;.
  140. </li><li> <code>R_SPARC_TLS_GD_ADD</code> is requested using &lsquo;<samp>%tgd_add</samp>&rsquo;.
  141. </li><li> <code>R_SPARC_TLS_GD_CALL</code> is requested using &lsquo;<samp>%tgd_call</samp>&rsquo;.
  142. </li><li> <code>R_SPARC_TLS_LDM_HI22</code> is requested using &lsquo;<samp>%tldm_hi22</samp>&rsquo;.
  143. </li><li> <code>R_SPARC_TLS_LDM_LO10</code> is requested using &lsquo;<samp>%tldm_lo10</samp>&rsquo;.
  144. </li><li> <code>R_SPARC_TLS_LDM_ADD</code> is requested using &lsquo;<samp>%tldm_add</samp>&rsquo;.
  145. </li><li> <code>R_SPARC_TLS_LDM_CALL</code> is requested using &lsquo;<samp>%tldm_call</samp>&rsquo;.
  146. </li><li> <code>R_SPARC_TLS_LDO_HIX22</code> is requested using &lsquo;<samp>%tldo_hix22</samp>&rsquo;.
  147. </li><li> <code>R_SPARC_TLS_LDO_LOX10</code> is requested using &lsquo;<samp>%tldo_lox10</samp>&rsquo;.
  148. </li><li> <code>R_SPARC_TLS_LDO_ADD</code> is requested using &lsquo;<samp>%tldo_add</samp>&rsquo;.
  149. </li><li> <code>R_SPARC_TLS_IE_HI22</code> is requested using &lsquo;<samp>%tie_hi22</samp>&rsquo;.
  150. </li><li> <code>R_SPARC_TLS_IE_LO10</code> is requested using &lsquo;<samp>%tie_lo10</samp>&rsquo;.
  151. </li><li> <code>R_SPARC_TLS_IE_LD</code> is requested using &lsquo;<samp>%tie_ld</samp>&rsquo;.
  152. </li><li> <code>R_SPARC_TLS_IE_LDX</code> is requested using &lsquo;<samp>%tie_ldx</samp>&rsquo;.
  153. </li><li> <code>R_SPARC_TLS_IE_ADD</code> is requested using &lsquo;<samp>%tie_add</samp>&rsquo;.
  154. </li><li> <code>R_SPARC_TLS_LE_HIX22</code> is requested using &lsquo;<samp>%tle_hix22</samp>&rsquo;.
  155. </li><li> <code>R_SPARC_TLS_LE_LOX10</code> is requested using &lsquo;<samp>%tle_lox10</samp>&rsquo;.
  156. </li></ul>
  157. <p>Here are some example TLS model sequences.
  158. </p>
  159. <p>First, General Dynamic:
  160. </p>
  161. <div class="example">
  162. <pre class="example">sethi %tgd_hi22(symbol), %l1
  163. add %l1, %tgd_lo10(symbol), %l1
  164. add %l7, %l1, %o0, %tgd_add(symbol)
  165. call __tls_get_addr, %tgd_call(symbol)
  166. nop
  167. </pre></div>
  168. <p>Local Dynamic:
  169. </p>
  170. <div class="example">
  171. <pre class="example">sethi %tldm_hi22(symbol), %l1
  172. add %l1, %tldm_lo10(symbol), %l1
  173. add %l7, %l1, %o0, %tldm_add(symbol)
  174. call __tls_get_addr, %tldm_call(symbol)
  175. nop
  176. sethi %tldo_hix22(symbol), %l1
  177. xor %l1, %tldo_lox10(symbol), %l1
  178. add %o0, %l1, %l1, %tldo_add(symbol)
  179. </pre></div>
  180. <p>Initial Exec:
  181. </p>
  182. <div class="example">
  183. <pre class="example">sethi %tie_hi22(symbol), %l1
  184. add %l1, %tie_lo10(symbol), %l1
  185. ld [%l7 + %l1], %o0, %tie_ld(symbol)
  186. add %g7, %o0, %o0, %tie_add(symbol)
  187. sethi %tie_hi22(symbol), %l1
  188. add %l1, %tie_lo10(symbol), %l1
  189. ldx [%l7 + %l1], %o0, %tie_ldx(symbol)
  190. add %g7, %o0, %o0, %tie_add(symbol)
  191. </pre></div>
  192. <p>And finally, Local Exec:
  193. </p>
  194. <div class="example">
  195. <pre class="example">sethi %tle_hix22(symbol), %l1
  196. add %l1, %tle_lox10(symbol), %l1
  197. add %g7, %l1, %l1
  198. </pre></div>
  199. <p>When assembling for 64-bit, and a secondary constant addend is
  200. specified in an address expression that would normally generate
  201. an <code>R_SPARC_LO10</code> relocation, the assembler will emit an
  202. <code>R_SPARC_OLO10</code> instead.
  203. </p>
  204. <hr>
  205. <div class="header">
  206. <p>
  207. 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>
  208. </div>
  209. </body>
  210. </html>