CFI-directives.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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: CFI directives</title>
  15. <meta name="description" content="Using as: CFI directives">
  16. <meta name="keywords" content="Using as: CFI directives">
  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="Pseudo-Ops.html#Pseudo-Ops" rel="up" title="Pseudo Ops">
  25. <link href="Comm.html#Comm" rel="next" title="Comm">
  26. <link href="Byte.html#Byte" rel="prev" title="Byte">
  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="CFI-directives"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Comm.html#Comm" accesskey="n" rel="next">Comm</a>, Previous: <a href="Byte.html#Byte" accesskey="p" rel="prev">Byte</a>, Up: <a href="Pseudo-Ops.html#Pseudo-Ops" accesskey="u" rel="up">Pseudo Ops</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="CFI-directives-1"></a>
  64. <h3 class="section">7.10 CFI directives</h3>
  65. <a name="g_t_002ecfi_005fsections-section_005flist"></a>
  66. <h4 class="subsection">7.10.1 <code>.cfi_sections <var>section_list</var></code></h4>
  67. <a name="index-cfi_005fsections-directive"></a>
  68. <p><code>.cfi_sections</code> may be used to specify whether CFI directives
  69. should emit <code>.eh_frame</code> section and/or <code>.debug_frame</code> section.
  70. If <var>section_list</var> is <code>.eh_frame</code>, <code>.eh_frame</code> is emitted,
  71. if <var>section_list</var> is <code>.debug_frame</code>, <code>.debug_frame</code> is emitted.
  72. To emit both use <code>.eh_frame, .debug_frame</code>. The default if this
  73. directive is not used is <code>.cfi_sections .eh_frame</code>.
  74. </p>
  75. <p>On targets that support compact unwinding tables these can be generated
  76. by specifying <code>.eh_frame_entry</code> instead of <code>.eh_frame</code>.
  77. </p>
  78. <p>Some targets may support an additional name, such as <code>.c6xabi.exidx</code>
  79. which is used by the target.
  80. </p>
  81. <p>The <code>.cfi_sections</code> directive can be repeated, with the same or different
  82. arguments, provided that CFI generation has not yet started. Once CFI
  83. generation has started however the section list is fixed and any attempts to
  84. redefine it will result in an error.
  85. </p>
  86. <a name="g_t_002ecfi_005fstartproc-_005bsimple_005d"></a>
  87. <h4 class="subsection">7.10.2 <code>.cfi_startproc [simple]</code></h4>
  88. <a name="index-cfi_005fstartproc-directive"></a>
  89. <p><code>.cfi_startproc</code> is used at the beginning of each function that
  90. should have an entry in <code>.eh_frame</code>. It initializes some internal
  91. data structures. Don&rsquo;t forget to close the function by
  92. <code>.cfi_endproc</code>.
  93. </p>
  94. <p>Unless <code>.cfi_startproc</code> is used along with parameter <code>simple</code>
  95. it also emits some architecture dependent initial CFI instructions.
  96. </p>
  97. <a name="g_t_002ecfi_005fendproc"></a>
  98. <h4 class="subsection">7.10.3 <code>.cfi_endproc</code></h4>
  99. <a name="index-cfi_005fendproc-directive"></a>
  100. <p><code>.cfi_endproc</code> is used at the end of a function where it closes its
  101. unwind entry previously opened by
  102. <code>.cfi_startproc</code>, and emits it to <code>.eh_frame</code>.
  103. </p>
  104. <a name="g_t_002ecfi_005fpersonality-encoding-_005b_002c-exp_005d"></a>
  105. <h4 class="subsection">7.10.4 <code>.cfi_personality <var>encoding</var> [, <var>exp</var>]</code></h4>
  106. <a name="index-cfi_005fpersonality-directive"></a>
  107. <p><code>.cfi_personality</code> defines personality routine and its encoding.
  108. <var>encoding</var> must be a constant determining how the personality
  109. should be encoded. If it is 255 (<code>DW_EH_PE_omit</code>), second
  110. argument is not present, otherwise second argument should be
  111. a constant or a symbol name. When using indirect encodings,
  112. the symbol provided should be the location where personality
  113. can be loaded from, not the personality routine itself.
  114. The default after <code>.cfi_startproc</code> is <code>.cfi_personality 0xff</code>,
  115. no personality routine.
  116. </p>
  117. <a name="g_t_002ecfi_005fpersonality_005fid-id"></a>
  118. <h4 class="subsection">7.10.5 <code>.cfi_personality_id <var>id</var></code></h4>
  119. <a name="index-cfi_005fpersonality_005fid-directive"></a>
  120. <p><code>cfi_personality_id</code> defines a personality routine by its index as
  121. defined in a compact unwinding format.
  122. Only valid when generating compact EH frames (i.e.
  123. with <code>.cfi_sections eh_frame_entry</code>.
  124. </p>
  125. <a name="g_t_002ecfi_005ffde_005fdata-_005bopcode1-_005b_002c-_2026_005d_005d"></a>
  126. <h4 class="subsection">7.10.6 <code>.cfi_fde_data [<var>opcode1</var> [, &hellip;]]</code></h4>
  127. <a name="index-cfi_005ffde_005fdata-directive"></a>
  128. <p><code>cfi_fde_data</code> is used to describe the compact unwind opcodes to be
  129. used for the current function. These are emitted inline in the
  130. <code>.eh_frame_entry</code> section if small enough and there is no LSDA, or
  131. in the <code>.gnu.extab</code> section otherwise.
  132. Only valid when generating compact EH frames (i.e.
  133. with <code>.cfi_sections eh_frame_entry</code>.
  134. </p>
  135. <a name="g_t_002ecfi_005flsda-encoding-_005b_002c-exp_005d"></a>
  136. <h4 class="subsection">7.10.7 <code>.cfi_lsda <var>encoding</var> [, <var>exp</var>]</code></h4>
  137. <p><code>.cfi_lsda</code> defines LSDA and its encoding.
  138. <var>encoding</var> must be a constant determining how the LSDA
  139. should be encoded. If it is 255 (<code>DW_EH_PE_omit</code>), the second
  140. argument is not present, otherwise the second argument should be a constant
  141. or a symbol name. The default after <code>.cfi_startproc</code> is <code>.cfi_lsda 0xff</code>,
  142. meaning that no LSDA is present.
  143. </p>
  144. <a name="g_t_002ecfi_005finline_005flsda-_005balign_005d"></a>
  145. <h4 class="subsection">7.10.8 <code>.cfi_inline_lsda</code> [<var>align</var>]</h4>
  146. <p><code>.cfi_inline_lsda</code> marks the start of a LSDA data section and
  147. switches to the corresponding <code>.gnu.extab</code> section.
  148. Must be preceded by a CFI block containing a <code>.cfi_lsda</code> directive.
  149. Only valid when generating compact EH frames (i.e.
  150. with <code>.cfi_sections eh_frame_entry</code>.
  151. </p>
  152. <p>The table header and unwinding opcodes will be generated at this point,
  153. so that they are immediately followed by the LSDA data. The symbol
  154. referenced by the <code>.cfi_lsda</code> directive should still be defined
  155. in case a fallback FDE based encoding is used. The LSDA data is terminated
  156. by a section directive.
  157. </p>
  158. <p>The optional <var>align</var> argument specifies the alignment required.
  159. The alignment is specified as a power of two, as with the
  160. <code>.p2align</code> directive.
  161. </p>
  162. <a name="g_t_002ecfi_005fdef_005fcfa-register_002c-offset"></a>
  163. <h4 class="subsection">7.10.9 <code>.cfi_def_cfa <var>register</var>, <var>offset</var></code></h4>
  164. <p><code>.cfi_def_cfa</code> defines a rule for computing CFA as: <i>take
  165. address from <var>register</var> and add <var>offset</var> to it</i>.
  166. </p>
  167. <a name="g_t_002ecfi_005fdef_005fcfa_005fregister-register"></a>
  168. <h4 class="subsection">7.10.10 <code>.cfi_def_cfa_register <var>register</var></code></h4>
  169. <p><code>.cfi_def_cfa_register</code> modifies a rule for computing CFA. From
  170. now on <var>register</var> will be used instead of the old one. Offset
  171. remains the same.
  172. </p>
  173. <a name="g_t_002ecfi_005fdef_005fcfa_005foffset-offset"></a>
  174. <h4 class="subsection">7.10.11 <code>.cfi_def_cfa_offset <var>offset</var></code></h4>
  175. <p><code>.cfi_def_cfa_offset</code> modifies a rule for computing CFA. Register
  176. remains the same, but <var>offset</var> is new. Note that it is the
  177. absolute offset that will be added to a defined register to compute
  178. CFA address.
  179. </p>
  180. <a name="g_t_002ecfi_005fadjust_005fcfa_005foffset-offset"></a>
  181. <h4 class="subsection">7.10.12 <code>.cfi_adjust_cfa_offset <var>offset</var></code></h4>
  182. <p>Same as <code>.cfi_def_cfa_offset</code> but <var>offset</var> is a relative
  183. value that is added/substracted from the previous offset.
  184. </p>
  185. <a name="g_t_002ecfi_005foffset-register_002c-offset"></a>
  186. <h4 class="subsection">7.10.13 <code>.cfi_offset <var>register</var>, <var>offset</var></code></h4>
  187. <p>Previous value of <var>register</var> is saved at offset <var>offset</var> from
  188. CFA.
  189. </p>
  190. <a name="g_t_002ecfi_005fval_005foffset-register_002c-offset"></a>
  191. <h4 class="subsection">7.10.14 <code>.cfi_val_offset <var>register</var>, <var>offset</var></code></h4>
  192. <p>Previous value of <var>register</var> is CFA + <var>offset</var>.
  193. </p>
  194. <a name="g_t_002ecfi_005frel_005foffset-register_002c-offset"></a>
  195. <h4 class="subsection">7.10.15 <code>.cfi_rel_offset <var>register</var>, <var>offset</var></code></h4>
  196. <p>Previous value of <var>register</var> is saved at offset <var>offset</var> from
  197. the current CFA register. This is transformed to <code>.cfi_offset</code>
  198. using the known displacement of the CFA register from the CFA.
  199. This is often easier to use, because the number will match the
  200. code it&rsquo;s annotating.
  201. </p>
  202. <a name="g_t_002ecfi_005fregister-register1_002c-register2"></a>
  203. <h4 class="subsection">7.10.16 <code>.cfi_register <var>register1</var>, <var>register2</var></code></h4>
  204. <p>Previous value of <var>register1</var> is saved in register <var>register2</var>.
  205. </p>
  206. <a name="g_t_002ecfi_005frestore-register"></a>
  207. <h4 class="subsection">7.10.17 <code>.cfi_restore <var>register</var></code></h4>
  208. <p><code>.cfi_restore</code> says that the rule for <var>register</var> is now the
  209. same as it was at the beginning of the function, after all initial
  210. instruction added by <code>.cfi_startproc</code> were executed.
  211. </p>
  212. <a name="g_t_002ecfi_005fundefined-register"></a>
  213. <h4 class="subsection">7.10.18 <code>.cfi_undefined <var>register</var></code></h4>
  214. <p>From now on the previous value of <var>register</var> can&rsquo;t be restored anymore.
  215. </p>
  216. <a name="g_t_002ecfi_005fsame_005fvalue-register"></a>
  217. <h4 class="subsection">7.10.19 <code>.cfi_same_value <var>register</var></code></h4>
  218. <p>Current value of <var>register</var> is the same like in the previous frame,
  219. i.e. no restoration needed.
  220. </p>
  221. <a name="g_t_002ecfi_005fremember_005fstate-and-_002ecfi_005frestore_005fstate"></a>
  222. <h4 class="subsection">7.10.20 <code>.cfi_remember_state</code> and <code>.cfi_restore_state</code></h4>
  223. <p><code>.cfi_remember_state</code> pushes the set of rules for every register onto an
  224. implicit stack, while <code>.cfi_restore_state</code> pops them off the stack and
  225. places them in the current row. This is useful for situations where you have
  226. multiple <code>.cfi_*</code> directives that need to be undone due to the control
  227. flow of the program. For example, we could have something like this (assuming
  228. the CFA is the value of <code>rbp</code>):
  229. </p>
  230. <div class="smallexample">
  231. <pre class="smallexample"> je label
  232. popq %rbx
  233. .cfi_restore %rbx
  234. popq %r12
  235. .cfi_restore %r12
  236. popq %rbp
  237. .cfi_restore %rbp
  238. .cfi_def_cfa %rsp, 8
  239. ret
  240. label:
  241. /* Do something else */
  242. </pre></div>
  243. <p>Here, we want the <code>.cfi</code> directives to affect only the rows corresponding
  244. to the instructions before <code>label</code>. This means we&rsquo;d have to add multiple
  245. <code>.cfi</code> directives after <code>label</code> to recreate the original save
  246. locations of the registers, as well as setting the CFA back to the value of
  247. <code>rbp</code>. This would be clumsy, and result in a larger binary size. Instead,
  248. we can write:
  249. </p>
  250. <div class="smallexample">
  251. <pre class="smallexample"> je label
  252. popq %rbx
  253. .cfi_remember_state
  254. .cfi_restore %rbx
  255. popq %r12
  256. .cfi_restore %r12
  257. popq %rbp
  258. .cfi_restore %rbp
  259. .cfi_def_cfa %rsp, 8
  260. ret
  261. label:
  262. .cfi_restore_state
  263. /* Do something else */
  264. </pre></div>
  265. <p>That way, the rules for the instructions after <code>label</code> will be the same
  266. as before the first <code>.cfi_restore</code> without having to use multiple
  267. <code>.cfi</code> directives.
  268. </p>
  269. <a name="g_t_002ecfi_005freturn_005fcolumn-register"></a>
  270. <h4 class="subsection">7.10.21 <code>.cfi_return_column <var>register</var></code></h4>
  271. <p>Change return column <var>register</var>, i.e. the return address is either
  272. directly in <var>register</var> or can be accessed by rules for <var>register</var>.
  273. </p>
  274. <a name="g_t_002ecfi_005fsignal_005fframe"></a>
  275. <h4 class="subsection">7.10.22 <code>.cfi_signal_frame</code></h4>
  276. <p>Mark current function as signal trampoline.
  277. </p>
  278. <a name="g_t_002ecfi_005fwindow_005fsave"></a>
  279. <h4 class="subsection">7.10.23 <code>.cfi_window_save</code></h4>
  280. <p>SPARC register window has been saved.
  281. </p>
  282. <a name="g_t_002ecfi_005fescape-expression_005b_002c-_2026_005d"></a>
  283. <h4 class="subsection">7.10.24 <code>.cfi_escape</code> <var>expression</var>[, &hellip;]</h4>
  284. <p>Allows the user to add arbitrary bytes to the unwind info. One
  285. might use this to add OS-specific CFI opcodes, or generic CFI
  286. opcodes that GAS does not yet support.
  287. </p>
  288. <a name="g_t_002ecfi_005fval_005fencoded_005faddr-register_002c-encoding_002c-label"></a>
  289. <h4 class="subsection">7.10.25 <code>.cfi_val_encoded_addr <var>register</var>, <var>encoding</var>, <var>label</var></code></h4>
  290. <p>The current value of <var>register</var> is <var>label</var>. The value of <var>label</var>
  291. will be encoded in the output file according to <var>encoding</var>; see the
  292. description of <code>.cfi_personality</code> for details on this encoding.
  293. </p>
  294. <p>The usefulness of equating a register to a fixed label is probably
  295. limited to the return address register. Here, it can be useful to
  296. mark a code segment that has only one return address which is reached
  297. by a direct branch and no copy of the return address exists in memory
  298. or another register.
  299. </p>
  300. <hr>
  301. <div class="header">
  302. <p>
  303. Next: <a href="Comm.html#Comm" accesskey="n" rel="next">Comm</a>, Previous: <a href="Byte.html#Byte" accesskey="p" rel="prev">Byte</a>, Up: <a href="Pseudo-Ops.html#Pseudo-Ops" accesskey="u" rel="up">Pseudo Ops</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>
  304. </div>
  305. </body>
  306. </html>