Input-Section-Wildcards.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 linker LD
  4. (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16))
  5. version 2.35.1.
  6. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  7. Permission is granted to copy, distribute and/or modify this document
  8. under the terms of the GNU Free Documentation License, Version 1.3
  9. or any later version published by the Free Software Foundation;
  10. with no Invariant Sections, with no Front-Cover Texts, and with no
  11. Back-Cover Texts. A copy of the license is included in the
  12. section entitled "GNU Free Documentation License". -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>LD: Input Section Wildcards</title>
  16. <meta name="description" content="LD: Input Section Wildcards">
  17. <meta name="keywords" content="LD: Input Section Wildcards">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Input-Section.html#Input-Section" rel="up" title="Input Section">
  26. <link href="Input-Section-Common.html#Input-Section-Common" rel="next" title="Input Section Common">
  27. <link href="Input-Section-Basics.html#Input-Section-Basics" rel="previous" title="Input Section Basics">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {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.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Input-Section-Wildcards"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Input-Section-Common.html#Input-Section-Common" accesskey="n" rel="next">Input Section Common</a>, Previous: <a href="Input-Section-Basics.html#Input-Section-Basics" accesskey="p" rel="previous">Input Section Basics</a>, Up: <a href="Input-Section.html#Input-Section" accesskey="u" rel="up">Input Section</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  62. </div>
  63. <hr>
  64. <a name="Input-Section-Wildcard-Patterns"></a>
  65. <h4 class="subsubsection">3.6.4.2 Input Section Wildcard Patterns</h4>
  66. <a name="index-input-section-wildcards"></a>
  67. <a name="index-wildcard-file-name-patterns"></a>
  68. <a name="index-file-name-wildcard-patterns"></a>
  69. <a name="index-section-name-wildcard-patterns"></a>
  70. <p>In an input section description, either the file name or the section
  71. name or both may be wildcard patterns.
  72. </p>
  73. <p>The file name of &lsquo;<samp>*</samp>&rsquo; seen in many examples is a simple wildcard
  74. pattern for the file name.
  75. </p>
  76. <p>The wildcard patterns are like those used by the Unix shell.
  77. </p>
  78. <dl compact="compact">
  79. <dt>&lsquo;<samp>*</samp>&rsquo;</dt>
  80. <dd><p>matches any number of characters
  81. </p></dd>
  82. <dt>&lsquo;<samp>?</samp>&rsquo;</dt>
  83. <dd><p>matches any single character
  84. </p></dd>
  85. <dt>&lsquo;<samp>[<var>chars</var>]</samp>&rsquo;</dt>
  86. <dd><p>matches a single instance of any of the <var>chars</var>; the &lsquo;<samp>-</samp>&rsquo;
  87. character may be used to specify a range of characters, as in
  88. &lsquo;<samp>[a-z]</samp>&rsquo; to match any lower case letter
  89. </p></dd>
  90. <dt>&lsquo;<samp>\</samp>&rsquo;</dt>
  91. <dd><p>quotes the following character
  92. </p></dd>
  93. </dl>
  94. <p>When a file name is matched with a wildcard, the wildcard characters
  95. will not match a &lsquo;<samp>/</samp>&rsquo; character (used to separate directory names on
  96. Unix). A pattern consisting of a single &lsquo;<samp>*</samp>&rsquo; character is an
  97. exception; it will always match any file name, whether it contains a
  98. &lsquo;<samp>/</samp>&rsquo; or not. In a section name, the wildcard characters will match
  99. a &lsquo;<samp>/</samp>&rsquo; character.
  100. </p>
  101. <p>File name wildcard patterns only match files which are explicitly
  102. specified on the command line or in an <code>INPUT</code> command. The linker
  103. does not search directories to expand wildcards.
  104. </p>
  105. <p>If a file name matches more than one wildcard pattern, or if a file name
  106. appears explicitly and is also matched by a wildcard pattern, the linker
  107. will use the first match in the linker script. For example, this
  108. sequence of input section descriptions is probably in error, because the
  109. <samp>data.o</samp> rule will not be used:
  110. </p><div class="smallexample">
  111. <pre class="smallexample">.data : { *(.data) }
  112. .data1 : { data.o(.data) }
  113. </pre></div>
  114. <a name="index-SORT_005fBY_005fNAME"></a>
  115. <p>Normally, the linker will place files and sections matched by wildcards
  116. in the order in which they are seen during the link. You can change
  117. this by using the <code>SORT_BY_NAME</code> keyword, which appears before a wildcard
  118. pattern in parentheses (e.g., <code>SORT_BY_NAME(.text*)</code>). When the
  119. <code>SORT_BY_NAME</code> keyword is used, the linker will sort the files or sections
  120. into ascending order by name before placing them in the output file.
  121. </p>
  122. <a name="index-SORT_005fBY_005fALIGNMENT"></a>
  123. <p><code>SORT_BY_ALIGNMENT</code> is similar to <code>SORT_BY_NAME</code>.
  124. <code>SORT_BY_ALIGNMENT</code> will sort sections into descending order of
  125. alignment before placing them in the output file. Placing larger
  126. alignments before smaller alignments can reduce the amount of padding
  127. needed.
  128. </p>
  129. <a name="index-SORT_005fBY_005fINIT_005fPRIORITY"></a>
  130. <p><code>SORT_BY_INIT_PRIORITY</code> is also similar to <code>SORT_BY_NAME</code>.
  131. <code>SORT_BY_INIT_PRIORITY</code> will sort sections into ascending
  132. numerical order of the GCC init_priority attribute encoded in the
  133. section name before placing them in the output file. In
  134. <code>.init_array.NNNNN</code> and <code>.fini_array.NNNNN</code>, <code>NNNNN</code> is
  135. the init_priority. In <code>.ctors.NNNNN</code> and <code>.dtors.NNNNN</code>,
  136. <code>NNNNN</code> is 65535 minus the init_priority.
  137. </p>
  138. <a name="index-SORT"></a>
  139. <p><code>SORT</code> is an alias for <code>SORT_BY_NAME</code>.
  140. </p>
  141. <p>When there are nested section sorting commands in linker script, there
  142. can be at most 1 level of nesting for section sorting commands.
  143. </p>
  144. <ol>
  145. <li> <code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)).
  146. It will sort the input sections by name first, then by alignment if two
  147. sections have the same name.
  148. </li><li> <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)).
  149. It will sort the input sections by alignment first, then by name if two
  150. sections have the same alignment.
  151. </li><li> <code>SORT_BY_NAME</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)) is
  152. treated the same as <code>SORT_BY_NAME</code> (wildcard section pattern).
  153. </li><li> <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern))
  154. is treated the same as <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern).
  155. </li><li> All other nested section sorting commands are invalid.
  156. </li></ol>
  157. <p>When both command-line section sorting option and linker script
  158. section sorting command are used, section sorting command always
  159. takes precedence over the command-line option.
  160. </p>
  161. <p>If the section sorting command in linker script isn&rsquo;t nested, the
  162. command-line option will make the section sorting command to be
  163. treated as nested sorting command.
  164. </p>
  165. <ol>
  166. <li> <code>SORT_BY_NAME</code> (wildcard section pattern ) with
  167. <samp>--sort-sections alignment</samp> is equivalent to
  168. <code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)).
  169. </li><li> <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern) with
  170. <samp>--sort-section name</samp> is equivalent to
  171. <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)).
  172. </li></ol>
  173. <p>If the section sorting command in linker script is nested, the
  174. command-line option will be ignored.
  175. </p>
  176. <a name="index-SORT_005fNONE"></a>
  177. <p><code>SORT_NONE</code> disables section sorting by ignoring the command-line
  178. section sorting option.
  179. </p>
  180. <p>If you ever get confused about where input sections are going, use the
  181. &lsquo;<samp>-M</samp>&rsquo; linker option to generate a map file. The map file shows
  182. precisely how input sections are mapped to output sections.
  183. </p>
  184. <p>This example shows how wildcard patterns might be used to partition
  185. files. This linker script directs the linker to place all &lsquo;<samp>.text</samp>&rsquo;
  186. sections in &lsquo;<samp>.text</samp>&rsquo; and all &lsquo;<samp>.bss</samp>&rsquo; sections in &lsquo;<samp>.bss</samp>&rsquo;.
  187. The linker will place the &lsquo;<samp>.data</samp>&rsquo; section from all files beginning
  188. with an upper case character in &lsquo;<samp>.DATA</samp>&rsquo;; for all other files, the
  189. linker will place the &lsquo;<samp>.data</samp>&rsquo; section in &lsquo;<samp>.data</samp>&rsquo;.
  190. </p><div class="smallexample">
  191. <pre class="smallexample">SECTIONS {
  192. .text : { *(.text) }
  193. .DATA : { [A-Z]*(.data) }
  194. .data : { *(.data) }
  195. .bss : { *(.bss) }
  196. }
  197. </pre></div>
  198. <hr>
  199. <div class="header">
  200. <p>
  201. Next: <a href="Input-Section-Common.html#Input-Section-Common" accesskey="n" rel="next">Input Section Common</a>, Previous: <a href="Input-Section-Basics.html#Input-Section-Basics" accesskey="p" rel="previous">Input Section Basics</a>, Up: <a href="Input-Section.html#Input-Section" accesskey="u" rel="up">Input Section</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  202. </div>
  203. </body>
  204. </html>