Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

416 lines
17KB

  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>Section (Using as)</title>
  16. <meta name="description" content="Section (Using as)">
  17. <meta name="keywords" content="Section (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="Set.html#Set" rel="next" title="Set">
  26. <link href="Scl.html#Scl" rel="prev" title="Scl">
  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="Section"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="Set.html#Set" accesskey="n" rel="next">Set</a>, Previous: <a href="Scl.html#Scl" accesskey="p" rel="prev">Scl</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="g_t_002esection-name"></a>
  63. <h3 class="section">7.83 <code>.section <var>name</var></code></h3>
  64. <a name="index-named-section"></a>
  65. <p>Use the <code>.section</code> directive to assemble the following code into a section
  66. named <var>name</var>.
  67. </p>
  68. <p>This directive is only supported for targets that actually support arbitrarily
  69. named sections; on <code>a.out</code> targets, for example, it is not accepted, even
  70. with a standard <code>a.out</code> section name.
  71. </p>
  72. <a name="COFF-Version"></a>
  73. <h4 class="subheading">COFF Version</h4>
  74. <a name="index-section-directive-_0028COFF-version_0029"></a>
  75. <p>For COFF targets, the <code>.section</code> directive is used in one of the following
  76. ways:
  77. </p>
  78. <div class="smallexample">
  79. <pre class="smallexample">.section <var>name</var>[, &quot;<var>flags</var>&quot;]
  80. .section <var>name</var>[, <var>subsection</var>]
  81. </pre></div>
  82. <p>If the optional argument is quoted, it is taken as flags to use for the
  83. section. Each flag is a single character. The following flags are recognized:
  84. </p>
  85. <dl compact="compact">
  86. <dt><code>b</code></dt>
  87. <dd><p>bss section (uninitialized data)
  88. </p></dd>
  89. <dt><code>n</code></dt>
  90. <dd><p>section is not loaded
  91. </p></dd>
  92. <dt><code>w</code></dt>
  93. <dd><p>writable section
  94. </p></dd>
  95. <dt><code>d</code></dt>
  96. <dd><p>data section
  97. </p></dd>
  98. <dt><code>e</code></dt>
  99. <dd><p>exclude section from linking
  100. </p></dd>
  101. <dt><code>r</code></dt>
  102. <dd><p>read-only section
  103. </p></dd>
  104. <dt><code>x</code></dt>
  105. <dd><p>executable section
  106. </p></dd>
  107. <dt><code>s</code></dt>
  108. <dd><p>shared section (meaningful for PE targets)
  109. </p></dd>
  110. <dt><code>a</code></dt>
  111. <dd><p>ignored. (For compatibility with the ELF version)
  112. </p></dd>
  113. <dt><code>y</code></dt>
  114. <dd><p>section is not readable (meaningful for PE targets)
  115. </p></dd>
  116. <dt><code>0-9</code></dt>
  117. <dd><p>single-digit power-of-two section alignment (GNU extension)
  118. </p></dd>
  119. </dl>
  120. <p>If no flags are specified, the default flags depend upon the section name. If
  121. the section name is not recognized, the default will be for the section to be
  122. loaded and writable. Note the <code>n</code> and <code>w</code> flags remove attributes
  123. from the section, rather than adding them, so if they are used on their own it
  124. will be as if no flags had been specified at all.
  125. </p>
  126. <p>If the optional argument to the <code>.section</code> directive is not quoted, it is
  127. taken as a subsection number (see <a href="Sub_002dSections.html#Sub_002dSections">Sub-Sections</a>).
  128. </p>
  129. <a name="ELF-Version"></a>
  130. <h4 class="subheading">ELF Version</h4>
  131. <a name="index-Section-Stack-3"></a>
  132. <p>This is one of the ELF section stack manipulation directives. The others are
  133. <code>.subsection</code> (see <a href="SubSection.html#SubSection">SubSection</a>), <code>.pushsection</code>
  134. (see <a href="PushSection.html#PushSection">PushSection</a>), <code>.popsection</code> (see <a href="PopSection.html#PopSection">PopSection</a>), and
  135. <code>.previous</code> (see <a href="Previous.html#Previous">Previous</a>).
  136. </p>
  137. <a name="index-section-directive-_0028ELF-version_0029"></a>
  138. <p>For ELF targets, the <code>.section</code> directive is used like this:
  139. </p>
  140. <div class="smallexample">
  141. <pre class="smallexample">.section <var>name</var> [, &quot;<var>flags</var>&quot;[, @<var>type</var>[,<var>flag_specific_arguments</var>]]]
  142. </pre></div>
  143. <a name="Section-Name-Substitutions"></a><a name="index-_002d_002dsectname_002dsubst"></a>
  144. <a name="index-section-name-substitution"></a>
  145. <p>If the &lsquo;<samp>--sectname-subst</samp>&rsquo; command-line option is provided, the <var>name</var>
  146. argument may contain a substitution sequence. Only <code>%S</code> is supported
  147. at the moment, and substitutes the current section name. For example:
  148. </p>
  149. <div class="smallexample">
  150. <pre class="smallexample">.macro exception_code
  151. .section %S.exception
  152. [exception code here]
  153. .previous
  154. .endm
  155. .text
  156. [code]
  157. exception_code
  158. [...]
  159. .section .init
  160. [init code]
  161. exception_code
  162. [...]
  163. </pre></div>
  164. <p>The two <code>exception_code</code> invocations above would create the
  165. <code>.text.exception</code> and <code>.init.exception</code> sections respectively.
  166. This is useful e.g. to discriminate between ancillary sections that are
  167. tied to setup code to be discarded after use from ancillary sections that
  168. need to stay resident without having to define multiple <code>exception_code</code>
  169. macros just for that purpose.
  170. </p>
  171. <p>The optional <var>flags</var> argument is a quoted string which may contain any
  172. combination of the following characters:
  173. </p>
  174. <dl compact="compact">
  175. <dt><code>a</code></dt>
  176. <dd><p>section is allocatable
  177. </p></dd>
  178. <dt><code>d</code></dt>
  179. <dd><p>section is a GNU_MBIND section
  180. </p></dd>
  181. <dt><code>e</code></dt>
  182. <dd><p>section is excluded from executable and shared library.
  183. </p></dd>
  184. <dt><code>o</code></dt>
  185. <dd><p>section references a symbol defined in another section (the linked-to
  186. section) in the same file.
  187. </p></dd>
  188. <dt><code>w</code></dt>
  189. <dd><p>section is writable
  190. </p></dd>
  191. <dt><code>x</code></dt>
  192. <dd><p>section is executable
  193. </p></dd>
  194. <dt><code>M</code></dt>
  195. <dd><p>section is mergeable
  196. </p></dd>
  197. <dt><code>S</code></dt>
  198. <dd><p>section contains zero terminated strings
  199. </p></dd>
  200. <dt><code>G</code></dt>
  201. <dd><p>section is a member of a section group
  202. </p></dd>
  203. <dt><code>T</code></dt>
  204. <dd><p>section is used for thread-local-storage
  205. </p></dd>
  206. <dt><code>?</code></dt>
  207. <dd><p>section is a member of the previously-current section&rsquo;s group, if any
  208. </p></dd>
  209. <dt><code><code>&lt;number&gt;</code></code></dt>
  210. <dd><p>a numeric value indicating the bits to be set in the ELF section header&rsquo;s flags
  211. field. Note - if one or more of the alphabetic characters described above is
  212. also included in the flags field, their bit values will be ORed into the
  213. resulting value.
  214. </p></dd>
  215. <dt><code><code>&lt;target specific&gt;</code></code></dt>
  216. <dd><p>some targets extend this list with their own flag characters
  217. </p></dd>
  218. </dl>
  219. <p>Note - once a section&rsquo;s flags have been set they cannot be changed. There are
  220. a few exceptions to this rule however. Processor and application specific
  221. flags can be added to an already defined section. The <code>.interp</code>,
  222. <code>.strtab</code> and <code>.symtab</code> sections can have the allocate flag
  223. (<code>a</code>) set after they are initially defined, and the <code>.note-GNU-stack</code>
  224. section may have the executable (<code>x</code>) flag added.
  225. </p>
  226. <p>The optional <var>type</var> argument may contain one of the following constants:
  227. </p>
  228. <dl compact="compact">
  229. <dt><code>@progbits</code></dt>
  230. <dd><p>section contains data
  231. </p></dd>
  232. <dt><code>@nobits</code></dt>
  233. <dd><p>section does not contain data (i.e., section only occupies space)
  234. </p></dd>
  235. <dt><code>@note</code></dt>
  236. <dd><p>section contains data which is used by things other than the program
  237. </p></dd>
  238. <dt><code>@init_array</code></dt>
  239. <dd><p>section contains an array of pointers to init functions
  240. </p></dd>
  241. <dt><code>@fini_array</code></dt>
  242. <dd><p>section contains an array of pointers to finish functions
  243. </p></dd>
  244. <dt><code>@preinit_array</code></dt>
  245. <dd><p>section contains an array of pointers to pre-init functions
  246. </p></dd>
  247. <dt><code>@<code>&lt;number&gt;</code></code></dt>
  248. <dd><p>a numeric value to be set as the ELF section header&rsquo;s type field.
  249. </p></dd>
  250. <dt><code>@<code>&lt;target specific&gt;</code></code></dt>
  251. <dd><p>some targets extend this list with their own types
  252. </p></dd>
  253. </dl>
  254. <p>Many targets only support the first three section types. The type may be
  255. enclosed in double quotes if necessary.
  256. </p>
  257. <p>Note on targets where the <code>@</code> character is the start of a comment (eg
  258. ARM) then another character is used instead. For example the ARM port uses the
  259. <code>%</code> character.
  260. </p>
  261. <p>Note - some sections, eg <code>.text</code> and <code>.data</code> are considered to be
  262. special and have fixed types. Any attempt to declare them with a different
  263. type will generate an error from the assembler.
  264. </p>
  265. <p>If <var>flags</var> contains the <code>M</code> symbol then the <var>type</var> argument must
  266. be specified as well as an extra argument&mdash;<var>entsize</var>&mdash;like this:
  267. </p>
  268. <div class="smallexample">
  269. <pre class="smallexample">.section <var>name</var> , &quot;<var>flags</var>&quot;M, @<var>type</var>, <var>entsize</var>
  270. </pre></div>
  271. <p>Sections with the <code>M</code> flag but not <code>S</code> flag must contain fixed size
  272. constants, each <var>entsize</var> octets long. Sections with both <code>M</code> and
  273. <code>S</code> must contain zero terminated strings where each character is
  274. <var>entsize</var> bytes long. The linker may remove duplicates within sections with
  275. the same name, same entity size and same flags. <var>entsize</var> must be an
  276. absolute expression. For sections with both <code>M</code> and <code>S</code>, a string
  277. which is a suffix of a larger string is considered a duplicate. Thus
  278. <code>&quot;def&quot;</code> will be merged with <code>&quot;abcdef&quot;</code>; A reference to the first
  279. <code>&quot;def&quot;</code> will be changed to a reference to <code>&quot;abcdef&quot;+3</code>.
  280. </p>
  281. <p>If <var>flags</var> contains the <code>o</code> flag, then the <var>type</var> argument
  282. must be present along with an additional field like this:
  283. </p>
  284. <div class="smallexample">
  285. <pre class="smallexample">.section <var>name</var>,&quot;<var>flags</var>&quot;o,@<var>type</var>,<var>SymbolName</var>
  286. </pre></div>
  287. <p>The <var>SymbolName</var> field specifies the symbol name which the section
  288. references.
  289. </p>
  290. <p>Note: If both the <var>M</var> and <var>o</var> flags are present, then the fields
  291. for the Merge flag should come first, like this:
  292. </p>
  293. <div class="smallexample">
  294. <pre class="smallexample">.section <var>name</var>,&quot;<var>flags</var>&quot;Mo,@<var>type</var>,<var>entsize</var>,<var>SymbolName</var>
  295. </pre></div>
  296. <p>If <var>flags</var> contains the <code>G</code> symbol then the <var>type</var> argument must
  297. be present along with an additional field like this:
  298. </p>
  299. <div class="smallexample">
  300. <pre class="smallexample">.section <var>name</var> , &quot;<var>flags</var>&quot;G, @<var>type</var>, <var>GroupName</var>[, <var>linkage</var>]
  301. </pre></div>
  302. <p>The <var>GroupName</var> field specifies the name of the section group to which this
  303. particular section belongs. The optional linkage field can contain:
  304. </p>
  305. <dl compact="compact">
  306. <dt><code>comdat</code></dt>
  307. <dd><p>indicates that only one copy of this section should be retained
  308. </p></dd>
  309. <dt><code>.gnu.linkonce</code></dt>
  310. <dd><p>an alias for comdat
  311. </p></dd>
  312. </dl>
  313. <p>Note: if both the <var>M</var> and <var>G</var> flags are present then the fields for
  314. the Merge flag should come first, like this:
  315. </p>
  316. <div class="smallexample">
  317. <pre class="smallexample">.section <var>name</var> , &quot;<var>flags</var>&quot;MG, @<var>type</var>, <var>entsize</var>, <var>GroupName</var>[, <var>linkage</var>]
  318. </pre></div>
  319. <p>If both <code>o</code> flag and <code>G</code> flag are present, then the
  320. <var>SymbolName</var> field for <code>o</code> comes first, like this:
  321. </p>
  322. <div class="smallexample">
  323. <pre class="smallexample">.section <var>name</var>,&quot;<var>flags</var>&quot;oG,@<var>type</var>,<var>SymbolName</var>,<var>GroupName</var>[,<var>linkage</var>]
  324. </pre></div>
  325. <p>If <var>flags</var> contains the <code>?</code> symbol then it may not also contain the
  326. <code>G</code> symbol and the <var>GroupName</var> or <var>linkage</var> fields should not be
  327. present. Instead, <code>?</code> says to consider the section that&rsquo;s current before
  328. this directive. If that section used <code>G</code>, then the new section will use
  329. <code>G</code> with those same <var>GroupName</var> and <var>linkage</var> fields implicitly.
  330. If not, then the <code>?</code> symbol has no effect.
  331. </p>
  332. <p>The optional <var>unique,<code>&lt;number&gt;</code></var> argument must come last. It
  333. assigns <var><code>&lt;number&gt;</code></var> as a unique section ID to distinguish
  334. different sections with the same section name like these:
  335. </p>
  336. <div class="smallexample">
  337. <pre class="smallexample">.section <var>name</var>,&quot;<var>flags</var>&quot;,@<var>type</var>,<var>unique,<code>&lt;number&gt;</code></var>
  338. .section <var>name</var>,&quot;<var>flags</var>&quot;G,@<var>type</var>,<var>GroupName</var>,[<var>linkage</var>],<var>unique,<code>&lt;number&gt;</code></var>
  339. .section <var>name</var>,&quot;<var>flags</var>&quot;MG,@<var>type</var>,<var>entsize</var>,<var>GroupName</var>[,<var>linkage</var>],<var>unique,<code>&lt;number&gt;</code></var>
  340. </pre></div>
  341. <p>The valid values of <var><code>&lt;number&gt;</code></var> are between 0 and 4294967295.
  342. </p>
  343. <p>If no flags are specified, the default flags depend upon the section name. If
  344. the section name is not recognized, the default will be for the section to have
  345. none of the above flags: it will not be allocated in memory, nor writable, nor
  346. executable. The section will contain data.
  347. </p>
  348. <p>For ELF targets, the assembler supports another type of <code>.section</code>
  349. directive for compatibility with the Solaris assembler:
  350. </p>
  351. <div class="smallexample">
  352. <pre class="smallexample">.section &quot;<var>name</var>&quot;[, <var>flags</var>...]
  353. </pre></div>
  354. <p>Note that the section name is quoted. There may be a sequence of comma
  355. separated flags:
  356. </p>
  357. <dl compact="compact">
  358. <dt><code>#alloc</code></dt>
  359. <dd><p>section is allocatable
  360. </p></dd>
  361. <dt><code>#write</code></dt>
  362. <dd><p>section is writable
  363. </p></dd>
  364. <dt><code>#execinstr</code></dt>
  365. <dd><p>section is executable
  366. </p></dd>
  367. <dt><code>#exclude</code></dt>
  368. <dd><p>section is excluded from executable and shared library.
  369. </p></dd>
  370. <dt><code>#tls</code></dt>
  371. <dd><p>section is used for thread local storage
  372. </p></dd>
  373. </dl>
  374. <p>This directive replaces the current section and subsection. See the
  375. contents of the gas testsuite directory <code>gas/testsuite/gas/elf</code> for
  376. some examples of how this directive and the other section stack directives
  377. work.
  378. </p>
  379. <hr>
  380. <div class="header">
  381. <p>
  382. Next: <a href="Set.html#Set" accesskey="n" rel="next">Set</a>, Previous: <a href="Scl.html#Scl" accesskey="p" rel="prev">Scl</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>
  383. </div>
  384. </body>
  385. </html>