Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

212 Zeilen
9.8KB

  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 Basics (LD)</title>
  17. <meta name="description" content="Input Section Basics (LD)">
  18. <meta name="keywords" content="Input Section Basics (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-Wildcards.html#Input-Section-Wildcards" rel="next" title="Input Section Wildcards">
  27. <link href="Input-Section.html#Input-Section" rel="prev" title="Input Section">
  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-Basics"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Input-Section-Wildcards.html#Input-Section-Wildcards" accesskey="n" rel="next">Input Section Wildcards</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-Basics-1"></a>
  64. <h4 class="subsubsection">3.6.4.1 Input Section Basics</h4>
  65. <a name="index-input-section-basics"></a>
  66. <p>An input section description consists of a file name optionally followed
  67. by a list of section names in parentheses.
  68. </p>
  69. <p>The file name and the section name may be wildcard patterns, which we
  70. describe further below (see <a href="Input-Section-Wildcards.html#Input-Section-Wildcards">Input Section Wildcards</a>).
  71. </p>
  72. <p>The most common input section description is to include all input
  73. sections with a particular name in the output section. For example, to
  74. include all input &lsquo;<samp>.text</samp>&rsquo; sections, you would write:
  75. </p><div class="smallexample">
  76. <pre class="smallexample">*(.text)
  77. </pre></div>
  78. <p>Here the &lsquo;<samp>*</samp>&rsquo; is a wildcard which matches any file name. To exclude a list
  79. <a name="index-EXCLUDE_005fFILE"></a>
  80. of files from matching the file name wildcard, EXCLUDE_FILE may be used to
  81. match all files except the ones specified in the EXCLUDE_FILE list. For
  82. example:
  83. </p><div class="smallexample">
  84. <pre class="smallexample">EXCLUDE_FILE (*crtend.o *otherfile.o) *(.ctors)
  85. </pre></div>
  86. <p>will cause all .ctors sections from all files except <samp>crtend.o</samp>
  87. and <samp>otherfile.o</samp> to be included. The EXCLUDE_FILE can also be
  88. placed inside the section list, for example:
  89. </p><div class="smallexample">
  90. <pre class="smallexample">*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
  91. </pre></div>
  92. <p>The result of this is identically to the previous example. Supporting
  93. two syntaxes for EXCLUDE_FILE is useful if the section list contains
  94. more than one section, as described below.
  95. </p>
  96. <p>There are two ways to include more than one section:
  97. </p><div class="smallexample">
  98. <pre class="smallexample">*(.text .rdata)
  99. *(.text) *(.rdata)
  100. </pre></div>
  101. <p>The difference between these is the order in which the &lsquo;<samp>.text</samp>&rsquo; and
  102. &lsquo;<samp>.rdata</samp>&rsquo; input sections will appear in the output section. In the
  103. first example, they will be intermingled, appearing in the same order as
  104. they are found in the linker input. In the second example, all
  105. &lsquo;<samp>.text</samp>&rsquo; input sections will appear first, followed by all
  106. &lsquo;<samp>.rdata</samp>&rsquo; input sections.
  107. </p>
  108. <p>When using EXCLUDE_FILE with more than one section, if the exclusion
  109. is within the section list then the exclusion only applies to the
  110. immediately following section, for example:
  111. </p><div class="smallexample">
  112. <pre class="smallexample">*(EXCLUDE_FILE (*somefile.o) .text .rdata)
  113. </pre></div>
  114. <p>will cause all &lsquo;<samp>.text</samp>&rsquo; sections from all files except
  115. <samp>somefile.o</samp> to be included, while all &lsquo;<samp>.rdata</samp>&rsquo; sections
  116. from all files, including <samp>somefile.o</samp>, will be included. To
  117. exclude the &lsquo;<samp>.rdata</samp>&rsquo; sections from <samp>somefile.o</samp> the example
  118. could be modified to:
  119. </p><div class="smallexample">
  120. <pre class="smallexample">*(EXCLUDE_FILE (*somefile.o) .text EXCLUDE_FILE (*somefile.o) .rdata)
  121. </pre></div>
  122. <p>Alternatively, placing the EXCLUDE_FILE outside of the section list,
  123. before the input file selection, will cause the exclusion to apply for
  124. all sections. Thus the previous example can be rewritten as:
  125. </p><div class="smallexample">
  126. <pre class="smallexample">EXCLUDE_FILE (*somefile.o) *(.text .rdata)
  127. </pre></div>
  128. <p>You can specify a file name to include sections from a particular file.
  129. You would do this if one or more of your files contain special data that
  130. needs to be at a particular location in memory. For example:
  131. </p><div class="smallexample">
  132. <pre class="smallexample">data.o(.data)
  133. </pre></div>
  134. <p>To refine the sections that are included based on the section flags
  135. of an input section, INPUT_SECTION_FLAGS may be used.
  136. </p>
  137. <p>Here is a simple example for using Section header flags for ELF sections:
  138. </p>
  139. <div class="smallexample">
  140. <pre class="smallexample">SECTIONS {
  141. .text : { INPUT_SECTION_FLAGS (SHF_MERGE &amp; SHF_STRINGS) *(.text) }
  142. .text2 : { INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) }
  143. }
  144. </pre></div>
  145. <p>In this example, the output section &lsquo;<samp>.text</samp>&rsquo; will be comprised of any
  146. input section matching the name *(.text) whose section header flags
  147. <code>SHF_MERGE</code> and <code>SHF_STRINGS</code> are set. The output section
  148. &lsquo;<samp>.text2</samp>&rsquo; will be comprised of any input section matching the name *(.text)
  149. whose section header flag <code>SHF_WRITE</code> is clear.
  150. </p>
  151. <p>You can also specify files within archives by writing a pattern
  152. matching the archive, a colon, then the pattern matching the file,
  153. with no whitespace around the colon.
  154. </p>
  155. <dl compact="compact">
  156. <dt>&lsquo;<samp>archive:file</samp>&rsquo;</dt>
  157. <dd><p>matches file within archive
  158. </p></dd>
  159. <dt>&lsquo;<samp>archive:</samp>&rsquo;</dt>
  160. <dd><p>matches the whole archive
  161. </p></dd>
  162. <dt>&lsquo;<samp>:file</samp>&rsquo;</dt>
  163. <dd><p>matches file but not one in an archive
  164. </p></dd>
  165. </dl>
  166. <p>Either one or both of &lsquo;<samp>archive</samp>&rsquo; and &lsquo;<samp>file</samp>&rsquo; can contain shell
  167. wildcards. On DOS based file systems, the linker will assume that a
  168. single letter followed by a colon is a drive specifier, so
  169. &lsquo;<samp>c:myfile.o</samp>&rsquo; is a simple file specification, not &lsquo;<samp>myfile.o</samp>&rsquo;
  170. within an archive called &lsquo;<samp>c</samp>&rsquo;. &lsquo;<samp>archive:file</samp>&rsquo; filespecs may
  171. also be used within an <code>EXCLUDE_FILE</code> list, but may not appear in
  172. other linker script contexts. For instance, you cannot extract a file
  173. from an archive by using &lsquo;<samp>archive:file</samp>&rsquo; in an <code>INPUT</code>
  174. command.
  175. </p>
  176. <p>If you use a file name without a list of sections, then all sections in
  177. the input file will be included in the output section. This is not
  178. commonly done, but it may by useful on occasion. For example:
  179. </p><div class="smallexample">
  180. <pre class="smallexample">data.o
  181. </pre></div>
  182. <p>When you use a file name which is not an &lsquo;<samp>archive:file</samp>&rsquo; specifier
  183. and does not contain any wild card
  184. characters, the linker will first see if you also specified the file
  185. name on the linker command line or in an <code>INPUT</code> command. If you
  186. did not, the linker will attempt to open the file as an input file, as
  187. though it appeared on the command line. Note that this differs from an
  188. <code>INPUT</code> command, because the linker will not search for the file in
  189. the archive search path.
  190. </p>
  191. <hr>
  192. <div class="header">
  193. <p>
  194. Next: <a href="Input-Section-Wildcards.html#Input-Section-Wildcards" accesskey="n" rel="next">Input Section Wildcards</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>
  195. </div>
  196. </body>
  197. </html>