OpenRISC_002dRelocs.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 5.1, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>Using as: OpenRISC-Relocs</title>
  15. <meta name="description" content="Using as: OpenRISC-Relocs">
  16. <meta name="keywords" content="Using as: OpenRISC-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="OpenRISC_002dSyntax.html#OpenRISC_002dSyntax" rel="up" title="OpenRISC-Syntax">
  25. <link href="OpenRISC_002dFloat.html#OpenRISC_002dFloat" rel="next" title="OpenRISC-Float">
  26. <link href="OpenRISC_002dRegs.html#OpenRISC_002dRegs" rel="previous" title="OpenRISC-Regs">
  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="OpenRISC_002dRelocs"></a>
  58. <div class="header">
  59. <p>
  60. Previous: <a href="OpenRISC_002dRegs.html#OpenRISC_002dRegs" accesskey="p" rel="previous">OpenRISC-Regs</a>, Up: <a href="OpenRISC_002dSyntax.html#OpenRISC_002dSyntax" accesskey="u" rel="up">OpenRISC-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.33.1.3 Relocations</h4>
  65. <a name="index-OpenRISC-relocations"></a>
  66. <a name="index-relocations_002c-OpenRISC"></a>
  67. <p>ELF relocations are available as defined in the OpenRISC architecture
  68. specification.
  69. </p>
  70. <p><code>R_OR1K_HI_16_IN_INSN</code> is obtained using &lsquo;<samp>hi</samp>&rsquo; and
  71. <code>R_OR1K_LO_16_IN_INSN</code> and <code>R_OR1K_SLO16</code> are obtained using
  72. &lsquo;<samp>lo</samp>&rsquo;. For signed offsets <code>R_OR1K_AHI16</code> is obtained from
  73. &lsquo;<samp>ha</samp>&rsquo;. For example:
  74. </p>
  75. <div class="example">
  76. <pre class="example">l.movhi r5, hi(symbol)
  77. l.ori r5, r5, lo(symbol)
  78. l.movhi r5, ha(symbol)
  79. l.addi r5, r5, lo(symbol)
  80. </pre></div>
  81. <p>These &ldquo;high&rdquo; mnemonics extract bits 31:16 of their operand,
  82. and the &ldquo;low&rdquo; mnemonics extract bits 15:0 of their operand.
  83. </p>
  84. <p>The PC relative relocation <code>R_OR1K_GOTPC_HI16</code> can be obtained by
  85. enclosing an operand inside of &lsquo;<samp>gotpchi</samp>&rsquo;. Likewise, the
  86. <code>R_OR1K_GOTPC_LO16</code> relocation can be obtained using &lsquo;<samp>gotpclo</samp>&rsquo;.
  87. These are mostly used when assembling PIC code. For example, the
  88. standard PIC sequence on OpenRISC to get the base of the global offset
  89. table, PC relative, into a register, can be performed as:
  90. </p>
  91. <div class="example">
  92. <pre class="example">l.jal 0x8
  93. l.movhi r17, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
  94. l.ori r17, r17, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
  95. l.add r17, r17, r9
  96. </pre></div>
  97. <p>Several relocations exist to allow the link editor to perform GOT data
  98. references. The <code>R_OR1K_GOT16</code> relocation can obtained by enclosing an
  99. operand inside of &lsquo;<samp>got</samp>&rsquo;. For example, assuming the GOT base is in
  100. register <code>r17</code>.
  101. </p>
  102. <div class="example">
  103. <pre class="example">l.lwz r19, got(a)(r17)
  104. l.lwz r21, 0(r19)
  105. </pre></div>
  106. <p>Also, several relocations exist for local GOT references. The
  107. <code>R_OR1K_GOTOFF_AHI16</code> relocation can obtained by enclosing an operand
  108. inside of &lsquo;<samp>gotoffha</samp>&rsquo;. Likewise, <code>R_OR1K_GOTOFF_LO16</code> and
  109. <code>R_OR1K_GOTOFF_SLO16</code> can be obtained by enclosing an operand inside of
  110. &lsquo;<samp>gotofflo</samp>&rsquo;. For example, assuming the GOT base is in register
  111. <code>rl7</code>:
  112. </p>
  113. <div class="example">
  114. <pre class="example">l.movhi r19, gotoffha(symbol)
  115. l.add r19, r19, r17
  116. l.lwz r19, gotofflo(symbol)(r19)
  117. </pre></div>
  118. <p>The above PC relative relocations use a <code>l.jal</code> (jump) instruction
  119. and reading of the link register to load the PC. OpenRISC also supports
  120. page offset PC relative locations without a jump instruction using the
  121. <code>l.adrp</code> instruction. By default the <code>l.adrp</code> instruction will
  122. create an <code>R_OR1K_PCREL_PG21</code> relocation.
  123. Likewise, <code>BFD_RELOC_OR1K_LO13</code> and <code>BFD_RELOC_OR1K_SLO13</code> can
  124. be obtained by enclosing an operand inside of &lsquo;<samp>po</samp>&rsquo;. For example:
  125. </p>
  126. <div class="example">
  127. <pre class="example">l.adrp r3, symbol
  128. l.ori r4, r3, po(symbol)
  129. l.lbz r5, po(symbol)(r3)
  130. l.sb po(symbol)(r3), r6
  131. </pre></div>
  132. <p>Likewise the page offset relocations can be used with GOT references. The
  133. relocation <code>R_OR1K_GOT_PG21</code> can be obtained by enclosing an
  134. <code>l.adrp</code> immediate operand inside of &lsquo;<samp>got</samp>&rsquo;. Likewise,
  135. <code>R_OR1K_GOT_LO13</code> can be obtained by enclosing an operand inside of
  136. &lsquo;<samp>gotpo</samp>&rsquo;. For example to load the value of a GOT symbol into register
  137. &lsquo;<samp>r5</samp>&rsquo; we can do:
  138. </p>
  139. <div class="example">
  140. <pre class="example">l.adrp r17, got(_GLOBAL_OFFSET_TABLE_)
  141. l.lwz r5, gotpo(symbol)(r17)
  142. </pre></div>
  143. <p>There are many relocations that can be requested for access to
  144. thread local storage variables. All of the OpenRISC TLS mnemonics
  145. are supported:
  146. </p>
  147. <ul>
  148. <li> <code>R_OR1K_TLS_GD_HI16</code> is requested using &lsquo;<samp>tlsgdhi</samp>&rsquo;.
  149. </li><li> <code>R_OR1K_TLS_GD_LO16</code> is requested using &lsquo;<samp>tlsgdlo</samp>&rsquo;.
  150. </li><li> <code>R_OR1K_TLS_GD_PG21</code> is requested using &lsquo;<samp>tldgd</samp>&rsquo;.
  151. </li><li> <code>R_OR1K_TLS_GD_LO13</code> is requested using &lsquo;<samp>tlsgdpo</samp>&rsquo;.
  152. </li><li> <code>R_OR1K_TLS_LDM_HI16</code> is requested using &lsquo;<samp>tlsldmhi</samp>&rsquo;.
  153. </li><li> <code>R_OR1K_TLS_LDM_LO16</code> is requested using &lsquo;<samp>tlsldmlo</samp>&rsquo;.
  154. </li><li> <code>R_OR1K_TLS_LDM_PG21</code> is requested using &lsquo;<samp>tldldm</samp>&rsquo;.
  155. </li><li> <code>R_OR1K_TLS_LDM_LO13</code> is requested using &lsquo;<samp>tlsldmpo</samp>&rsquo;.
  156. </li><li> <code>R_OR1K_TLS_LDO_HI16</code> is requested using &lsquo;<samp>dtpoffhi</samp>&rsquo;.
  157. </li><li> <code>R_OR1K_TLS_LDO_LO16</code> is requested using &lsquo;<samp>dtpofflo</samp>&rsquo;.
  158. </li><li> <code>R_OR1K_TLS_IE_HI16</code> is requested using &lsquo;<samp>gottpoffhi</samp>&rsquo;.
  159. </li><li> <code>R_OR1K_TLS_IE_AHI16</code> is requested using &lsquo;<samp>gottpoffha</samp>&rsquo;.
  160. </li><li> <code>R_OR1K_TLS_IE_LO16</code> is requested using &lsquo;<samp>gottpofflo</samp>&rsquo;.
  161. </li><li> <code>R_OR1K_TLS_IE_PG21</code> is requested using &lsquo;<samp>gottp</samp>&rsquo;.
  162. </li><li> <code>R_OR1K_TLS_IE_LO13</code> is requested using &lsquo;<samp>gottppo</samp>&rsquo;.
  163. </li><li> <code>R_OR1K_TLS_LE_HI16</code> is requested using &lsquo;<samp>tpoffhi</samp>&rsquo;.
  164. </li><li> <code>R_OR1K_TLS_LE_AHI16</code> is requested using &lsquo;<samp>tpoffha</samp>&rsquo;.
  165. </li><li> <code>R_OR1K_TLS_LE_LO16</code> is requested using &lsquo;<samp>tpofflo</samp>&rsquo;.
  166. </li><li> <code>R_OR1K_TLS_LE_SLO16</code> also is requested using &lsquo;<samp>tpofflo</samp>&rsquo;
  167. depending on the instruction format.
  168. </li></ul>
  169. <p>Here are some example TLS model sequences.
  170. </p>
  171. <p>First, General Dynamic:
  172. </p>
  173. <div class="example">
  174. <pre class="example">l.movhi r17, tlsgdhi(symbol)
  175. l.ori r17, r17, tlsgdlo(symbol)
  176. l.add r17, r17, r16
  177. l.or r3, r17, r17
  178. l.jal plt(__tls_get_addr)
  179. l.nop
  180. </pre></div>
  181. <p>Initial Exec:
  182. </p>
  183. <div class="example">
  184. <pre class="example">l.movhi r17, gottpoffhi(symbol)
  185. l.add r17, r17, r16
  186. l.lwz r17, gottpofflo(symbol)(r17)
  187. l.add r17, r17, r10
  188. l.lbs r17, 0(r17)
  189. </pre></div>
  190. <p>And finally, Local Exec:
  191. </p>
  192. <div class="example">
  193. <pre class="example">l.movhi r17, tpoffha(symbol)
  194. l.add r17, r17, r10
  195. l.addi r17, r17, tpofflo(symbol)
  196. l.lbs r17, 0(r17)
  197. </pre></div>
  198. <hr>
  199. <div class="header">
  200. <p>
  201. Previous: <a href="OpenRISC_002dRegs.html#OpenRISC_002dRegs" accesskey="p" rel="previous">OpenRISC-Regs</a>, Up: <a href="OpenRISC_002dSyntax.html#OpenRISC_002dSyntax" accesskey="u" rel="up">OpenRISC-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>
  202. </div>
  203. </body>
  204. </html>