You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Input-Section-Wildcards.html 10KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 Arm Embedded Toolchain 10-2020-q4-major)
  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 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Input Section Wildcards (LD)</title>
  17. <meta name="description" content="Input Section Wildcards (LD)">
  18. <meta name="keywords" content="Input Section Wildcards (LD)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  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.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Input-Section-Wildcards"></a>
  58. <div class="header">
  59. <p>
  60. 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>
  61. </div>
  62. <hr>
  63. <a name="Input-Section-Wildcard-Patterns"></a>
  64. <h4 class="subsubsection">3.6.4.2 Input Section Wildcard Patterns</h4>
  65. <a name="index-input-section-wildcards"></a>
  66. <a name="index-wildcard-file-name-patterns"></a>
  67. <a name="index-file-name-wildcard-patterns"></a>
  68. <a name="index-section-name-wildcard-patterns"></a>
  69. <p>In an input section description, either the file name or the section
  70. name or both may be wildcard patterns.
  71. </p>
  72. <p>The file name of &lsquo;<samp>*</samp>&rsquo; seen in many examples is a simple wildcard
  73. pattern for the file name.
  74. </p>
  75. <p>The wildcard patterns are like those used by the Unix shell.
  76. </p>
  77. <dl compact="compact">
  78. <dt>&lsquo;<samp>*</samp>&rsquo;</dt>
  79. <dd><p>matches any number of characters
  80. </p></dd>
  81. <dt>&lsquo;<samp>?</samp>&rsquo;</dt>
  82. <dd><p>matches any single character
  83. </p></dd>
  84. <dt>&lsquo;<samp>[<var>chars</var>]</samp>&rsquo;</dt>
  85. <dd><p>matches a single instance of any of the <var>chars</var>; the &lsquo;<samp>-</samp>&rsquo;
  86. character may be used to specify a range of characters, as in
  87. &lsquo;<samp>[a-z]</samp>&rsquo; to match any lower case letter
  88. </p></dd>
  89. <dt>&lsquo;<samp>\</samp>&rsquo;</dt>
  90. <dd><p>quotes the following character
  91. </p></dd>
  92. </dl>
  93. <p>When a file name is matched with a wildcard, the wildcard characters
  94. will not match a &lsquo;<samp>/</samp>&rsquo; character (used to separate directory names on
  95. Unix). A pattern consisting of a single &lsquo;<samp>*</samp>&rsquo; character is an
  96. exception; it will always match any file name, whether it contains a
  97. &lsquo;<samp>/</samp>&rsquo; or not. In a section name, the wildcard characters will match
  98. a &lsquo;<samp>/</samp>&rsquo; character.
  99. </p>
  100. <p>File name wildcard patterns only match files which are explicitly
  101. specified on the command line or in an <code>INPUT</code> command. The linker
  102. does not search directories to expand wildcards.
  103. </p>
  104. <p>If a file name matches more than one wildcard pattern, or if a file name
  105. appears explicitly and is also matched by a wildcard pattern, the linker
  106. will use the first match in the linker script. For example, this
  107. sequence of input section descriptions is probably in error, because the
  108. <samp>data.o</samp> rule will not be used:
  109. </p><div class="smallexample">
  110. <pre class="smallexample">.data : { *(.data) }
  111. .data1 : { data.o(.data) }
  112. </pre></div>
  113. <a name="index-SORT_005fBY_005fNAME"></a>
  114. <p>Normally, the linker will place files and sections matched by wildcards
  115. in the order in which they are seen during the link. You can change
  116. this by using the <code>SORT_BY_NAME</code> keyword, which appears before a wildcard
  117. pattern in parentheses (e.g., <code>SORT_BY_NAME(.text*)</code>). When the
  118. <code>SORT_BY_NAME</code> keyword is used, the linker will sort the files or sections
  119. into ascending order by name before placing them in the output file.
  120. </p>
  121. <a name="index-SORT_005fBY_005fALIGNMENT"></a>
  122. <p><code>SORT_BY_ALIGNMENT</code> is similar to <code>SORT_BY_NAME</code>.
  123. <code>SORT_BY_ALIGNMENT</code> will sort sections into descending order of
  124. alignment before placing them in the output file. Placing larger
  125. alignments before smaller alignments can reduce the amount of padding
  126. needed.
  127. </p>
  128. <a name="index-SORT_005fBY_005fINIT_005fPRIORITY"></a>
  129. <p><code>SORT_BY_INIT_PRIORITY</code> is also similar to <code>SORT_BY_NAME</code>.
  130. <code>SORT_BY_INIT_PRIORITY</code> will sort sections into ascending
  131. numerical order of the GCC init_priority attribute encoded in the
  132. section name before placing them in the output file. In
  133. <code>.init_array.NNNNN</code> and <code>.fini_array.NNNNN</code>, <code>NNNNN</code> is
  134. the init_priority. In <code>.ctors.NNNNN</code> and <code>.dtors.NNNNN</code>,
  135. <code>NNNNN</code> is 65535 minus the init_priority.
  136. </p>
  137. <a name="index-SORT"></a>
  138. <p><code>SORT</code> is an alias for <code>SORT_BY_NAME</code>.
  139. </p>
  140. <p>When there are nested section sorting commands in linker script, there
  141. can be at most 1 level of nesting for section sorting commands.
  142. </p>
  143. <ol>
  144. <li> <code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)).
  145. It will sort the input sections by name first, then by alignment if two
  146. sections have the same name.
  147. </li><li> <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)).
  148. It will sort the input sections by alignment first, then by name if two
  149. sections have the same alignment.
  150. </li><li> <code>SORT_BY_NAME</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)) is
  151. treated the same as <code>SORT_BY_NAME</code> (wildcard section pattern).
  152. </li><li> <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern))
  153. is treated the same as <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern).
  154. </li><li> All other nested section sorting commands are invalid.
  155. </li></ol>
  156. <p>When both command-line section sorting option and linker script
  157. section sorting command are used, section sorting command always
  158. takes precedence over the command-line option.
  159. </p>
  160. <p>If the section sorting command in linker script isn&rsquo;t nested, the
  161. command-line option will make the section sorting command to be
  162. treated as nested sorting command.
  163. </p>
  164. <ol>
  165. <li> <code>SORT_BY_NAME</code> (wildcard section pattern ) with
  166. <samp>--sort-sections alignment</samp> is equivalent to
  167. <code>SORT_BY_NAME</code> (<code>SORT_BY_ALIGNMENT</code> (wildcard section pattern)).
  168. </li><li> <code>SORT_BY_ALIGNMENT</code> (wildcard section pattern) with
  169. <samp>--sort-section name</samp> is equivalent to
  170. <code>SORT_BY_ALIGNMENT</code> (<code>SORT_BY_NAME</code> (wildcard section pattern)).
  171. </li></ol>
  172. <p>If the section sorting command in linker script is nested, the
  173. command-line option will be ignored.
  174. </p>
  175. <a name="index-SORT_005fNONE"></a>
  176. <p><code>SORT_NONE</code> disables section sorting by ignoring the command-line
  177. section sorting option.
  178. </p>
  179. <p>If you ever get confused about where input sections are going, use the
  180. &lsquo;<samp>-M</samp>&rsquo; linker option to generate a map file. The map file shows
  181. precisely how input sections are mapped to output sections.
  182. </p>
  183. <p>This example shows how wildcard patterns might be used to partition
  184. files. This linker script directs the linker to place all &lsquo;<samp>.text</samp>&rsquo;
  185. sections in &lsquo;<samp>.text</samp>&rsquo; and all &lsquo;<samp>.bss</samp>&rsquo; sections in &lsquo;<samp>.bss</samp>&rsquo;.
  186. The linker will place the &lsquo;<samp>.data</samp>&rsquo; section from all files beginning
  187. with an upper case character in &lsquo;<samp>.DATA</samp>&rsquo;; for all other files, the
  188. linker will place the &lsquo;<samp>.data</samp>&rsquo; section in &lsquo;<samp>.data</samp>&rsquo;.
  189. </p><div class="smallexample">
  190. <pre class="smallexample">SECTIONS {
  191. .text : { *(.text) }
  192. .DATA : { [A-Z]*(.data) }
  193. .data : { *(.data) }
  194. .bss : { *(.bss) }
  195. }
  196. </pre></div>
  197. <hr>
  198. <div class="header">
  199. <p>
  200. 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>
  201. </div>
  202. </body>
  203. </html>