Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

317 linhas
16KB

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