Section.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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-2021 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.84 <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>R</code></dt>
  210. <dd><p>retained section (apply SHF_GNU_RETAIN to prevent linker garbage
  211. collection, GNU ELF extension)
  212. </p></dd>
  213. <dt><code><code>&lt;number&gt;</code></code></dt>
  214. <dd><p>a numeric value indicating the bits to be set in the ELF section header&rsquo;s flags
  215. field. Note - if one or more of the alphabetic characters described above is
  216. also included in the flags field, their bit values will be ORed into the
  217. resulting value.
  218. </p></dd>
  219. <dt><code><code>&lt;target specific&gt;</code></code></dt>
  220. <dd><p>some targets extend this list with their own flag characters
  221. </p></dd>
  222. </dl>
  223. <p>Note - once a section&rsquo;s flags have been set they cannot be changed. There are
  224. a few exceptions to this rule however. Processor and application specific
  225. flags can be added to an already defined section. The <code>.interp</code>,
  226. <code>.strtab</code> and <code>.symtab</code> sections can have the allocate flag
  227. (<code>a</code>) set after they are initially defined, and the <code>.note-GNU-stack</code>
  228. section may have the executable (<code>x</code>) flag added. Also note that the
  229. <code>.attach_to_group</code> directive can be used to add a section to a group even
  230. if the section was not originally declared to be part of that group.
  231. </p>
  232. <p>The optional <var>type</var> argument may contain one of the following constants:
  233. </p>
  234. <dl compact="compact">
  235. <dt><code>@progbits</code></dt>
  236. <dd><p>section contains data
  237. </p></dd>
  238. <dt><code>@nobits</code></dt>
  239. <dd><p>section does not contain data (i.e., section only occupies space)
  240. </p></dd>
  241. <dt><code>@note</code></dt>
  242. <dd><p>section contains data which is used by things other than the program
  243. </p></dd>
  244. <dt><code>@init_array</code></dt>
  245. <dd><p>section contains an array of pointers to init functions
  246. </p></dd>
  247. <dt><code>@fini_array</code></dt>
  248. <dd><p>section contains an array of pointers to finish functions
  249. </p></dd>
  250. <dt><code>@preinit_array</code></dt>
  251. <dd><p>section contains an array of pointers to pre-init functions
  252. </p></dd>
  253. <dt><code>@<code>&lt;number&gt;</code></code></dt>
  254. <dd><p>a numeric value to be set as the ELF section header&rsquo;s type field.
  255. </p></dd>
  256. <dt><code>@<code>&lt;target specific&gt;</code></code></dt>
  257. <dd><p>some targets extend this list with their own types
  258. </p></dd>
  259. </dl>
  260. <p>Many targets only support the first three section types. The type may be
  261. enclosed in double quotes if necessary.
  262. </p>
  263. <p>Note on targets where the <code>@</code> character is the start of a comment (eg
  264. ARM) then another character is used instead. For example the ARM port uses the
  265. <code>%</code> character.
  266. </p>
  267. <p>Note - some sections, eg <code>.text</code> and <code>.data</code> are considered to be
  268. special and have fixed types. Any attempt to declare them with a different
  269. type will generate an error from the assembler.
  270. </p>
  271. <p>If <var>flags</var> contains the <code>M</code> symbol then the <var>type</var> argument must
  272. be specified as well as an extra argument&mdash;<var>entsize</var>&mdash;like this:
  273. </p>
  274. <div class="smallexample">
  275. <pre class="smallexample">.section <var>name</var> , &quot;<var>flags</var>&quot;M, @<var>type</var>, <var>entsize</var>
  276. </pre></div>
  277. <p>Sections with the <code>M</code> flag but not <code>S</code> flag must contain fixed size
  278. constants, each <var>entsize</var> octets long. Sections with both <code>M</code> and
  279. <code>S</code> must contain zero terminated strings where each character is
  280. <var>entsize</var> bytes long. The linker may remove duplicates within sections with
  281. the same name, same entity size and same flags. <var>entsize</var> must be an
  282. absolute expression. For sections with both <code>M</code> and <code>S</code>, a string
  283. which is a suffix of a larger string is considered a duplicate. Thus
  284. <code>&quot;def&quot;</code> will be merged with <code>&quot;abcdef&quot;</code>; A reference to the first
  285. <code>&quot;def&quot;</code> will be changed to a reference to <code>&quot;abcdef&quot;+3</code>.
  286. </p>
  287. <p>If <var>flags</var> contains the <code>o</code> flag, then the <var>type</var> argument
  288. must be present along with an additional field like this:
  289. </p>
  290. <div class="smallexample">
  291. <pre class="smallexample">.section <var>name</var>,&quot;<var>flags</var>&quot;o,@<var>type</var>,<var>SymbolName</var>|<var>SectionIndex</var>
  292. </pre></div>
  293. <p>The <var>SymbolName</var> field specifies the symbol name which the section
  294. references. Alternatively a numeric <var>SectionIndex</var> can be provided. This
  295. is not generally a good idea as section indicies are rarely known at assembly
  296. time, but the facility is provided for testing purposes. An index of zero is
  297. allowed. It indicates that the linked-to section has already been discarded.
  298. </p>
  299. <p>Note: If both the <var>M</var> and <var>o</var> flags are present, then the fields
  300. for the Merge flag should come first, like this:
  301. </p>
  302. <div class="smallexample">
  303. <pre class="smallexample">.section <var>name</var>,&quot;<var>flags</var>&quot;Mo,@<var>type</var>,<var>entsize</var>,<var>SymbolName</var>
  304. </pre></div>
  305. <p>If <var>flags</var> contains the <code>G</code> symbol then the <var>type</var> argument must
  306. be present along with an additional field like this:
  307. </p>
  308. <div class="smallexample">
  309. <pre class="smallexample">.section <var>name</var> , &quot;<var>flags</var>&quot;G, @<var>type</var>, <var>GroupName</var>[, <var>linkage</var>]
  310. </pre></div>
  311. <p>The <var>GroupName</var> field specifies the name of the section group to which this
  312. particular section belongs. The optional linkage field can contain:
  313. </p>
  314. <dl compact="compact">
  315. <dt><code>comdat</code></dt>
  316. <dd><p>indicates that only one copy of this section should be retained
  317. </p></dd>
  318. <dt><code>.gnu.linkonce</code></dt>
  319. <dd><p>an alias for comdat
  320. </p></dd>
  321. </dl>
  322. <p>Note: if both the <var>M</var> and <var>G</var> flags are present then the fields for
  323. the Merge flag should come first, like this:
  324. </p>
  325. <div class="smallexample">
  326. <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>]
  327. </pre></div>
  328. <p>If both <code>o</code> flag and <code>G</code> flag are present, then the
  329. <var>SymbolName</var> field for <code>o</code> comes first, like this:
  330. </p>
  331. <div class="smallexample">
  332. <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>]
  333. </pre></div>
  334. <p>If <var>flags</var> contains the <code>?</code> symbol then it may not also contain the
  335. <code>G</code> symbol and the <var>GroupName</var> or <var>linkage</var> fields should not be
  336. present. Instead, <code>?</code> says to consider the section that&rsquo;s current before
  337. this directive. If that section used <code>G</code>, then the new section will use
  338. <code>G</code> with those same <var>GroupName</var> and <var>linkage</var> fields implicitly.
  339. If not, then the <code>?</code> symbol has no effect.
  340. </p>
  341. <p>The optional <var>unique,<code>&lt;number&gt;</code></var> argument must come last. It
  342. assigns <var><code>&lt;number&gt;</code></var> as a unique section ID to distinguish
  343. different sections with the same section name like these:
  344. </p>
  345. <div class="smallexample">
  346. <pre class="smallexample">.section <var>name</var>,&quot;<var>flags</var>&quot;,@<var>type</var>,<var>unique,<code>&lt;number&gt;</code></var>
  347. .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>
  348. .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>
  349. </pre></div>
  350. <p>The valid values of <var><code>&lt;number&gt;</code></var> are between 0 and 4294967295.
  351. </p>
  352. <p>If no flags are specified, the default flags depend upon the section name. If
  353. the section name is not recognized, the default will be for the section to have
  354. none of the above flags: it will not be allocated in memory, nor writable, nor
  355. executable. The section will contain data.
  356. </p>
  357. <p>For ELF targets, the assembler supports another type of <code>.section</code>
  358. directive for compatibility with the Solaris assembler:
  359. </p>
  360. <div class="smallexample">
  361. <pre class="smallexample">.section &quot;<var>name</var>&quot;[, <var>flags</var>...]
  362. </pre></div>
  363. <p>Note that the section name is quoted. There may be a sequence of comma
  364. separated flags:
  365. </p>
  366. <dl compact="compact">
  367. <dt><code>#alloc</code></dt>
  368. <dd><p>section is allocatable
  369. </p></dd>
  370. <dt><code>#write</code></dt>
  371. <dd><p>section is writable
  372. </p></dd>
  373. <dt><code>#execinstr</code></dt>
  374. <dd><p>section is executable
  375. </p></dd>
  376. <dt><code>#exclude</code></dt>
  377. <dd><p>section is excluded from executable and shared library.
  378. </p></dd>
  379. <dt><code>#tls</code></dt>
  380. <dd><p>section is used for thread local storage
  381. </p></dd>
  382. </dl>
  383. <p>This directive replaces the current section and subsection. See the
  384. contents of the gas testsuite directory <code>gas/testsuite/gas/elf</code> for
  385. some examples of how this directive and the other section stack directives
  386. work.
  387. </p>
  388. <hr>
  389. <div class="header">
  390. <p>
  391. 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>
  392. </div>
  393. </body>
  394. </html>