Input-Section-Wildcards.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 Binutils)
  5. version 2.28.
  6. Copyright (C) 1991-2017 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.2, 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="prev" 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="prev">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 very similar to <code>SORT_BY_NAME</code>. The
  124. difference is <code>SORT_BY_ALIGNMENT</code> will sort sections into
  125. descending order by alignment before placing them in the output file.
  126. Larger alignments are placed before smaller alignments in order to
  127. reduce the amount of padding necessary.
  128. </p>
  129. <a name="index-SORT_005fBY_005fINIT_005fPRIORITY"></a>
  130. <p><code>SORT_BY_INIT_PRIORITY</code> is very similar to <code>SORT_BY_NAME</code>. The
  131. difference is <code>SORT_BY_INIT_PRIORITY</code> will sort sections into
  132. ascending order by numerical value of the GCC init_priority attribute
  133. encoded in the section name before placing them in the output file.
  134. </p>
  135. <a name="index-SORT"></a>
  136. <p><code>SORT</code> is an alias for <code>SORT_BY_NAME</code>.
  137. </p>
  138. <p>When there are nested section sorting commands in linker script, there
  139. can be at most 1 level of nesting for section sorting commands.
  140. </p>
  141. <ol>
  142. <li> <code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)).
  143. It will sort the input sections by name first, then by alignment if two
  144. sections have the same name.
  145. </li><li> <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)).
  146. It will sort the input sections by alignment first, then by name if two
  147. sections have the same alignment.
  148. </li><li> <code>SORT_BY_NAME</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)) is
  149. treated the same as <code>SORT_BY_NAME</code> (wildcard section pattern).
  150. </li><li> <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern))
  151. is treated the same as <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern).
  152. </li><li> All other nested section sorting commands are invalid.
  153. </li></ol>
  154. <p>When both command line section sorting option and linker script
  155. section sorting command are used, section sorting command always
  156. takes precedence over the command line option.
  157. </p>
  158. <p>If the section sorting command in linker script isn&rsquo;t nested, the
  159. command line option will make the section sorting command to be
  160. treated as nested sorting command.
  161. </p>
  162. <ol>
  163. <li> <code>SORT_BY_NAME</code> (wildcard section pattern ) with
  164. <samp>--sort-sections alignment</samp> is equivalent to
  165. <code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)).
  166. </li><li> <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern) with
  167. <samp>--sort-section name</samp> is equivalent to
  168. <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)).
  169. </li></ol>
  170. <p>If the section sorting command in linker script is nested, the
  171. command line option will be ignored.
  172. </p>
  173. <a name="index-SORT_005fNONE"></a>
  174. <p><code>SORT_NONE</code> disables section sorting by ignoring the command line
  175. section sorting option.
  176. </p>
  177. <p>If you ever get confused about where input sections are going, use the
  178. &lsquo;<samp>-M</samp>&rsquo; linker option to generate a map file. The map file shows
  179. precisely how input sections are mapped to output sections.
  180. </p>
  181. <p>This example shows how wildcard patterns might be used to partition
  182. files. This linker script directs the linker to place all &lsquo;<samp>.text</samp>&rsquo;
  183. sections in &lsquo;<samp>.text</samp>&rsquo; and all &lsquo;<samp>.bss</samp>&rsquo; sections in &lsquo;<samp>.bss</samp>&rsquo;.
  184. The linker will place the &lsquo;<samp>.data</samp>&rsquo; section from all files beginning
  185. with an upper case character in &lsquo;<samp>.DATA</samp>&rsquo;; for all other files, the
  186. linker will place the &lsquo;<samp>.data</samp>&rsquo; section in &lsquo;<samp>.data</samp>&rsquo;.
  187. </p><div class="smallexample">
  188. <pre class="smallexample">SECTIONS {
  189. .text : { *(.text) }
  190. .DATA : { [A-Z]*(.data) }
  191. .data : { *(.data) }
  192. .bss : { *(.bss) }
  193. }
  194. </pre></div>
  195. <hr>
  196. <div class="header">
  197. <p>
  198. 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="prev">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>
  199. </div>
  200. </body>
  201. </html>